From 2f14dbf5a54e1c971099feef66dc69a129016b3d Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Fri, 9 Sep 2022 14:38:44 +0800 Subject: [PATCH] Fix wrong exit code when es2abc parse-only mode fails Issue:I5Q7UP Change-Id: Ie48af55eb2a10ea207877f7ff6a04bc978f0f7b9 Signed-off-by: chenqy930 --- es2panda/aot/main.cpp | 5 ++--- es2panda/es2panda.cpp | 19 +++++++++++++------ es2panda/es2panda.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/es2panda/aot/main.cpp b/es2panda/aot/main.cpp index aa3c203107..2da57c1bb0 100644 --- a/es2panda/aot/main.cpp +++ b/es2panda/aot/main.cpp @@ -151,10 +151,9 @@ int Run(int argc, const char **argv) options->CompilerOptions().isDebug, &allocator); } - Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programsInfo, &allocator); - + int ret = Compiler::CompileFiles(options->CompilerOptions(), cachePrograms, programsInfo, &allocator); if (options->ParseOnly()) { - return 0; + return ret; } if (!options->NpmModuleEntryList().empty()) { diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index fcb7f8208a..22e3d95387 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -144,7 +144,7 @@ void Compiler::SelectCompileFile(CompilerOptions &options, options.sourceFiles = inputList; } -void Compiler::CompileFiles(CompilerOptions &options, +int Compiler::CompileFiles(CompilerOptions &options, std::map *cacheProgs, std::map &progsInfo, panda::ArenaAllocator *allocator) @@ -154,17 +154,22 @@ void Compiler::CompileFiles(CompilerOptions &options, symbolTable = new util::SymbolTable(options.hotfixOptions.symbolTable, options.hotfixOptions.dumpSymbolTable); if (!symbolTable->Initialize()) { std::cerr << "Exits due to hot fix initialize failed!" << std::endl; - return; + return 1; } } SelectCompileFile(options, cacheProgs, progsInfo, allocator); + bool failed = false; auto queue = new compiler::CompileFileQueue(options.fileThreadCount, &options, progsInfo, symbolTable, allocator); - queue->Schedule(); - queue->Consume(); - queue->Wait(); + try { + queue->Schedule(); + queue->Consume(); + queue->Wait(); + } catch (const class Error &e) { + failed = true; + } delete queue; queue = nullptr; @@ -173,6 +178,8 @@ void Compiler::CompileFiles(CompilerOptions &options, delete symbolTable; symbolTable = nullptr; } + + return failed ? 1 : 0; } panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceFile *src, @@ -203,7 +210,7 @@ panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceF std::cerr << err.TypeString() << ": " << err.Message(); std::cerr << " [" << src->fileName << ":" << err.Line() << ":" << err.Col() << "]" << std::endl; - return nullptr; + throw err; } return program; } diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index dc0e9480ee..c6144e2e6f 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -165,7 +165,7 @@ public: util::SymbolTable *symbolTable = nullptr); panda::pandasm::Program *CompileFile(CompilerOptions &options, SourceFile *src, util::SymbolTable *symbolTable_); - static void CompileFiles(CompilerOptions &options, + static int CompileFiles(CompilerOptions &options, std::map *cacheProgs, std::map &progsInfo, panda::ArenaAllocator *allocator); -- Gitee