From bd20db81c7ebaeb75d36bf1c9195855900c81cc0 Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Mon, 5 Sep 2022 18:40:54 +0800 Subject: [PATCH] Fix output full path in error message Issue:I5PTCW Signed-off-by: chenqy930 Change-Id: I31e963fd4d8b7c4262bffcea5ade4b3a0571a323 --- es2panda/aot/options.cpp | 13 +++++-------- es2panda/es2panda.cpp | 6 ++---- es2panda/util/helpers.h | 9 +++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index fd09afa999..7f51a5be3e 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -17,6 +17,7 @@ #include "mergeProgram.h" #include "os/file.h" +#include #include #if defined(PANDA_TARGET_WINDOWS) #include @@ -29,11 +30,6 @@ #include namespace panda::es2panda::aot { -template -T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())) -{ - return path.substr(path.find_last_of(delims) + 1); -} template T RemoveExtension(T const &filename) @@ -107,7 +103,7 @@ bool Options::CollectInputFilesFromFileDirectory(const std::string &input, const return false; } for (auto &f : files) { - es2panda::SourceFile src(f, BaseName(f), scriptKind_); + es2panda::SourceFile src(f, util::Helpers::BaseName(f), scriptKind_); sourceFiles_.push_back(src); } @@ -262,13 +258,14 @@ bool Options::Parse(int argc, const char **argv) } else if (!outputIsEmpty) { compilerOutput_ = outputFile.GetValue(); } else if (outputIsEmpty && !inputIsEmpty) { - compilerOutput_ = RemoveExtension(BaseName(sourceFile_)).append(".abc"); + compilerOutput_ = RemoveExtension(util::Helpers::BaseName(sourceFile_)).append(".abc"); } if (opMergeAbc.GetValue()) { recordName_ = recordName.GetValue(); if (recordName_.empty()) { - recordName_ = compilerOutput_.empty() ? "Base64Output" : RemoveExtension(BaseName(compilerOutput_)); + recordName_ = compilerOutput_.empty() ? "Base64Output" : + RemoveExtension(util::Helpers::BaseName(compilerOutput_)); } recordName_ = FormatRecordName(recordName_); } diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 0f2204eb13..dd7b61b439 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -59,10 +60,6 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil std::cout << ast.Dump() << std::endl; } - if (options.parseOnly) { - return nullptr; - } - std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? fname : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); @@ -161,6 +158,7 @@ panda::pandasm::Program *Compiler::CompileFile(CompilerOptions &options, SourceF src->hash = GetHash32String(reinterpret_cast(buffer.c_str())); } } + src->fileName = util::Helpers::BaseName(src->fileName); auto *program = Compile(*src, options); if (!program) { diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index e970162905..d9021aa9e2 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -75,6 +76,8 @@ public: uint32_t index); static bool OptimizeProgram(panda::pandasm::Program *prog, es2panda::CompilerOptions *options); + template + static T BaseName(T const &path, T const &delims = std::string(panda::os::file::File::GetPathDelim())); static const uint32_t INVALID_INDEX = 4294967295L; static const uint32_t MAX_INT32 = 2147483647; @@ -94,6 +97,12 @@ bool Helpers::IsInteger(double number) return false; } +template +T Helpers::BaseName(T const &path, T const &delims) +{ + return path.substr(path.find_last_of(delims) + 1); +} + } // namespace panda::es2panda::util #endif -- Gitee