diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 6a29659a5f81d0b0b688016ff33f10360aa8f0b9..d4959c95c5ed23e701a120d2bbd769209453c276 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 463ac9740cc65699399329dc2787691508ead700..409181ecc360d059abb3b2e4c72f2ea1b09c5eaa 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 6d38b78fe12935540b47fd79bef2131b805105ce..e57b5adfea6752a077c381ff0dd6977bef26e31a 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 03846b4edb2ad52bc77c706bb89004f1a4cb8c28..f70fdf6636d0fef21f3fb3c3421deb4135ad8b91 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 3b12b56143ed380eb4dda0127c001f010ecc28ef..71feee3c18e98f3673f719684146d8f9d08e05fd 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 87fa056006b2ba2267bad3b3a2fd859a37d41bf0..4ba6b88548cd03e382187970b8384e3170de0e62 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 60e35b3075d7159197182ee00774dec4786a07f9..0bf3a40815189fdbce36785c9d2d013ceccb4e95 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");