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 0000000000000000000000000000000000000000..616c892c355635614e0fdce21da4bf1b80493ee9 --- /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 0000000000000000000000000000000000000000..9166781e59e20d6b4ba66532e9808b9f73f523dd --- /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 0000000000000000000000000000000000000000..cdf2ea6287fbddcd1e0cdca46d318679ba75ee62 --- /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 0000000000000000000000000000000000000000..e5f0d26c2145a9e948f31e9c9cf46a72282daabd --- /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 0000000000000000000000000000000000000000..52d6814886251ffdf466f89196b0bac4d82d04cb --- /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 0000000000000000000000000000000000000000..e3bcd41b3ded582b41e2952a94aac66325ded1fe --- /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 0000000000000000000000000000000000000000..528a013e16a4d2cf85c935cb821a48fadc32711a --- /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 9b64cc0f4be8977b0141df578c5881374dad3050..bd8d7512cdd24c778cc052605d2cf55518a54c4f 100644 --- a/ets2panda/util/importPathManager.cpp +++ b/ets2panda/util/importPathManager.cpp @@ -363,6 +363,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 @@ -386,8 +400,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(); @@ -508,6 +522,9 @@ util::StringView ImportPathManager::FormModuleName(const util::Path &path) return FormUnitName(unitName) + (relativePath.empty() || FormUnitName(unitName).empty() ? relativePath : ("." + relativePath)); }; + if (auto dmn = TryFormDynamicModuleName(arktsConfig_->Dependencies(), tryFormModuleName); !dmn.empty()) { + return util::UString(dmn, allocator_).View(); + } if (auto res = tryFormModuleName(arktsConfig_->Package(), arktsConfig_->BaseUrl() + pathDelimiter_.data()); res) { return util::UString(res.value(), allocator_).View(); } @@ -524,9 +541,6 @@ util::StringView ImportPathManager::FormModuleName(const util::Path &path) return util::UString(res.value(), allocator_).View(); } } - if (auto dmn = TryFormDynamicModuleName(arktsConfig_->Dependencies(), tryFormModuleName); !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(arktsConfig_->Package(), arktsConfig_->BaseUrl()); res) { return util::UString(res.value(), allocator_).View(); diff --git a/ets2panda/util/importPathManager.h b/ets2panda/util/importPathManager.h index 04c4742836122c14d39444927a3d9a39e15a6ea5..17703ef1b2ab0bf734bcf7cb80c54e705f90244f 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 ProcessExternalModuleImport(ImportMetadata &importData);