From 0a41140939f778b21a99015559473d53732dd8e1 Mon Sep 17 00:00:00 2001 From: ozerovnikita Date: Thu, 9 Nov 2023 20:14:04 +0300 Subject: [PATCH] fix hardcoded arktsconfig path Description: Move arktsconfig.json generation path to es2panda bin directory and change es2panda option.cpp to open it by default Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8J02Y Signed-off-by: ozerovnikita --- ets2panda/BUILD.gn | 4 --- ets2panda/CMakeLists.txt | 27 ++++++++++++++++--- ets2panda/test/unit/ast_dumper_test.cpp | 10 ++++--- .../test/unit/public/es2panda_public_test.cpp | 2 +- ets2panda/util/arktsconfig.cpp | 4 +-- ets2panda/util/arktsconfig.h | 4 +++ ets2panda/util/options.cpp | 9 ++++++- 7 files changed, 44 insertions(+), 16 deletions(-) diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 6a29659a5f..d4959c95c5 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -364,14 +364,10 @@ libes2panda_public_sources = [ "util/options.cpp", ] -build_gen_root = rebase_path(root_gen_dir) - config("libes2panda_config") { cflags_cc = [ "-fexceptions", "-Werror=shadow", - - "-DDEFAULT_ARKTSCONFIG=\"$build_gen_root/tools/es2panda/generated/arktsconfig.json\"", ] } diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 463ac9740c..409181ecc3 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -21,8 +21,31 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(GENERATED_DIR ${OUTPUT_DIR}/generated) set(GENERATED_STAMP ${OUTPUT_DIR}/gen_dir.stamp) +if(CMAKE_CROSSCOMPILING) + ExternalProject_Get_Property(panda_host_tools binary_dir) + set(DEFAULT_ARKTSCONFIG "${binary_dir}/tools/es2panda/aot") +else() + set(DEFAULT_ARKTSCONFIG "${CMAKE_BINARY_DIR}/bin") +endif() file(MAKE_DIRECTORY "${GENERATED_DIR}") if(PANDA_WITH_ETS) + file(WRITE "${DEFAULT_ARKTSCONFIG}/arktsconfig.json" + "{\n" + " \"compilerOptions\": {\n" + " \"baseUrl\": \"${PANDA_ROOT}\",\n" + " \"paths\": {\n" + " \"std\": [\"${PANDA_ROOT}/plugins/ets/stdlib/std\"],\n" + " \"escompat\": [\"${PANDA_ROOT}/plugins/ets/stdlib/escompat\"],\n" + " \"import_tests\": [\"${CMAKE_CURRENT_SOURCE_DIR}/test/parser/ets/import_tests\"],\n" + " \"dynamic_import_tests\": [\"${CMAKE_CURRENT_SOURCE_DIR}/test/parser/ets/dynamic_import_tests\"]\n" + " },\n" + " \"dynamicPaths\": {\n" + " \"dynamic_js_import_tests\": {\"language\": \"js\", \"hasDecl\": false},\n" + " \"${CMAKE_CURRENT_SOURCE_DIR}/test/parser/ets/dynamic_import_tests\": {\"language\": \"js\", \"hasDecl\": true}\n" + " }\n" + " }\n" + "}\n" + ) file(WRITE "${GENERATED_DIR}/arktsconfig.json" "{\n" " \"compilerOptions\": {\n" @@ -472,10 +495,6 @@ panda_target_include_directories(es2panda-public PRIVATE ${OUTPUT_DIR} ) -panda_target_compile_definitions(es2panda-public - PRIVATE "DEFAULT_ARKTSCONFIG=\"${GENERATED_DIR}/arktsconfig.json\"" -) - panda_target_compile_options(es2panda-public PRIVATE -fexceptions -Werror=shadow ) diff --git a/ets2panda/test/unit/ast_dumper_test.cpp b/ets2panda/test/unit/ast_dumper_test.cpp index 6d38b78fe1..e57b5adfea 100644 --- a/ets2panda/test/unit/ast_dumper_test.cpp +++ b/ets2panda/test/unit/ast_dumper_test.cpp @@ -83,8 +83,9 @@ TEST_F(ASTDumperTest, DumpJsonSimple) return a + b;\ }"; - int argc = 0; - const char *argv = ""; + int argc = 1; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) + const char *argv = "../../../bin/es2panda"; auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; @@ -108,8 +109,9 @@ TEST_F(ASTDumperTest, DumpJsonUTF16Char) return 0;\ }"; - int argc = 0; - const char *argv = ""; + int argc = 1; + // NOLINTNEXTLINE(modernize-avoid-c-arrays) + const char *argv = "../../../bin/es2panda"; auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; diff --git a/ets2panda/test/unit/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp index 03846b4edb..f70fdf6636 100644 --- a/ets2panda/test/unit/public/es2panda_public_test.cpp +++ b/ets2panda/test/unit/public/es2panda_public_test.cpp @@ -23,7 +23,7 @@ public: { impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); // NOLINTNEXTLINE(modernize-avoid-c-arrays) - char const *argv[] = {"test"}; + char const *argv[] = {"../../../bin/es2panda"}; cfg_ = impl_->CreateConfig(1, argv); } diff --git a/ets2panda/util/arktsconfig.cpp b/ets2panda/util/arktsconfig.cpp index 3b12b56143..71feee3c18 100644 --- a/ets2panda/util/arktsconfig.cpp +++ b/ets2panda/util/arktsconfig.cpp @@ -57,7 +57,7 @@ static bool IsAbsolute(const std::string &path) #endif // ARKTSCONFIG_USE_FILESYSTEM } -static std::string JoinPaths(const std::string &a, const std::string &b) +std::string JoinPaths(const std::string &a, const std::string &b) { #ifndef ARKTSCONFIG_USE_FILESYSTEM return a + '/' + b; @@ -66,7 +66,7 @@ static std::string JoinPaths(const std::string &a, const std::string &b) #endif // ARKTSCONFIG_USE_FILESYSTEM } -static std::string ParentPath(const std::string &path) +std::string ParentPath(const std::string &path) { #ifndef ARKTSCONFIG_USE_FILESYSTEM auto pos = path.find('/'); diff --git a/ets2panda/util/arktsconfig.h b/ets2panda/util/arktsconfig.h index 87fa056006..4ba6b88548 100644 --- a/ets2panda/util/arktsconfig.h +++ b/ets2panda/util/arktsconfig.h @@ -143,6 +143,10 @@ private: // Find source files and compute destination locations // Return: vector of path pairs std::vector> FindProjectSources(const std::shared_ptr &arkts_config); + +std::string JoinPaths(const std::string &a, const std::string &b); +std::string ParentPath(const std::string &path); + } // namespace panda::es2panda #endif // ES2PANDA_AOT_TSCONFIG_H diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index 60e35b3075..0bf3a40815 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -17,6 +17,8 @@ #include "utils/pandargs.h" +#include "arktsconfig.h" + #include #ifdef PANDA_WITH_BYTECODE_OPTIMIZER @@ -172,7 +174,12 @@ bool Options::Parse(int argc, const char **argv) "Generate program dump before running phases in the list"); panda::PandArg dump_after_phases("dump-after-phases", "", "Generate program dump after running phases in the list"); - panda::PandArg arkts_config("arktsconfig", DEFAULT_ARKTSCONFIG, "Path to arkts configuration file"); + panda::PandArg arkts_config( + "arktsconfig", + panda::es2panda::JoinPaths( + panda::es2panda::ParentPath(argv[0]), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + "arktsconfig.json"), + "Path to arkts configuration file"); // tail arguments panda::PandArg input_file("input", "", "input file"); -- Gitee