From 89bb9eb555b1a21c2dd8ed4e36e598ccc3bc618b Mon Sep 17 00:00:00 2001 From: lihao Date: Sun, 8 Jun 2025 16:16:07 +0800 Subject: [PATCH] bugfix:Check file belongs to folder Issue: [Bug]: Check file belongs to folder https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICDG7C Signed-off-by: lihao --- ets2panda/driver/build_system/package.json | 1 + .../build_system/src/build/base_mode.ts | 9 +++- .../demo_entry1.2_har1.2/build_config1.json | 23 +++++++++ .../demo_entry1.2_har1.2/build_config2.json | 23 +++++++++ .../demo_entry1.2_har1.2/build_config3.json | 51 +++++++++++++++++++ .../test/e2e/demo_entry1.2_har1.2/entry/a.ets | 25 +++++++++ .../e2e/demo_entry1.2_har1.2/harA/index.ets | 16 ++++++ .../e2e/demo_entry1.2_har1.2/harA/sub.ets | 18 +++++++ .../e2e/demo_entry1.2_har1.2/harAA/index.ets | 16 ++++++ .../e2e/demo_entry1.2_har1.2/harAA/sub.ets | 22 ++++++++ 10 files changed, 202 insertions(+), 2 deletions(-) create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config1.json create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config2.json create mode 100644 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config3.json create mode 100644 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/entry/a.ets create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/index.ets create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/sub.ets create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/index.ets create mode 100755 ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets diff --git a/ets2panda/driver/build_system/package.json b/ets2panda/driver/build_system/package.json index 92db8a38ca..7edeacd577 100644 --- a/ets2panda/driver/build_system/package.json +++ b/ets2panda/driver/build_system/package.json @@ -10,6 +10,7 @@ "build_debug": "npm run clean && tsc --sourceMap", "demo_entry1.2_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.2_hsp1.2/build_config2.json", "demo_entry1.2_hsp1.1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_hsp1.1/build_config.json", + "demo_entry1.2_har1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2/build_config2.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2/build_config3.json", "demo_entry1.1_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.1_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.1_hsp1.2/build_config2.json", "demo_entry1.2_har1.2_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config2.json", "demo_entry1.2_har1.2_hsp1.1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_har1.2_hsp1.1/build_config.json", diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 5796c8a413..0a4c64d516 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -633,8 +633,13 @@ export abstract class BaseMode { return; } this.entryFiles.forEach((file: string) => { - for (const [_, moduleInfo] of this.moduleInfos) { - if (!file.startsWith(moduleInfo.moduleRootPath)) { + // Skip the declaration files when compiling abc + if (file.endsWith(DECL_ETS_SUFFIX)) { + return; + } + for (const [packageName, moduleInfo] of this.moduleInfos) { + const relativePath = path.relative(moduleInfo.moduleRootPath, file); + if (relativePath.startsWith('..') || path.isAbsolute(relativePath)) { continue; } const filePathFromModuleRoot: string = path.relative(moduleInfo.moduleRootPath, file); diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config1.json new file mode 100755 index 0000000000..9944bc1b5c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config1.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets" + ], + "packageName": "harAA", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config2.json new file mode 100755 index 0000000000..220fd2e7f2 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config2.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/sub.ets" + ], + "packageName": "harA", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config3.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config3.json new file mode 100644 index 0000000000..3c4bf1c7d2 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/build_config3.json @@ -0,0 +1,51 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/entry/a.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/sub.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist/out/entry", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harA/index.ets", + "language": "1.2" + }, + { + "packageName": "harAA", + "moduleName": "harAA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2/harAA/index.ets", + "language": "1.2" + } + ], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/entry/a.ets new file mode 100644 index 0000000000..601d263597 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/entry/a.ets @@ -0,0 +1,25 @@ +/* + * 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 {sub} from 'harA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + console.log(ret) + let res = add(1, 2) + console.log(res) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/index.ets new file mode 100755 index 0000000000..279a65d222 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/index.ets @@ -0,0 +1,16 @@ +/* + * 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 { sub } from './sub' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/sub.ets new file mode 100755 index 0000000000..0ef62e9c7d --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harA/sub.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 function sub(a: number, b: number) { + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/index.ets new file mode 100755 index 0000000000..d21f768ae0 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/index.ets @@ -0,0 +1,16 @@ +/* + * 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 { sub,add } from './sub' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets new file mode 100755 index 0000000000..1c50393037 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2/harAA/sub.ets @@ -0,0 +1,22 @@ +/* + * 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 function sub(a: number, b: number) { + return (a - b)*1000 +} + +export function add(a: number, b: number) { + retrun a+b; +} \ No newline at end of file -- Gitee