From 617617cac922ea2cc47292eb8cfa1b28baa747b9 Mon Sep 17 00:00:00 2001 From: tension <1113989231@qq.com> Date: Mon, 1 Sep 2025 09:42:40 +0800 Subject: [PATCH] Fix importpathmanager gen error path Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICUEW5 Signed-off-by: zhangli <1113989231@qq.com> Change-id: af8cb9f75a812c15d7a61e849b3a78bc1za4e98ac --- .../build_config.json | 44 +++++++++++++++++++ .../library/decl-fileInfo.json | 13 ++++++ .../library/file1.ets | 20 +++++++++ .../library/file2.d.ets | 19 ++++++++ .../library/file2.ets | 20 +++++++++ .../library/file3.d.ets | 18 ++++++++ .../library/file3.ets | 18 ++++++++ ets2panda/util/importPathManager.cpp | 24 +++++++--- ets2panda/util/importPathManager.h | 1 + 9 files changed, 172 insertions(+), 5 deletions(-) create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/build_config.json create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/decl-fileInfo.json create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.d.ets create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.ets create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.d.ets create mode 100644 ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.ets diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/build_config.json b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/build_config.json new file mode 100644 index 0000000000..616c892c35 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/build_config.json @@ -0,0 +1,44 @@ +{ + + "plugins": { + "ArkUI": "${absolute_path_to_build_system}/test/mock_sdk/ets/ets1.2/build-tools/ui-plugins/lib/ui-plugins/index.js", + "ArkUI-Memo": "${absolute_path_to_build_system}/test/mock_sdk/ets/ets1.2/build-tools/ui-plugins/lib/memo-plugins/index.js" + }, + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets" + ], + "packageName": "library", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1", + "sourceRoots": [ + "./" + ], + "bundleName": "com.example.myapplication", + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "compileSdkVersion":20, + "compatibleSdkVersion": 20, + "dependentModuleList": [ + { + "language": "hybrid", + "packageName": "library", + "moduleType": "har", + "moduleName": "library", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1", + "declFilePath": "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1/library/decl-fileInfo.json", + "sourceRoots": [ + "./" + ], + "dependencies": [] + } + ], + "entryFile": [ + "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets" + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/decl-fileInfo.json new file mode 100644 index 0000000000..9166781e59 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "library", + "files": { + "file2": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.d.ets", + "ohmUrl": "@normalized:N&undefined&&library/file2&" + }, + "file3": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.d.ets", + "ohmUrl": "@normalized:N&undefined&&library/file3&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets new file mode 100644 index 0000000000..cdf2ea6287 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file1.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { B } from 'library/file2' + +export function foo1() { + +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.d.ets b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.d.ets new file mode 100644 index 0000000000..e5f0d26c21 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.d.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + import { A } from './file3'; + export declare class B { + foo2(a: A): void; + } \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.ets b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.ets new file mode 100644 index 0000000000..52d6814886 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file2.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { A } from './file3' + +export class B { + foo2(a: A) { } +}; \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.d.ets b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.d.ets new file mode 100644 index 0000000000..e3bcd41b3d --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.d.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + export declare class A { + name?: string; + } \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.ets b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.ets new file mode 100644 index 0000000000..528a013e16 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_file1.2_file1.1_file1.1/library/file3.ets @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class A { + name?: string; +} \ No newline at end of file diff --git a/ets2panda/util/importPathManager.cpp b/ets2panda/util/importPathManager.cpp index a22a321bea..ed3fed6da2 100644 --- a/ets2panda/util/importPathManager.cpp +++ b/ets2panda/util/importPathManager.cpp @@ -402,6 +402,20 @@ std::string ImportPathManager::TryMatchDependencies(std::string_view fixedPath) return {}; } +std::string ImportPathManager::TryResolvePath(std::string_view fixedPath) const +{ + auto normalizedPath = ark::os::NormalizePath(std::string(fixedPath)); + std::replace_if( + normalizedPath.begin(), normalizedPath.end(), [&](auto &c) { return c == pathDelimiter_[0]; }, '/'); + if (arktsConfig_->Dependencies().find(normalizedPath) != arktsConfig_->Dependencies().cend()) { + return normalizedPath; + } + if (arktsConfig_->Paths().find(normalizedPath) != arktsConfig_->Paths().cend()) { + return normalizedPath; + } + return {}; +} + std::string_view ImportPathManager::DirOrDirWithIndexFile(StringView dir) const { // Supported index files: keep this checking order @@ -425,8 +439,8 @@ ImportPathManager::ResolvedPathRes ImportPathManager::AppendExtensionOrIndexFile std::replace_if( fixedPath.begin(), fixedPath.end(), [&](auto &c) { return ((delim != c) && ((c == '\\') || (c == '/'))); }, delim); - if (auto resolvedDynamic = TryMatchDependencies(fixedPath); !resolvedDynamic.empty()) { - return {UString(resolvedDynamic, allocator_).View().Utf8(), true}; + if (auto resolvedPath = TryResolvePath(fixedPath); !resolvedPath.empty()) { + return {UString(resolvedPath, allocator_).View().Utf8(), true}; } auto path = UString(fixedPath, allocator_).View(); @@ -557,6 +571,9 @@ util::StringView ImportPathManager::FormModuleName(const util::Path &path) } std::string const filePath(path.GetAbsolutePath()); + if (auto dmn = TryFormDynamicModuleName(arktsConfig_->Dependencies(), filePath); !dmn.empty()) { + return util::UString(dmn, allocator_).View(); + } if (auto res = TryFormModuleName(filePath, arktsConfig_->Package(), arktsConfig_->BaseUrl() + pathDelimiter_.data(), arktsConfig_->CacheDir()); res) { @@ -579,9 +596,6 @@ util::StringView ImportPathManager::FormModuleName(const util::Path &path) return util::UString(res.value(), allocator_).View(); } } - if (auto dmn = TryFormDynamicModuleName(arktsConfig_->Dependencies(), filePath); !dmn.empty()) { - return util::UString(dmn, allocator_).View(); - } // NOTE (hurton): as a last step, try resolving using the BaseUrl again without a path delimiter at the end if (auto res = TryFormModuleName(filePath, arktsConfig_->Package(), arktsConfig_->BaseUrl(), arktsConfig_->CacheDir()); diff --git a/ets2panda/util/importPathManager.h b/ets2panda/util/importPathManager.h index 02273bf0ec..833007cf85 100644 --- a/ets2panda/util/importPathManager.h +++ b/ets2panda/util/importPathManager.h @@ -183,6 +183,7 @@ private: std::string_view DirOrDirWithIndexFile(StringView dir) const; ResolvedPathRes AppendExtensionOrIndexFileIfOmitted(StringView basePath) const; std::string TryMatchDependencies(std::string_view fixedPath) const; + std::string TryResolvePath(std::string_view fixedPath) const; StringView GetRealPath(StringView path) const; void ProcessExternalLibraryImport(ImportMetadata &importData); std::string_view TryImportFromDeclarationCache(std::string_view resolvedImportPath) const; -- Gitee