From 257f01813646acba16d0ca9f9ffdfc218d6cc210 Mon Sep 17 00:00:00 2001 From: Amosov Date: Thu, 21 Sep 2023 17:03:20 +0300 Subject: [PATCH] Correct path delimiter for windows Signed-off-by: Amosov --- CMakeLists.txt | 17 ++++++++++++----- parser/ETSparser.cpp | 16 ++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f324d5586..3c8570927 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,8 +17,15 @@ project (es2panda) 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(PANDA_TARGET_WINDOWS) + set(DELIM "\\\\") +else() + set(DELIM "/") +endif() + +set(GENERATED_DIR ${OUTPUT_DIR}${DELIM}generated) +set(GENERATED_STAMP ${OUTPUT_DIR}${DELIM}gen_dir.stamp) file(MAKE_DIRECTORY "${GENERATED_DIR}") if(PANDA_WITH_ETS) file(WRITE "${GENERATED_DIR}/arktsconfig.json" @@ -26,9 +33,9 @@ if(PANDA_WITH_ETS) " \"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" + " \"std\": [\"${PANDA_ROOT}${DELIM}plugins${DELIM}ets${DELIM}stdlib${DELIM}std\"],\n" + " \"escompat\": [\"${PANDA_ROOT}${DELIM}plugins${DELIM}ets${DELIM}stdlib${DELIM}escompat\"],\n" + " \"import_tests\": [\"${CMAKE_CURRENT_SOURCE_DIR}${DELIM}test${DELIM}parser${DELIM}ets${DELIM}import_tests\"]\n" " },\n" " \"dynamicPaths\": {\n" " \"dynamic_js_import_tests\": {\"language\": \"js\", \"hasDecl\": false}\n" diff --git a/parser/ETSparser.cpp b/parser/ETSparser.cpp index a6f4b9727..ee3c174b1 100644 --- a/parser/ETSparser.cpp +++ b/parser/ETSparser.cpp @@ -306,10 +306,11 @@ void ETSParser::CollectDefaultSources() std::tuple ETSParser::GetImportData(const std::string &path) { std::string key; - if (util::Helpers::IsRelativePath(path) || path.find('/') == 0) { + const auto path_delimiter = panda::os::file::File::GetPathDelim(); + if (util::Helpers::IsRelativePath(path) || path.find(path_delimiter) == 0) { key = path; } else { - std::string::size_type pos = path.find('/'); + std::string::size_type pos = path.find(path_delimiter); bool contains_delim = (pos != std::string::npos); key = contains_delim ? path.substr(0, pos) : path; } @@ -325,7 +326,7 @@ std::tuple ETSParser::GetImportData(const std::string &path) std::string ETSParser::ResolveImportPath(const std::string &path) { - char path_delimiter = panda::os::file::File::GetPathDelim().at(0); + const char path_delimiter = panda::os::file::File::GetPathDelim().at(0); if (util::Helpers::IsRelativePath(path)) { if (GetProgram()->ResolvedFilePath().Mutf8().empty()) { return GetProgram()->SourceFilePath().Mutf8() + path_delimiter + path; @@ -335,9 +336,8 @@ std::string ETSParser::ResolveImportPath(const std::string &path) std::string base_url; // Resolve delimeter character to basePath. - if (path.find('/') == 0) { + if (path.find_first_of("/\\") == 0) { base_url = ArkTSConfig()->BaseUrl(); - base_url.append(path, 0, path.length()); return base_url; } @@ -350,14 +350,14 @@ std::string ETSParser::ResolveImportPath(const std::string &path) // Resolve the root part of the path. // E.g. root part of std/math is std. - std::string::size_type pos = path.find('/'); + std::string::size_type pos = path.find_first_of("/\\"); bool contains_delim = (pos != std::string::npos); std::string root_part = contains_delim ? path.substr(0, pos) : path; if (root_part == "std" && !GetOptions().std_lib.empty()) { // Get std path from CLI if provided - base_url = GetOptions().std_lib + "/std"; + base_url = GetOptions().std_lib + path_delimiter + "std"; } else if (root_part == "escompat" && !GetOptions().std_lib.empty()) { // Get escompat path from CLI if provided - base_url = GetOptions().std_lib + "/escompat"; + base_url = GetOptions().std_lib + path_delimiter + "escompat"; } else { auto paths = ArkTSConfig()->Paths(); if (paths.count(root_part) == 0U) { -- Gitee