diff --git a/ets2panda/driver/build_system/jest.config.js b/ets2panda/driver/build_system/jest.config.js index a3c4407a95294367a2c69376e842d290ef99a043..e0c185bcc12043270d24a3e1e1e635b76d9e1b76 100644 --- a/ets2panda/driver/build_system/jest.config.js +++ b/ets2panda/driver/build_system/jest.config.js @@ -16,5 +16,14 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', - testMatch: ['/test/**/*.test.ts'], + verbose: true, + collectCoverage: true, + coverageDirectory: '/dist/coverage', + setupFilesAfterEnv: [ + '/test/testHook/jest.memory-usage.js', + '/test/testHook/jest.time-usage.js', + '/test/testHook/jest.abc-size.js' + ], + testMatch: [], + testPathIgnorePatterns: [], }; \ No newline at end of file diff --git a/ets2panda/driver/build_system/package.json b/ets2panda/driver/build_system/package.json index 4aa6431aec5f32b92bcab162f354469b33e982e2..c4259b39b814b4978e5f40f719a7caa7cf30b308 100644 --- a/ets2panda/driver/build_system/package.json +++ b/ets2panda/driver/build_system/package.json @@ -8,6 +8,31 @@ "clean": "rimraf dist", "build": "npm run clean && tsc", "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.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", + "demo_entry1.1_har1.1_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config2.json", + + "demo_entry1.1_har1.2_hsp1.1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config2.json", + "demo_entry1.1_har1.2_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config2.json", + "demo_entry1.2_har1.1_hsp1.2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config2.json", + "demo_entry1.2_har1.1_hsp1.1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config1.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config2.json && node ./dist/entry.js test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config3.json", + + "demo_entry1_2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/demo_entry1_2/build_config.json", + "demo_har1_2:gen_decl": "npm run build && node ./dist/entry.js test/e2e/demo_har1_2/build_config_decl.json", + "demo_hsp1_2:gen_decl": "npm run build && node ./dist/entry.js test/e2e/demo_hsp1_2/build_config_decl.json", + + "entry1_1_external_har1_2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_1_external_har1_2/build_config.json", + "entry1_1_external_har1_2:gen_decl": "npm run build && node ./dist/entry.js test/e2e/entry1_1_external_har1_2/build_config_decl.json", + "entry1_1_external_hsp1_2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_1_external_hsp1_2/build_config_decl.json && node ./dist/entry.js test/e2e/entry1_1_external_hsp1_2/build_config.json", + "entry1_1_external_hsp1_2:gen_decl": "npm run build && node ./dist/entry.js test/e2e/entry1_1_external_hsp1_2/build_config_decl.json", + "entry1_2_external_har1_1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_2_external_har1_1/build_config.json", + "entry1_2_external_hsp1_1:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_2_external_hsp1_1/build_config.json", + "entry1_2_external_har1_2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_2_external_har1_2/build_config.json", + "entry1_2_external_hsp1_2:gen_abc": "npm run build && node ./dist/entry.js test/e2e/entry1_2_external_hsp1_2/build_config.json", + "entry1_2_external_hsp1_2:gen_decl": "npm run build && node ./dist/entry.js test/e2e/entry1_2_external_hsp1_2/build_config_decl.json", "mixed_hap:gen_decl": "npm run build && node ./dist/entry.js test/demo_mix_hap/build_config_decl.json", "mixed_hap:gen_abc": "node ./dist/entry.js test/demo_mix_hap/build_config.json", @@ -15,15 +40,37 @@ "demo_hap:gen_abc": "npm run build && node ./dist/entry.js test/demo_hap/build_config.json", - "ut_test": "jest test/ut" + "ut_test": "jest test/ut", + "build_system_Utest": "jest --testMatch='**/test/ut/**/*.test.ts' --testPathIgnorePatterns='test/e2e/'", + "build_system_Etest": "TEST=demo_entry1.2_hsp1.1:gen_abc jest --testMatch='**/test/e2e/*.test.ts' --testPathIgnorePatterns='test/ut/'" }, "devDependencies": { - "typescript": "^5.0.0", - "@types/node": "22.10.7", + "@babel/core": "^7.24.9", + "@babel/preset-env": "^7.24.9", + "@babel/preset-typescript": "^7.24.9", "@tsconfig/recommended": "1.0.8", - "rimraf": "6.0.1" + "@types/jest": "^29.5.12", + "@types/node": "22.10.7", + "babel-jest": "^29.7.0", + "jest": "^29.7.0", + "rimraf": "6.0.1", + "ts-node": "^10.9.2", + "ts-jest": "^29.1.1", + "typescript": "^5.0.0" + }, + "babel": { + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "current" + } + } + ], + "@babel/preset-typescript" + ] }, "dependencies": { - } } diff --git a/ets2panda/driver/build_system/src/build/declgen_worker.ts b/ets2panda/driver/build_system/src/build/declgen_worker.ts index 63968d0d15f648925d1c2121ed6144717caa5e27..d73fb6c3d9980058c4b4034b19deae0f76c553c9 100644 --- a/ets2panda/driver/build_system/src/build/declgen_worker.ts +++ b/ets2panda/driver/build_system/src/build/declgen_worker.ts @@ -44,6 +44,7 @@ process.on('message', (message: { const koalaWrapperPath = path.resolve(buildConfig.buildSdkPath, KOALA_WRAPPER_PATH_FROM_SDK); let { arkts, arktsGlobal } = require(koalaWrapperPath); + arktsGlobal.es2panda._SetUpSoPath(buildConfig.pandaSdkPath); for (const fileInfo of taskList) { let errorStatus = false; diff --git a/ets2panda/driver/build_system/test/e2e/checkHash.test.ts b/ets2panda/driver/build_system/test/e2e/checkHash.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..7200e42e3d521b7eb4c89a840a4e9083976172d1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/checkHash.test.ts @@ -0,0 +1,126 @@ +/* + * 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 fs from 'fs'; +import path from 'path'; +import crypto from 'crypto'; + +function getAllModules(config: any) { + return [ + { packageName: config.packageName, modulePath: config.moduleRootPath, sourceRoots: config.sourceRoots || ['./'] }, + ...(config.dependentModuleList || []) + ]; +} + +function getAllSrcFiles(modules: any[]) { + let allSrcFiles: string[] = []; + for (const mod of modules) { + const moduleAbsPath = path.resolve(__dirname, '../../', mod.modulePath || mod.moduleRootPath || ''); + for (const root of mod.sourceRoots || ['./']) { + const srcRoot = path.resolve(moduleAbsPath, root); + if (fs.existsSync(srcRoot) && fs.statSync(srcRoot).isDirectory()) { + const files = fs.readdirSync(srcRoot) + .filter(f => f.endsWith('.ets')) + .map(f => path.join(srcRoot, f)); + allSrcFiles = allSrcFiles.concat(files); + } + } + } + return allSrcFiles; +} + +function calcFileHash(filePath: string): string { + const content = fs.readFileSync(filePath); + return crypto.createHash('sha256').update(content).digest('hex'); +} + +function getScriptConfig(testScriptName: string): { configPath: string, config: any } { + const pkgJsonPath = path.resolve(__dirname, '../../package.json'); + let scripts: Record = {}; + if (fs.existsSync(pkgJsonPath)) { + try { + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')); + scripts = pkg.scripts || {}; + } catch { + scripts = {}; + } + } + if (!scripts[testScriptName]) { + throw new Error(`TEST environment variable "${testScriptName}" is not a valid script name in package.json`); + } + const match = scripts[testScriptName].match(/node\s+[^\s]+\s+([^\s]+\.json)/); + if (!match) { + throw new Error(`Script "${testScriptName}" does not contain a node command`); + } + const configPath = path.resolve(__dirname, '../../', match[1]); + if (!fs.existsSync(configPath)) { + throw new Error(`Config file not found: ${configPath}`); + } + const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); + return { configPath, config }; +} + +function getHashCache(cachePath: string): Record | null { + const hashCachePath = path.join(cachePath, 'hash_cache.json'); + if (!fs.existsSync(hashCachePath)) { + console.warn(`hash_cache.json: ${hashCachePath} does not exist. Maybe clean build?`); + return null; + } + const rawHashCache = JSON.parse(fs.readFileSync(hashCachePath, 'utf-8')); + const hashCache: Record = {}; + for (const key in rawHashCache) { + hashCache[path.resolve(key)] = rawHashCache[key]; + } + return hashCache; +} + +function checkFileHash(allSrcFiles: string[], hashCache: Record) { + allSrcFiles.forEach(srcFile => { + const absPath = path.resolve(srcFile); + const hashInCache = hashCache[absPath]; + const actualHash = calcFileHash(absPath); + if (!hashInCache) { + console.log(`${absPath} doesn't participate in incremental compilation`); + } else { + if (actualHash !== hashInCache) { + console.log(`[Jest][${absPath} changed, hash:\nnow (${actualHash})\nprevious (${hashInCache})]`); + } else { + console.log(`[Jest][${absPath} unchanged, hash: ${actualHash}]`); + } + } + }); +} + +function testHelper(testScriptName: string) { + const { configPath, config } = getScriptConfig(testScriptName); + const cachePath = path.resolve(__dirname, '../../', config.cachePath); + + describe(`Output Artifact Check [${configPath}]`, () => { + it('Check hash of all source files with hash_cache.json', () => { + const hashCache = getHashCache(cachePath); + if (!hashCache) return; + const modules = getAllModules(config); + const allSrcFiles = getAllSrcFiles(modules); + checkFileHash(allSrcFiles, hashCache); + }); + }); +} + +const testScriptName = process.env.TEST; +if (!testScriptName) { + throw new Error('Set the TEST environment variable to specify a script name'); +} else { + testHelper(testScriptName); +} diff --git a/ets2panda/driver/build_system/test/e2e/compile.test.ts b/ets2panda/driver/build_system/test/e2e/compile.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..74c47e6b5d68df795e5e8a72859d42c8ec02621b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/compile.test.ts @@ -0,0 +1,195 @@ +/* + * 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 { execFile } from 'child_process'; +import { promisify } from 'util'; +import fs from 'fs'; +import path from 'path'; + +const execFileAsync = promisify(execFile); + +function getAllFilesWithExt(dir: string, exts: string[]): string[] { + if (!fs.existsSync(dir)) return []; + let result: string[] = []; + const entries = fs.readdirSync(dir, { withFileTypes: true }); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + result = result.concat(getAllFilesWithExt(fullPath, exts)); + } else if (exts.some(ext => entry.name.endsWith(ext))) { + result.push(fullPath); + } + } + return result; +} + +function getConfigAndPaths(testScriptName: string) { + const pkgJsonPath = path.resolve(__dirname, '../../package.json'); + let scripts: Record = {}; + if (fs.existsSync(pkgJsonPath)) { + try { + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')); + scripts = pkg.scripts || {}; + } catch { + scripts = {}; + } + } + if (!scripts[testScriptName]) { + throw new Error(`TEST environment variable "${testScriptName}" is not a valid script name in package.json`); + } + const script = scripts[testScriptName]; + const match = script.match(/node\s+([^\s]+)\s+([^\s]+\.json)/); + if (!match) { + throw new Error(`Script "${testScriptName}" does not contain a node ...config.json command`); + } + const configPath = path.resolve(__dirname, '../../', match[2]); + if (!fs.existsSync(configPath)) { + throw new Error(`Config file not found: ${configPath}`); + } + const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); + const cachePath = path.resolve(__dirname, '../../', config.cachePath); + return { config, configPath, cachePath }; +} + +function getExpectedOutputs(config: any, cachePath: string) { + const allModules = [ + { packageName: config.packageName, modulePath: config.moduleRootPath }, + ...(config.dependentModuleList || []).map((m: any) => ({ + packageName: m.packageName, + modulePath: m.modulePath + })) + ]; + return (config.compileFiles || []).map((src: string) => { + let matchedModule = allModules.find(m => { + const moduleAbs = path.resolve(__dirname, '../../', m.modulePath); + const absSrc = path.isAbsolute(src) ? src : path.resolve(moduleAbs, src); + const rel = path.relative(moduleAbs, absSrc); + return !rel.startsWith('..') && !path.isAbsolute(rel); + }); + if (!matchedModule) { + matchedModule = { packageName: config.packageName, modulePath: config.moduleRootPath }; + } + const moduleAbs = path.resolve(__dirname, '../../', matchedModule.modulePath); + const absSrc = path.isAbsolute(src) ? src : path.resolve(moduleAbs, src); + let relSrc = path.relative(moduleAbs, absSrc); + if (!relSrc || relSrc === '') { + relSrc = path.basename(absSrc); + } + return path.join( + cachePath, + matchedModule.packageName, + relSrc.replace(/\.[^/.]+$/, '.abc') + ); + }); +} + +async function runCompile(testScriptName: string): Promise { + try { + await execFileAsync('npm', ['run', testScriptName]); + } catch (err: any) { + throw new Error(`Fail to compile: ${err.stderr || err.message}`); + } +} + +function checkArktsConfig(config: any, cachePath: string) { + it('should generate arktsconfig.json in cachePath', () => { + const arktsConfigPath = path.join(cachePath, config.packageName, 'arktsconfig.json'); + if (!fs.existsSync(arktsConfigPath)) { + throw new Error(`Missing ${arktsConfigPath}`); + } + }); +} + +function checkDeclgenOutputs(config: any) { + const outPaths = [ + config.declgenBridgeCodePath, + config.declgenV1OutPath, + config.declgenV2OutPath + ].filter(Boolean); + outPaths.forEach(outPath => { + it(`should generate files in ${outPath}`, () => { + const absOutPath = path.resolve(__dirname, '../../', outPath); + if (!fs.existsSync(absOutPath) || !fs.statSync(absOutPath).isDirectory()) { + console.warn(`[Jest][${absOutPath} not found or not a directory, skip check.]`); + return; + } + const files = getAllFilesWithExt(absOutPath, ['.ts', '.d.ts', '.json', '.js', '.ets']); + if (files.length === 0) { + console.warn(`[Jest][${absOutPath} exists but no output files found, skip check.]`); + return; + } + files.forEach(f => console.log(`[Jest][${absOutPath} found output: ${f}]`)); + expect(files.length).toBeGreaterThan(0); + }); + }); +} + +function checkModuleRootDeclFiles(config: any) { + it('should generate declaration files in moduleRootPath', () => { + const absModuleRoot = path.resolve(__dirname, '../../', config.moduleRootPath); + if (!fs.existsSync(absModuleRoot) || !fs.statSync(absModuleRoot).isDirectory()) { + throw new Error(`[Jest][${absModuleRoot} not found or not a directory]`); + } + const declFiles = getAllFilesWithExt(absModuleRoot, ['.d.ts', '.ts', '.json']); + expect(declFiles.length).toBeGreaterThan(0); + }); +} + +function checkAbcFiles(expectedOutputs: string[]) { + it('should generate abc files for compileFiles', () => { + expectedOutputs.forEach(filePath => { + if (!fs.existsSync(filePath)) { + throw new Error(`Missing ${filePath}`); + } + if (fs.statSync(filePath).size === 0) { + throw new Error(`${filePath} exists but is empty`); + } + }); + }); +} + +function checkArtifacts(config: any, cachePath: string, expectedOutputs: string[]) { + checkArktsConfig(config, cachePath); + + if (config.enableDeclgenEts2Ts) { + checkDeclgenOutputs(config); + if (!config.compileFiles || config.compileFiles.length === 0) { + checkModuleRootDeclFiles(config); + } + } else { + if (config.compileFiles && config.compileFiles.length > 0) { + checkAbcFiles(expectedOutputs); + } else { + checkModuleRootDeclFiles(config); + } + } +} + +function testHelper(testScriptName: string) { + const { config, configPath, cachePath } = getConfigAndPaths(testScriptName); + const expectedOutputs = getExpectedOutputs(config, cachePath); + + describe(`Output Artifact Check [${configPath}]`, () => { + beforeAll(() => runCompile(testScriptName)); + checkArtifacts(config, cachePath, expectedOutputs); + }); +} + +const testScriptName = process.env.TEST; +if (!testScriptName) { + throw new Error('Set the TEST environment variable to specify a script name'); +} else { + testHelper(testScriptName); +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..540ae17e589a7a9a2796244c61319b7a406cac40 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config1.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/Calc.ets" + ], + + "packageName": "hspA", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/", + "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.1_har1.1_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..d7a47e61c8b7b3cbd74d3418e53119269ba4df5f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/build_config2.json @@ -0,0 +1,33 @@ +{ + "compileFiles": [], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.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": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..750382839f54bc587083a8897ba6e92621ede399 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/entry/a.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. + */ +import {sub} from 'harA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + console.log(ret) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..279a65d222d490fcf5865fd3faecae9778fb89f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.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.1_har1.1_hsp1.2/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.1_hsp1.2/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..d3170e03ef91b57d24572fe0eb68d3f960815c11 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config1.json @@ -0,0 +1,24 @@ +{ + "compileFiles": [], + + "packageName": "hspA", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA", + "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": [ + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..d1ba6641731478dd9cae087d515a03985c07777d --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/build_config2.json @@ -0,0 +1,50 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "entry", + "bundleName": "com.example.demo_entry1.1_har1.2_hsp1.1", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/entry", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out", + "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/", + "useNormalizedOHMUrl": true, + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/index.ets", + "dependencies": [ "hspA" ], + "language": "1.2" + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.ets", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/decl-fileInfo.json", + "language": "1.1" + } + ], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c121339edde088c7176b991247224b575b52197 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..279a65d222d490fcf5865fd3faecae9778fb89f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/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.1_har1.2_hsp1.1/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..049b59eb62ca233c46124a861e8adbc9a88fdd54 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.d.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 declare function add(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..c0c0e433a2afa1ac83aaa0373d296fed69ae02ad --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "hspA", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.1_har1.2_hsp1.1&hspA/index&" + }, + "Calc": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/Calc.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.1_har1.2_hsp1.1&hspA/Calc&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..ec09d8a883f34664c8c739070568beef7ae9f911 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.d.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 { add } from './Calc'; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.1/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..a06617898011aa33e0ac4cd4b092a04e8bce0514 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config1.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/index.ets" + ], + + "packageName": "hsp", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets1", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..5c8ba385fe2db402a307e305f22ce1e5981edf1e --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/build_config2.json @@ -0,0 +1,51 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.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", + "hasMainModule": true, + + "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.1_har1.2_hsp1.2/harA", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/index.ets", + "dependencies": [ + "hspA" + ], + "language": "1.2" + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..750382839f54bc587083a8897ba6e92621ede399 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/entry/a.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. + */ +import {sub} from 'harA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + console.log(ret) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..279a65d222d490fcf5865fd3faecae9778fb89f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.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.1_har1.2_hsp1.2/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..d8cfec133211ff63679de3e43a3af2073a08d6df --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/Calc.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 add(a: number, b: number) { + return a + b +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_har1.2_hsp1.2/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..21ffecc50df6ede6f5f71b5a6e8f6da1fb834673 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/build_config1.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/hsp/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/hsp/Calc.ets" + ], + + "packageName": "hsp", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/hsp/", + "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.1_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..ca2a934d3088117255c7c5c9e8aef26214736c3e --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/build_config2.json @@ -0,0 +1,34 @@ +{ + "compileFiles": [ + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/", + "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": "hsp", + "moduleName": "hsp", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/hsp", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.1_hsp1.2/hsp/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..ac4b0a305dbe2ec0ef92971a22018bf593427872 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/entry/a.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. + */ +import { add } from 'hsp' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.1_hsp1.2/hsp/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..c8b751563ac7f441aacae2524d4e2650d8cc8104 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config1.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [], + + "packageName": "hspA", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/hspA", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenBridgeCodePath": "./dist/declgen/ets", + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..5edb23b2534de11f2f40a239ac256eaeac0f52aa --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config2.json @@ -0,0 +1,24 @@ +{ + "compileFiles": [], + + "packageName": "harA", + "moduleType": "har", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/harA", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config3.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config3.json new file mode 100755 index 0000000000000000000000000000000000000000..7b0d5e819e7063fb74d243198d8955831e7b4126 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/build_config3.json @@ -0,0 +1,48 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/entry/a.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/entry", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/entry", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + + "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.1_hsp1.1/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.ets", + "language": "1.1", + "dependencies": [ "hspA" ], + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/decl-fileInfo.json" + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.ets", + "language": "1.1", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/decl-fileInfo.json" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..b91b35349f7624285e3e2a2826203d54f5271c22 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/entry/a.ets @@ -0,0 +1,26 @@ +/* + * 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' +import {add} from 'hspA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + let ret2 = add(1, 2) + console.log(ret) + console.log(ret2) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..9e68f1d9f87f84ea99de690978221652eb83ca29 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/decl-fileInfo.json @@ -0,0 +1,9 @@ +{ + "packageName": "harA", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.1_hsp1.1&harA/index&1.0.0" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..065354359652e4500a749cd7c411b3ed01acdc27 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.d.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 declare function sub(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..5b3dcef764cc039d28de1dc8b471f47d809c5c44 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/harA/index.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.1_hsp1.1/hspA/Calc.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..049b59eb62ca233c46124a861e8adbc9a88fdd54 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.d.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 declare function add(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..fd7cb4ff5306abeb4a09cc660fd46a0fe685eca1 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "hspA", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.1_hsp1.1&hspA/index&" + }, + "Calc": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/Calc.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.1_hsp1.1&hspA/Calc&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..ec09d8a883f34664c8c739070568beef7ae9f911 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.d.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 { add } from './Calc'; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.1/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..1f60eac75d58c4ad7c3b9a9c02c3e918bccc20a6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config1.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/Calc.ets" + ], + + "packageName": "hspA", + "moduleType": "shared", + "hasMainModule": true, + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/hspA", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..fab627cabc7518c96bdfc70818570f24855f472c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/build_config2.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/entry/a.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/entry", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/entry", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + + "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.1_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.ets", + "language": "1.1", + "dependencies": [ "hspA" ], + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/decl-fileInfo.json" + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..b91b35349f7624285e3e2a2826203d54f5271c22 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/entry/a.ets @@ -0,0 +1,26 @@ +/* + * 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' +import {add} from 'hspA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + let ret2 = add(1, 2) + console.log(ret) + console.log(ret2) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..8e0b06d1a55f2a4d524e7d7bf3b5de12fab3566f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/decl-fileInfo.json @@ -0,0 +1,9 @@ +{ + "packageName": "harA", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.1_hsp1.2&harA/index&1.0.0" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..065354359652e4500a749cd7c411b3ed01acdc27 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.d.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 declare function sub(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..5b3dcef764cc039d28de1dc8b471f47d809c5c44 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/harA/index.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.1_hsp1.2/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.1_hsp1.2/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/build_config.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..b46713de0f2313c04eafaab3bfd48bdbde07d95a --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/build_config.json @@ -0,0 +1,51 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/entry/a.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "entry", + "bundleName": "com.example.demo_entry1.2_har1.2_hsp1.1", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/entry/", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out", + "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/", + "useNormalizedOHMUrl": true, + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/index.ets", + "dependencies": [ "hspA" ], + "language": "1.2" + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.ets", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/decl-fileInfo.json", + "language": "1.1" + } + ], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c121339edde088c7176b991247224b575b52197 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..279a65d222d490fcf5865fd3faecae9778fb89f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/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_hsp1.1/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..049b59eb62ca233c46124a861e8adbc9a88fdd54 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.d.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 declare function add(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..fd854ab5d83b336c2d0c0d3f2a25eb76712e5725 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "hspA", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.2_hsp1.1&hspA/index&" + }, + "Calc": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/Calc.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.demo_entry1.2_har1.2_hsp1.1&hspA/Calc&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..ec09d8a883f34664c8c739070568beef7ae9f911 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.d.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 { add } from './Calc'; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.1/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..cec7a7664dc2c940be641610dc25b8d0a4afcf81 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config1.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/Calc.ets" + ], + + "packageName": "hspA", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/hspA", + "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": [ + ], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..af1bc8a9805859bc2d1acced8e114b34e4e2d007 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/build_config2.json @@ -0,0 +1,48 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/entry/a.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.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_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/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_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..1c121339edde088c7176b991247224b575b52197 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..279a65d222d490fcf5865fd3faecae9778fb89f6 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.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_hsp1.2/harA/sub.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_har1.2_hsp1.2/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/build_config.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..5c1a110fc87374a2e821b5f64a0e9a17e699ab86 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/build_config.json @@ -0,0 +1,37 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/entry/a.ets" + ], + + "packageName": "entry", + "moduleType": "entry", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/entry/", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out/", + "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": "hsp", + "moduleName": "hsp", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/hsp", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.ets", + "language": "1.1", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/hsp/decl-fileInfo.json" + } + ], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..b3b59b3cf47c6b44d346acb75b5d3158ff0b4728 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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 { add } from 'hsp' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..049b59eb62ca233c46124a861e8adbc9a88fdd54 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.d.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 declare function add(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.d.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..ec09d8a883f34664c8c739070568beef7ae9f911 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.d.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 { add } from './Calc'; diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..2fefcb5704fd9cfa4325f0e9f1926f09e553c2e4 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.1/hsp/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "hsp", + "files": { + "Index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/hsp/Index.d.ets", + "ohmUrl": "@normalized:N&undefined&&hsp/Index&" + }, + "Calc": { + "declPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.1/hsp/Calc.d.ets", + "ohmUrl": "@normalized:N&undefined&&hsp/Calc&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..6f88b5d9850482e08ee01b98d4d7f87442cf7bc8 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config1.json @@ -0,0 +1,27 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/hsp/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/hsp/Calc.ets" + ], + + "packageName": "hsp", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/hsp/", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out/", + "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": [], + "hasMainModule": true +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..42c0caa1dab27eed9e9fbdfd9dc2f47b02f2671c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/build_config2.json @@ -0,0 +1,36 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/entry/a.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/", + "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": "hsp", + "moduleName": "hsp", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/hsp", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/demo_entry1.2_hsp1.2/hsp/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_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..b3b59b3cf47c6b44d346acb75b5d3158ff0b4728 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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 { add } from 'hsp' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1.2_hsp1.2/hsp/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/demo_entry1_2/build_config.json b/ets2panda/driver/build_system/test/e2e/demo_entry1_2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..a6673efea3887c47f11f56f1fdee8578d9080c79 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1_2/build_config.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_entry1_2/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_entry1_2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "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/entry/index.ets b/ets2panda/driver/build_system/test/e2e/demo_entry1_2/entry/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..76a66d7bbfd24d99a07b0ee71e0e6225ec62d355 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_entry1_2/entry/index.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. + */ + +function main() { + let a: string = "hello world" + console.log(a) +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_har1_2/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_har1_2/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..5b3dcef764cc039d28de1dc8b471f47d809c5c44 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_har1_2/Calc.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_har1_2/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/demo_har1_2/build_config_decl.json new file mode 100755 index 0000000000000000000000000000000000000000..6d808ef1d6da3070b8115b83100882747b342070 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_har1_2/build_config_decl.json @@ -0,0 +1,22 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_har1_2/index.ets", + "${absolute_path_to_build_system}/test/e2e/demo_har1_2/Calc.ets" + ], + "packageName": "demo_har1_2", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_har1_2/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "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_har1_2/index.ets b/ets2panda/driver/build_system/test/e2e/demo_har1_2/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..6ebf762a0625a3da62495af734fa637e0305864a --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_har1_2/index.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. + */ + +export {sub} from './Calc.ets'; + +export function add(a: number, b: number) { + return a + b; +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/Calc.ets b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/build_config_decl.json new file mode 100755 index 0000000000000000000000000000000000000000..96a16c44d40aa7954f546062d136226191d4041b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/build_config_decl.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/demo_hsp1_2/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/demo_hsp1_2/index.ets" + ], + "packageName": "demo_hsp1_2", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/demo_hsp1_2/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "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_hsp1_2/index.ets b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..1ce82dab16cddc169ac8db70b81e44dbbee03a99 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/demo_hsp1_2/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 { add } from './Calc' \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..47fcd7ad54e8ef90f91982ee716bcdcfb922b492 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config.json @@ -0,0 +1,36 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_1_external_har1_2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "har1_2", + "moduleName": "har1_2", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config_decl.json new file mode 100755 index 0000000000000000000000000000000000000000..cdfbd1366ebaad4df7b04a6be4463ab89edf07aa --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/build_config_decl.json @@ -0,0 +1,28 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets" + ], + + "packageName": "har1_2", + "moduleType": "har", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/", + "sourceRoots": ["./"], + + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "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/entry1_1_external_har1_2/entry/index.ets b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/entry/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..cf378006256059c1540a9dff040cfca43dc50e6f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_har1_2/entry/index.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 { add, sub } from 'har1_2' + +add(5, 3); +sub(5, 3); diff --git a/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..8e9d8491551ec63b9212a91e969643a25569ab21 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config.json @@ -0,0 +1,33 @@ +{ + "compileFiles": [], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_1_external_hsp1_2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "hsp1_2", + "moduleName": "hsp1_2", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config_decl.json new file mode 100755 index 0000000000000000000000000000000000000000..eff1e4b05fa72a3c52d34cf0fc044ee7024c72d7 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/build_config_decl.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/index.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/Calc.ets" + ], + "packageName": "hsp1_2", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": true, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "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/entry1_1_external_hsp1_2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..f8b43b294e7f374b694a3c7155d7b327bdb7b27c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_1_external_hsp1_2/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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 { add } from 'hsp1_2' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..9f1508fd0e172016e9d7404684cdd25c1b2cb32f --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/build_config.json @@ -0,0 +1,36 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/entry1_2_external_har1_1/entry/index.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_2_external_har1_1/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenBridgeCodePath": "./dist/declgen/ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "hasMainModule": true, + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "har1_1", + "moduleName": "har1_1", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1/index.ets", + "language": "1.1", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1/decl-fileInfo.json" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/entry/index.ets b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/entry/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..3d9f89e235be647db16b3a46697883340ddb9842 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_1/entry/index.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. + */ + +import { sub } from 'har1_1' // should be insert by ui-plugins + +sub(5, 3); diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..fadb8532edad64040e4c98b0239c9536bde78578 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/build_config.json @@ -0,0 +1,37 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/entry1_2_external_har1_2/entry/index.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/Calc.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_2_external_har1_2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "hasMainModule": true, + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "har1_2", + "moduleName": "har1_2", + "moduleType": "har", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/entry/index.ets b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/entry/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..a145d71c7eb9cc3df117770058f4a9eb08768d18 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_har1_2/entry/index.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 { add, sub } from 'har1_2' // should be insert by ui-plugins + +add(5, 3); +sub(5, 3); diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..cf47e9786431e9cc64ad3e365acef53f1393ade8 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/build_config.json @@ -0,0 +1,37 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/entry1_2_external_hsp1_1/entry/a.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_2_external_hsp1_1/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "declgenBridgeCodePath": "./dist/declgen/ets", + "hasMainModule": true, + + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "hsp1_1", + "moduleName": "hsp1_1", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/", + "sourceRoots": ["./"], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/index.ets", + "language": "1.1", + "declFilesPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/decl-fileInfo.json" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/entry/a.ets b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..97b6bf8fcd41c5b1882ecafba06eece4996542fc --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_1/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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 { add } from 'hsp1_1' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config.json b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..4e77dda86bef8418f9a58bd09092fe549e3270ea --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config.json @@ -0,0 +1,35 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/entry1_2_external_hsp1_2/entry/a.ets" + ], + "packageName": "entry", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/entry1_2_external_hsp1_2/entry/", + "sourceRoots": [ + "./", + "src/main1/ets" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "hasMainModule": true, + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [ + { + "packageName": "hsp1_2", + "moduleName": "hsp1_2", + "moduleType": "shared", + "modulePath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2", + "sourceRoots": [ + "./" + ], + "entryFile": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config_decl.json b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config_decl.json new file mode 100755 index 0000000000000000000000000000000000000000..c41f6bb97f789b7db80709307333c3b28647ac63 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/build_config_decl.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/index.ets" + ], + "packageName": "hsp", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/", + "sourceRoots": [ + "./" + ], + "loaderOutPath": "./dist/out/", + "cachePath": "./dist/cache", + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "./dist/declgen/decl_ets", + "declgenV2OutPath": "./dist/declgen/decl_ets2", + "hasMainModule": true, + "declgenBridgeCodePath": "./dist/declgen/ets", + "buildSdkPath": "${absolute_path_to_build_system}/test/mock_sdk/", + "dependentModuleList": [] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/entry/a.ets b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..f8b43b294e7f374b694a3c7155d7b327bdb7b27c --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/entry1_2_external_hsp1_2/entry/a.ets @@ -0,0 +1,23 @@ +/* + * 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 { add } from 'hsp1_2' + +function main() { + let a: string = "hello world" + console.log(a) + let sum = add(2, 1) + console.log(sum) +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/build_config_har1_1.json b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_har1_1.json new file mode 100755 index 0000000000000000000000000000000000000000..1ac8e12ca9f586b09645a7cabf58966b04407805 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_har1_1.json @@ -0,0 +1,22 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1/index.ets" + ], + "packageName": "har1_1", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1/", + "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/externalProject/build_config_har1_2.json b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_har1_2.json new file mode 100755 index 0000000000000000000000000000000000000000..5c5a833f71ef4b3c84665bffe48a2874de49acc9 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_har1_2.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/index.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/Calc.ets" + ], + "packageName": "har1_2", + "moduleType": "har", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_2/", + "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/externalProject/build_config_hsp1_1.json b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_hsp1_1.json new file mode 100755 index 0000000000000000000000000000000000000000..8d2fc7de1a0246ef9990d09e4da0ac92751e42d4 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_hsp1_1.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/index.d.ets" + ], + "packageName": "hsp1_1", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/", + "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/externalProject/build_config_hsp1_2.json b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_hsp1_2.json new file mode 100755 index 0000000000000000000000000000000000000000..be6d80e0cf78eaff8f95044d244ee6fed34bfbd0 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/build_config_hsp1_2.json @@ -0,0 +1,23 @@ +{ + "compileFiles": [ + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/Calc.ets", + "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/index.ets" + ], + "packageName": "hsp1_2", + "moduleType": "shared", + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_2/", + "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/externalProject/har1_1/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..070789e7af09f39bb8c8b1f3c4236d2d403a92be --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/decl-fileInfo.json @@ -0,0 +1,9 @@ +{ + "packageName": "har1_1", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/externalProject/har1_1/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.externalProject&har1_1/index" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.d.ets b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..065354359652e4500a749cd7c411b3ed01acdc27 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.d.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 declare function sub(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..5b3dcef764cc039d28de1dc8b471f47d809c5c44 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/har1_1/index.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/externalProject/har1_2/Calc.ets b/ets2panda/driver/build_system/test/e2e/externalProject/har1_2/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..5b3dcef764cc039d28de1dc8b471f47d809c5c44 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/har1_2/Calc.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/externalProject/har1_2/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/har1_2/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..6ebf762a0625a3da62495af734fa637e0305864a --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/har1_2/index.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. + */ + +export {sub} from './Calc.ets'; + +export function add(a: number, b: number) { + return a + b; +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.d.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..049b59eb62ca233c46124a861e8adbc9a88fdd54 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.d.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 declare function add(a: number, b: number): number; diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/decl-fileInfo.json b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/decl-fileInfo.json new file mode 100755 index 0000000000000000000000000000000000000000..e74f427e5073eaf77e6898d0d28d24ccb6043d69 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/decl-fileInfo.json @@ -0,0 +1,13 @@ +{ + "packageName": "hsp", + "files": { + "index": { + "declPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/index.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.externalProject&hsp1_1/index&" + }, + "Calc": { + "declPath": "${absolute_path_to_build_system}/test/e2e/externalProject/hsp1_1/Calc.d.ets", + "ohmUrl": "@normalized:N&undefined&com.example.externalProject&hsp1_1/Calc&" + } + } +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/index.d.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/index.d.ets new file mode 100755 index 0000000000000000000000000000000000000000..ec09d8a883f34664c8c739070568beef7ae9f911 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/index.d.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 { add } from './Calc'; diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_1/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/Calc.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/index.ets b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/e2e/externalProject/hsp1_2/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/testHook/jest.abc-size.js b/ets2panda/driver/build_system/test/testHook/jest.abc-size.js new file mode 100755 index 0000000000000000000000000000000000000000..44225f3a1ee0fa25859814d5b0b6378be2f43399 --- /dev/null +++ b/ets2panda/driver/build_system/test/testHook/jest.abc-size.js @@ -0,0 +1,51 @@ +/* + * 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. + */ + +const fs = require('fs'); +const path = require('path'); + +function getAllAbcFiles(dir) { + let results = []; + if (!fs.existsSync(dir)) return results; + const list = fs.readdirSync(dir, { withFileTypes: true }); + for (const entry of list) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + results = results.concat(getAllAbcFiles(fullPath)); + } else if (entry.isFile() && entry.name.endsWith('.abc')) { + results.push(fullPath); + } + } + return results; +} + +function formatSize(bytes) { + if (bytes < 1024) return `${bytes} B`; + if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`; + return `${(bytes / 1024 / 1024).toFixed(2)} MB`; +} + +afterAll(() => { + const cacheDir = path.resolve(__dirname, '../../dist/cache'); + const abcFiles = getAllAbcFiles(cacheDir); + if (abcFiles.length === 0) { + console.warn(`[Jest][No .abc files found in ${cacheDir}]`); + return; + } + abcFiles.forEach(file => { + const size = fs.statSync(file).size; + console.log(`[Jest][${file}] size: ${formatSize(size)}`); + }); +}); diff --git a/ets2panda/driver/build_system/test/testHook/jest.memory-usage.js b/ets2panda/driver/build_system/test/testHook/jest.memory-usage.js new file mode 100755 index 0000000000000000000000000000000000000000..d0c3f7748e6d35248c74e9f5cdaa32c26bcb4cbc --- /dev/null +++ b/ets2panda/driver/build_system/test/testHook/jest.memory-usage.js @@ -0,0 +1,28 @@ +/* + * 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. + */ + +let startMem = 0; + +beforeEach(() => { + global.gc?.(); + startMem = process.memoryUsage().heapUsed; +}); + +afterEach(() => { + const endMem = process.memoryUsage().heapUsed; + const peak = (endMem - startMem) / 1024 / 1024; + const testName = expect.getState().currentTestName; + console.log(`[Jest][${testName} used ${peak.toFixed(2)} MB]`); +}); diff --git a/ets2panda/driver/build_system/test/testHook/jest.time-usage.js b/ets2panda/driver/build_system/test/testHook/jest.time-usage.js new file mode 100755 index 0000000000000000000000000000000000000000..3a95e76b83b5fa67e472e3415b0b53d1d92e7f38 --- /dev/null +++ b/ets2panda/driver/build_system/test/testHook/jest.time-usage.js @@ -0,0 +1,27 @@ +/* + * 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. + */ + +let startTime = 0; + +beforeEach(() => { + startTime = Date.now(); +}); + +afterEach(() => { + const endTime = Date.now(); + const duration = endTime - startTime; + const testName = expect.getState().currentTestName; + console.log(`[Jest][${testName} spent ${duration} ms]`); +}); diff --git a/ets2panda/driver/build_system/test/ut/base_modeTest/base_mode.test.ts b/ets2panda/driver/build_system/test/ut/base_modeTest/base_mode.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..3213406d6f15d5cf53ed0b1e03c7f43b717aeae1 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/base_modeTest/base_mode.test.ts @@ -0,0 +1,1095 @@ +/* + * 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 * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; +import * as entryModule from '../../../src/entry'; +import { BaseMode } from '../../../src/build/base_mode'; +import { BuildConfig, BUILD_TYPE, BUILD_MODE, OHOS_MODULE_TYPE, ModuleInfo } from '../../../src/types'; +import { BuildMode } from '../../../src/build/build_mode'; +import { isWindows, isMac } from '../../../src/utils'; +import { + ErrorCode, +} from '../../../src/error_code'; +import cluster, { + Cluster, +} from 'cluster'; + +interface Job { + id: string; + type?: string; + dependencies: string[]; + dependants: string[]; + fileList?: string[]; + isDeclFile?: boolean; + isAbcJob?: boolean; + isInCycle?: boolean; + result?: any; +} + +interface WorkerInfo { + worker: ThreadWorker; + isIdle: boolean; +} + +interface ThreadWorker { + postMessage: (message: any) => void; +} + +interface Queues { + externalProgramQueue: Job[]; + abcQueue: Job[]; +} + +interface DependencyFileConfig { + dependencies: Record; + dependants: Record; +} + +jest.mock('os', () => ({ + ...jest.requireActual('os'), + type: jest.fn().mockReturnValue('Darwin') +})); + +beforeEach(() => { + jest.clearAllMocks(); + process.exit = jest.fn() as any; +}); + +beforeAll(() => { + const { execSync } = require('child_process'); + execSync('rimraf test/ut/mock/dist', { stdio: 'pipe' }); +}); + +function main(configFilePath?: string): void { + const buildConfigPath = configFilePath; + + const projectConfig: BuildConfig = JSON.parse(fs.readFileSync(buildConfigPath!, 'utf-8')); + + entryModule.build(projectConfig); +} + +describe('test mock isWindows', () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.spyOn(os, 'type').mockReturnValue('Windows_NT'); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + test('test mac001', () => { + test_mac001(); + }); +}); + +function test_mac001() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config4.json"; + main(buildConfigPath); + expect(isWindows()).toBe(true); +} + +describe('test mock isMac', () => { + beforeEach(() => { + jest.clearAllMocks(); + jest.spyOn(os, 'type').mockReturnValue('Darwin'); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + test('test mac002', () => { + test_mac002(); + }); +}); + +function test_mac002() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config5.json"; + main(buildConfigPath); + expect(isMac()).toBe(true); +} + +describe('test base_mode.ts file api', () => { + test('test collectModuleInfos', () => { + test_collectModuleInfos(); + }); + + test('test collectDependentCompileFiles002', () => { + test_collectDependentCompileFiles002(); + }); + + test('test shouldSkipFile', () => { + test_shouldSkipFile(); + }); + + test('test setupCluster', () => { + test_setupCluster(); + }); + + test('test terminateAllWorkers', () => { + test_terminateAllWorkers(); + }); + + test('test collectModuleInfos 001', () => { + test_collectDependencyModules001(); + }); + + test('test collectModuleInfos 002', () => { + test_collectDependencyModules002(); + }); + + test('test runall new', () => { + test_runParallell1(); + }); + + test('test test_collectAbcFileFromByteCodeHar', () => { + test_collectAbcFileFromByteCodeHar(); + }); + + test('test getDependentModules', async () => { + test_getDependentModules(); + }); + + test('collectCompileFiles: test declaration files skip branch', () => { + test_collectCompileFiles_decl_ets_skip(); + }); + + test('collectCompileFiles: test bytecode HAR branch', () => { + test_collectCompileFiles_bytecode_har(); + }); + + test('collectCompileFiles: test file not in module path branch', () => { + test_collectCompileFiles_file_not_in_module(); + }); + + test('test createExternalProgramJob method branches', () => { + test_createExternalProgramJob_branches(); + }); + + test('test findStronglyConnectedComponents method branches', () => { + test_findStronglyConnectedComponents_branches(); + }); + + test('test assignTaskToIdleWorker abcQueue branch without job', () => { + test_assignTaskToIdleWorker_abcQueue_no_job(); + }); + + test('test assignTaskToIdleWorker with empty queues', () => { + test_assignTaskToIdleWorker_empty_queues(); + }); +}); + +function test_assignTaskToIdleWorker_empty_queues() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockConfig = { + packageName: "test", + moduleType: "har", + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache" + }; + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue(mockLogger); + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + + public testAssignTaskToIdleWorker( + workerInfo: WorkerInfo, + queues: Queues, + processingJobs: Set, + serializableConfig: Object, + globalContextPtr: any + ): void { + (this as any).assignTaskToIdleWorker( + workerInfo, + queues, + processingJobs, + serializableConfig, + globalContextPtr + ); + } + } + const baseMode = new TestBaseMode(mockConfig as any); + const mockWorker = { + postMessage: jest.fn() + }; + + const workerInfo: WorkerInfo = { + worker: mockWorker as unknown as ThreadWorker, + isIdle: true + }; + + const queues: Queues = { + externalProgramQueue: [], + abcQueue: [] + }; + + const processingJobs = new Set(); + const serializableConfig = {}; + const globalContextPtr = {}; + + (baseMode as any).allFiles = new Map([ + ['test/file.ets', { + filePath: 'test/file.ets', + packageName: 'test', + arktsConfigFile: 'test/config.json', + abcFilePath: './dist/file.abc' + }] + ]); + + const postMessageSpy = jest.spyOn(mockWorker, 'postMessage'); + + baseMode.testAssignTaskToIdleWorker( + workerInfo, + queues, + processingJobs, + serializableConfig, + globalContextPtr + ); + + expect(postMessageSpy).not.toHaveBeenCalled(); + expect(processingJobs.size).toBe(0); + expect(workerInfo.isIdle).toBe(true); + jest.restoreAllMocks(); +} + +function test_assignTaskToIdleWorker_abcQueue_no_job() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockConfig = { + packageName: "test", + moduleType: "har", + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache" + }; + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue(mockLogger); + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + public testAssignTaskToIdleWorker( + workerInfo: WorkerInfo, + queues: Queues, + processingJobs: Set, + serializableConfig: Object, + globalContextPtr: any + ): void { + (this as any).assignTaskToIdleWorker( + workerInfo, + queues, + processingJobs, + serializableConfig, + globalContextPtr + ); + } + } + + const baseMode = new TestBaseMode(mockConfig as any); + + const mockWorker = { + postMessage: jest.fn() + }; + + const workerInfo: WorkerInfo = { + worker: mockWorker as unknown as ThreadWorker, + isIdle: true + }; + + const queues: Queues = { + externalProgramQueue: [], + abcQueue: [{ + id: 'abc:test/nonexistentfile.ets', + type: 'abc', + dependencies: [], + dependants: [], + result: null, + fileList: ['test/nonexistentfile.ets'], + isDeclFile: false, + isAbcJob: true + }] + }; + + const processingJobs = new Set(); + const serializableConfig = {}; + const globalContextPtr = {}; + + (baseMode as any).allFiles = new Map([ + ['test/otherfile.ets', { + filePath: 'test/otherfile.ets', + packageName: 'test', + arktsConfigFile: 'test/config.json', + abcFilePath: './dist/otherfile.abc' + }] + ]); + + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => { }); + const postMessageSpy = jest.spyOn(mockWorker, 'postMessage'); + try { + baseMode.testAssignTaskToIdleWorker( + workerInfo, + queues, + processingJobs, + serializableConfig, + globalContextPtr + ); + fail('Expected method to throw, but it did not'); + } catch (error) { + expect(error).toBeInstanceOf(ReferenceError); + expect(workerInfo.isIdle).toBe(false); + } finally { + consoleSpy.mockRestore(); + jest.restoreAllMocks(); + } +} + +function test_findStronglyConnectedComponents_branches() { + const mockConfig = { + packageName: "test", moduleRootPath: "/test/path", sourceRoots: ["./"], + loaderOutPath: "./dist", cachePath: "./dist/cache", buildMode: "Debug" + }; + + class TestBaseMode extends BaseMode { + public run(): Promise { return Promise.resolve(); } + public testFindStronglyConnectedComponents(graph: DependencyFileConfig): Map> { + return (this as any).findStronglyConnectedComponents(graph); + } + protected createHash(input: string): string { return 'cycle-group-' + input.length; } + } + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue({ printInfo: jest.fn(), printError: jest.fn() }); + const baseMode = new TestBaseMode(mockConfig as any); + const graph1 = { + dependencies: { 'A': ['B', 'C'], 'B': ['C'], 'C': ['A'] }, + dependants: { 'A': ['C'], 'B': ['A'], 'C': ['A', 'B'] } + }; + const result1 = baseMode.testFindStronglyConnectedComponents(graph1); + expect(result1.size).toBe(1); + expect(Array.from(result1.values())[0].size).toBe(3); + const graph2 = { + dependencies: { 'A': ['B', 'C'], 'B': ['D'], 'C': ['D'], 'D': ['E'], 'E': ['B'] }, + dependants: { 'A': [], 'B': ['A', 'E'], 'C': ['A'], 'D': ['B', 'C'], 'E': ['D'] } + }; + const result2 = baseMode.testFindStronglyConnectedComponents(graph2); + expect(result2.size).toBe(1); + expect(Array.from(result2.values())[0].size).toBe(3); + const graph3 = { + dependencies: { 'A': ['B'], 'B': ['C'], 'C': ['D'], 'D': [], 'E': ['F'], 'F': ['E'] }, + dependants: { 'A': [], 'B': ['A'], 'C': ['B'], 'D': ['C'], 'E': ['F'], 'F': ['E'] } + }; + const result3 = baseMode.testFindStronglyConnectedComponents(graph3); + expect(result3.size).toBe(1); + expect(Array.from(result3.values())[0].size).toBe(2); + const graph4 = { + dependencies: { 'A': ['B'], 'B': ['C'], 'C': ['D'], 'D': [] }, + dependants: { 'A': [], 'B': ['A'], 'C': ['B'], 'D': ['C'] } + }; + const result4 = baseMode.testFindStronglyConnectedComponents(graph4); + expect(result4.size).toBe(0); +} + +function test_createExternalProgramJob_branches() { + const mockConfig = { + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + buildMode: "Debug", + moduleType: "har" + }; + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + + public testCreateExternalProgramJob(id: string, fileList: string[], jobs: Record, dependencies: Set, isInCycle?: boolean): void { + return (this as any).createExternalProgramJob(id, fileList, jobs, dependencies, isInCycle); + } + } + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue({ + printInfo: jest.fn(), + printError: jest.fn() + }); + + const baseMode = new TestBaseMode(mockConfig as any); + + { + const id = "external-program:test/file.ets"; + const fileList = ["test/file.ets"]; + const jobs: Record = {}; + const dependencies = new Set([id, "external-program:other.ets"]); + const isInCycle = false; + + baseMode.testCreateExternalProgramJob(id, fileList, jobs, dependencies, isInCycle); + + expect(dependencies.has(id)).toBe(false); + expect(dependencies.size).toBe(1); + + expect(jobs[id]).toBeDefined(); + expect(jobs[id].id).toBe(id); + expect(jobs[id].fileList).toEqual(fileList); + expect(jobs[id].isDeclFile).toBe(true); + expect(jobs[id].isInCycle).toBe(false); + expect(jobs[id].dependencies).toEqual(["external-program:other.ets"]); + expect(jobs[id].dependants).toEqual([]); + } + + { + const id = "external-program:test/file2.ets"; + const fileList = ["test/file2.ets", "test/file2b.ets"]; + const jobs: Record = { + [id]: { + id, + fileList: ["test/file2.ets"], + isDeclFile: false, + isInCycle: false, + isAbcJob: false, + dependencies: ["external-program:dep1.ets"], + dependants: ["external-program:dep3.ets"] + } + }; + + const dependencies = new Set(["external-program:dep2.ets"]); + const isInCycle = true; + + baseMode.testCreateExternalProgramJob(id, fileList, jobs, dependencies, isInCycle); + + expect(jobs[id]).toBeDefined(); + expect(jobs[id].id).toBe(id); + expect(jobs[id].fileList).toEqual(["test/file2.ets"]); + expect(jobs[id].isDeclFile).toBe(false); + expect(jobs[id].isInCycle).toBe(false); + expect(jobs[id].dependencies).toContain("external-program:dep1.ets"); + expect(jobs[id].dependencies).toContain("external-program:dep2.ets"); + expect(jobs[id].dependencies.length).toBe(2); + expect(jobs[id].dependants).toEqual(["external-program:dep3.ets"]); + } +} + +function test_collectCompileFiles_bytecode_har() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockConfig = { + packageName: "test", + moduleType: "har", + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + enableDeclgenEts2Ts: true, + dependentModuleList: [] + }; + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + + public testCollectCompileFiles(): void { + this.collectCompileFiles(); + } + + public testCollectAbcFileFromByteCodeHar(): void { + this.collectAbcFileFromByteCodeHar(); + } + } + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue(mockLogger); + const baseMode = new TestBaseMode(mockConfig as any); + + (baseMode as any).cacheDir = "./dist/cache"; + (baseMode as any).abcFiles = new Set(); + (baseMode as any).hashCache = {}; + (baseMode as any).compileFiles = new Map(); + + (baseMode as any).entryFiles = new Set([ + '/test/path/test.ets' + ]); + + (baseMode as any).moduleInfos = new Map(); + (baseMode as any).moduleInfos.set("test", { + packageName: "test", + moduleType: "har", + byteCodeHar: true, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + arktsConfigFile: "./dist/cache/test/config.json", + compileFileInfos: [] + }); + + (global as any).getFileHash = jest.fn().mockReturnValue("hash123"); + const utils = require('../../../src/utils'); + + jest.spyOn(baseMode, 'testCollectAbcFileFromByteCodeHar').mockImplementation(() => { }); + + baseMode.testCollectCompileFiles(); +} + +function test_collectCompileFiles_file_not_in_module() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockConfig = { + packageName: "test", + moduleType: "har", + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + enableDeclgenEts2Ts: true, + dependentModuleList: [] + }; + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + + public testCollectCompileFiles(): void { + this.collectCompileFiles(); + } + } + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue(mockLogger); + const baseMode = new TestBaseMode(mockConfig as any); + + (baseMode as any).cacheDir = "./dist/cache"; + (baseMode as any).abcFiles = new Set(); + (baseMode as any).hashCache = {}; + (baseMode as any).compileFiles = new Map(); + + (baseMode as any).entryFiles = new Set([ + '/other/path/test.ets' + ]); + + (baseMode as any).moduleInfos = new Map(); + (baseMode as any).moduleInfos.set("test", { + packageName: "test", + moduleType: "har", + byteCodeHar: false, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + arktsConfigFile: "./dist/cache/test/config.json", + compileFileInfos: [] + }); + + baseMode.testCollectCompileFiles(); + + expect(mockLogger.printError).toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCode.BUILDSYSTEM_FILE_NOT_BELONG_TO_ANY_MODULE_FAIL, + description: 'File does not belong to any module in moduleInfos.' + }) + ); + + expect((baseMode as any).compileFiles.size).toBe(0); +} + +function test_collectCompileFiles_decl_ets_skip() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockConfig = { + packageName: "test", + moduleType: "har", + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + enableDeclgenEts2Ts: true, + dependentModuleList: [] + }; + + class TestBaseMode extends BaseMode { + public run(): Promise { + return Promise.resolve(); + } + + public testCollectCompileFiles(): void { + this.collectCompileFiles(); + } + } + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance = jest.fn().mockReturnValue(mockLogger); + const baseMode = new TestBaseMode(mockConfig as any); + + (baseMode as any).cacheDir = "./dist/cache"; + (baseMode as any).abcFiles = new Set(); + (baseMode as any).hashCache = {}; + (baseMode as any).compileFiles = new Map(); + + (baseMode as any).entryFiles = new Set([ + './test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets', + '/test/path/test.d.ets' + ]); + + (baseMode as any).moduleInfos = new Map(); + (baseMode as any).moduleInfos.set("test", { + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + arktsConfigFile: "./dist/cache/test/config.json", + compileFileInfos: [] + }); + + (global as any).getFileHash = jest.fn().mockReturnValue("hash123"); + const utils = require('../../../src/utils'); + + baseMode.testCollectCompileFiles(); +} + +function test_collectDependencyModules001() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config6.json"; + main(buildConfigPath); +} + +function test_collectDependencyModules002() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config7.json"; + main(buildConfigPath); +} + +function test_collectAbcFileFromByteCodeHar() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config8.json"; + main(buildConfigPath); +} + +function test_getDependentModules() { + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config9.json"; + main(buildConfigPath); +} + +async function test_runParallell1() { + const mockLogger = { + printInfo: jest.fn(), + printError: jest.fn() + }; + + const mockCluster = { + isPrimary: true, + fork: jest.fn().mockReturnValue({ + on: jest.fn(), + send: jest.fn() + }), + workers: {}, + removeAllListeners: jest.fn(), + setupPrimary: jest.fn() + }; + + jest.spyOn(cluster, 'fork').mockImplementation(mockCluster.fork); + jest.spyOn(cluster, 'removeAllListeners').mockImplementation(mockCluster.removeAllListeners); + jest.spyOn(cluster, 'setupPrimary').mockImplementation(mockCluster.setupPrimary); + + const mockConfig = { + packageName: "test", + compileFiles: ["test/file.ets"], + moduleRootPath: "test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + buildMode: "Debug" + }; + + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + + class TestBuildMode extends BuildMode { + + public generateModuleInfos(): void { + } + + public setupCluster(): void { + } + + public mergeAbcFiles(): void { + } + } + + const baseMode = new TestBuildMode(mockConfig as any); + + jest.spyOn(baseMode, 'generateModuleInfos').mockImplementation(() => { }); + jest.spyOn(baseMode, 'setupCluster').mockImplementation(() => { }); + jest.spyOn(baseMode, 'mergeAbcFiles').mockImplementation(() => { }); + + (baseMode as any).logger = mockLogger; + + await baseMode.runParallell(); + + expect(baseMode.generateModuleInfos).toHaveBeenCalled(); + expect(baseMode.setupCluster).toHaveBeenCalled(); + expect(baseMode.mergeAbcFiles).toHaveBeenCalled(); +} + +function test_collectModuleInfos() { + const mockLogger = { + printError: jest.fn(), + printInfo: jest.fn() + }; + const mockConfig: BuildConfig = { + buildMode: BUILD_MODE.DEBUG, + compileFiles: ["test.ets"], + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + plugins: {}, + buildType: BUILD_TYPE.BUILD, + hasMainModule: true, + moduleType: OHOS_MODULE_TYPE.HAR, + arkts: {} as any, + arktsGlobal: {} as any, + enableDeclgenEts2Ts: false, + byteCodeHar: false, + declgenV1OutPath: "./dist/declgen", + declgenV2OutPath: "./dist/declgen/v2", + buildSdkPath: "./sdk", + externalApiPaths: [], + + dependentModuleList: [ + { + "packageName": "", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "index.ets", + "language": "11.2", + "dependencies": ["hspA"], + "byteCodeHar": false + }, + { + "packageName": "", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "11.2", + "byteCodeHar": false + } + ] + }; + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + let baseModule: BuildMode = new BuildMode(mockConfig); + (baseModule as any).collectModuleInfos(); + + expect(mockLogger.printError).not.toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCode.BUILDSYSTEM_MODULE_INFO_NOT_CORRECT_FAIL, + description: 'Main module info from hvigor is not correct.' + }) + ); +} + +function test_collectDependentCompileFiles002() { + const mockLogger = { + printError: jest.fn(), + printInfo: jest.fn(), + hasErrors: jest.fn().mockReturnValue(false) + }; + + const moduleRootPath = "test/ut/mock/demo_1.2_dep_hsp1.2/entry/"; + const testFile = `${moduleRootPath}a.ets`; + + const mockConfig: BuildConfig = { + compileFiles: [testFile], + packageName: "entry", + moduleType: OHOS_MODULE_TYPE.HAR, + buildType: BUILD_TYPE.BUILD, + buildMode: BUILD_MODE.DEBUG, + moduleRootPath: moduleRootPath, + sourceRoots: ["./"], + loaderOutPath: "test/ut/mock/dist", + cachePath: "test/ut/mock/dist/cache", + dependentModuleList: [], + plugins: {}, + hasMainModule: false, + arkts: {} as any, + arktsGlobal: {} as any, + enableDeclgenEts2Ts: false, + byteCodeHar: false, + declgenV1OutPath: "./dist/declgen", + declgenV2OutPath: "./dist/declgen/v2", + buildSdkPath: "./sdk", + externalApiPaths: [] + }; + + const BaseMode = require('../../../src/build/base_mode').BaseMode; + const BuildMode = require('../../../src/build/build_mode').BuildMode; + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + let baseModule = new BuildMode(mockConfig); + + (baseModule as any).logger = mockLogger; + (baseModule as any).moduleInfos = new Map(); + (baseModule as any).moduleInfos.set("entry", { + packageName: "entry", + moduleRootPath: moduleRootPath, + sourceRoots: ["./"], + compileFileInfos: [] + }); + + (baseModule as any).entryFiles = new Set([testFile]); + (baseModule as any).dependencyFileMap = { + dependants: { + [testFile]: ["dependency1.ets", "dependency2.ets"] + } + }; + (baseModule as any).cacheDir = "test/ut/mock/dist/cache"; + (baseModule as any).hashCache = {}; + (baseModule as any).abcFiles = new Set(); + (baseModule as any).compileFiles = new Map(); + + (baseModule as any).isBuildConfigModified = true; + + (baseModule as any).isFileChanged = jest.fn().mockReturnValue(false); + + (baseModule as any).collectDependentCompileFiles(); + + expect(mockLogger.printError).not.toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCode.BUILDSYSTEM_FILE_NOT_BELONG_TO_ANY_MODULE_FAIL, + message: 'File does not belong to any module in moduleInfos.' + }) + ); + + expect((baseModule as any).abcFiles.size).toBe(1); + const compileFilesArray = Array.from((baseModule as any).compileFiles.keys()); + expect(compileFilesArray.length).toBe(1); + expect(compileFilesArray[0]).toBe(testFile); +} + +function test_shouldSkipFile() { + const mockLogger = { printError: jest.fn() }; + const mockConfig: BuildConfig = { + buildMode: BUILD_MODE.DEBUG, + compileFiles: ["test.ets"], + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + plugins: {}, + dependentModuleList: [], + buildType: BUILD_TYPE.BUILD, + hasMainModule: false, + moduleType: OHOS_MODULE_TYPE.HAR, + byteCodeHar: false, + arkts: {} as any, + arktsGlobal: {} as any, + declgenV1OutPath: "./dist/declgen", + declgenV2OutPath: "./dist/declgen/v2", + buildSdkPath: "./sdk", + externalApiPaths: [], + enableDeclgenEts2Ts: false + }; + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + let baseModule: BaseMode = new BuildMode(mockConfig); + (baseModule as any).logger = mockLogger; + (baseModule as any).hashCache = { + "/test/path/file.ets": "hash123" + }; + + const file = "/test/path/file.ets"; + const moduleInfo: ModuleInfo = { + isMainModule: false, + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + arktsConfigFile: "/cache/test/arktsconfig.json", + compileFileInfos: [], + declgenV1OutPath: "/dist/declgen", + declgenBridgeCodePath: "/dist/bridge", + dynamicDepModuleInfos: new Map(), + staticDepModuleInfos: new Map(), + moduleType: OHOS_MODULE_TYPE.HAR, + entryFile: "index.ets", + declgenV2OutPath: "/dist/declgen/v2", + byteCodeHar: false + }; + const filePathFromModuleRoot = "file.ets"; + const abcFilePath = "/cache/test/file.abc"; + + (baseModule as any).enableDeclgenEts2Ts = true; + let result3 = (baseModule as any).shouldSkipFile(file, moduleInfo, filePathFromModuleRoot, abcFilePath); + (baseModule as any).enableDeclgenEts2Ts = false; + let result4 = (baseModule as any).shouldSkipFile(file, moduleInfo, filePathFromModuleRoot, abcFilePath); + expect(result3).toBe(false); + expect(result4).toBe(false); +} + +function test_setupCluster() { + const mockConfig: BuildConfig = { + buildMode: BUILD_MODE.DEBUG, + compileFiles: ["test.ets"], + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + plugins: {}, + dependentModuleList: [], + maxWorkers: 1, + buildType: BUILD_TYPE.BUILD, + hasMainModule: true, + arkts: {} as any, + arktsGlobal: {} as any, + enableDeclgenEts2Ts: false, + moduleType: OHOS_MODULE_TYPE.HAR, + declgenV1OutPath: "./dist/declgen", + declgenV2OutPath: "./dist/declgen/v2", + buildSdkPath: "./sdk", + byteCodeHar: false, + externalApiPaths: [] + }; + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + let baseModule: BaseMode = new BuildMode(mockConfig); + + const originalRemoveAllListeners = cluster.removeAllListeners; + const originalSetupPrimary = cluster.setupPrimary; + + const removeAllListenersSpy = jest.fn(); + cluster.removeAllListeners = removeAllListenersSpy; + + const setupPrimarySpy = jest.fn(); + cluster.setupPrimary = setupPrimarySpy; + + try { + (baseModule as any).setupCluster(cluster, { + clearExitListeners: false, + execPath: '/path/to/worker', + execArgs: [] + }); + + expect(removeAllListenersSpy).not.toHaveBeenCalled(); + expect(setupPrimarySpy).toHaveBeenCalledWith({ + exec: '/path/to/worker', + execArgv: [] + }); + } finally { + cluster.removeAllListeners = originalRemoveAllListeners; + cluster.setupPrimary = originalSetupPrimary; + } +} + +function test_terminateAllWorkers() { + const mockConfig: BuildConfig = { + buildMode: BUILD_MODE.DEBUG, + compileFiles: ["test.ets"], + packageName: "test", + moduleRootPath: "/test/path", + sourceRoots: ["./"], + loaderOutPath: "./dist", + cachePath: "./dist/cache", + plugins: {}, + dependentModuleList: [], + buildType: BUILD_TYPE.BUILD, + hasMainModule: true, + arkts: {} as any, + arktsGlobal: {} as any, + enableDeclgenEts2Ts: false, + moduleType: OHOS_MODULE_TYPE.HAR, + declgenV1OutPath: "./dist/declgen", + declgenV2OutPath: "./dist/declgen/v2", + buildSdkPath: "./sdk", + byteCodeHar: false, + externalApiPaths: [] + }; + const Logger = require('../../../src/logger').Logger; + Logger.instance = null; + Logger.getInstance(mockConfig); + let baseModule: BaseMode = new BuildMode(mockConfig); + + const originalWorkers = cluster.workers; + + try { + Object.defineProperty(cluster, 'workers', { + value: {}, + configurable: true + }); + + expect(() => { + (baseModule as any).terminateAllWorkers(); + }).not.toThrow(); + + Object.defineProperty(cluster, 'workers', { + value: undefined, + configurable: true + }); + + expect(() => { + (baseModule as any).terminateAllWorkers(); + }).not.toThrow(); + } finally { + Object.defineProperty(cluster, 'workers', { + value: originalWorkers, + configurable: true + }); + } +} diff --git a/ets2panda/driver/build_system/test/ut/entryTest/entry.test.ts b/ets2panda/driver/build_system/test/ut/entryTest/entry.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..22feac87f48efdb7d0b01641b5e498c427f41a64 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/entryTest/entry.test.ts @@ -0,0 +1,84 @@ +/* + * 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 * as fs from 'fs'; +import * as entryModule from '../../../src/entry'; +import { BuildConfig } from '../../../src/types'; + +beforeEach(() => { + jest.clearAllMocks(); + + process.exit = jest.fn() as any; + +}); + +function main(configFilePath?: string): void { + const buildConfigPath = configFilePath; + + const projectConfig: BuildConfig = JSON.parse(fs.readFileSync(buildConfigPath!, 'utf-8')); + + entryModule.build(projectConfig); +} + +describe('test entry.ts file api', () => { + test('test build001', () => { + test_build001(); + }); + test('test build002', () => { + test_build002(); + }); + test('test build003', () => { + test_build003(); + }); + test('test build004', () => { + test_build004(); + }); +}); + +function test_build001() { + const buildSpy = jest.spyOn(entryModule, 'build'); + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config3.json"; + main(buildConfigPath); + expect(buildSpy).toHaveBeenCalledWith(expect.objectContaining({ + buildType: 'build' + })); +} + +function test_build002() { + const buildSpy = jest.spyOn(entryModule, 'build'); + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config.json"; + main(buildConfigPath); + expect(buildSpy).toHaveBeenCalledWith(expect.objectContaining({ + buildType: 'build1' + })); +} + +function test_build003() { + const buildSpy = jest.spyOn(entryModule, 'build'); + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config1.json"; + main(buildConfigPath); + expect(buildSpy).toHaveBeenCalledWith(expect.objectContaining({ + frameworkMode: true, + })); +} + +function test_build004() { + const buildSpy = jest.spyOn(entryModule, 'build'); + const buildConfigPath = "test/ut/mock/demo_1.2_dep_hsp1.2/build_config2.json"; + main(buildConfigPath); + expect(buildSpy).toHaveBeenCalledWith(expect.objectContaining({ + enableDeclgenEts2Ts: true, + })); +} diff --git a/ets2panda/driver/build_system/test/ut/fileManagerTest/filemanager.test.ts b/ets2panda/driver/build_system/test/ut/fileManagerTest/filemanager.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..4beba39f104d6748739bc37952cd8281f5bad762 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/fileManagerTest/filemanager.test.ts @@ -0,0 +1,216 @@ +/* + * 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 { FileManager } from '../../../src/plugins/FileManager'; +import { LANGUAGE_VERSION } from '../../../src/pre_define'; +import * as utils from '../../../src/utils'; + +describe('class FileManager', () => { + const mockBuildConfig = { + dependentModuleList: [ + { + packageName: 'modA', + modulePath: '/mock/path/modA', + language: LANGUAGE_VERSION.ARKTS_1_2 + } + ], + externalApiPaths: ['/mock/staticApi'], + buildSdkPath: '/mock/sdk', + compileFiles: ['/mock/project/main.ets'] + }; + + afterEach(() => { + FileManager.cleanFileManagerObject(); + FileManager.arkTSModuleMap.clear(); + FileManager.staticApiPath.clear(); + FileManager.dynamicApiPath.clear(); + // Make tsc ignore the access of private member + // @ts-ignore + FileManager.buildConfig = undefined; + }); + + it('should initialize singleton and static properties', () => { + FileManager.init(mockBuildConfig as any); + expect(FileManager.getInstance()).toBeInstanceOf(FileManager); + expect(FileManager.buildConfig).toEqual(mockBuildConfig); + expect(FileManager.staticApiPath.size).toBe(1); + expect(FileManager.dynamicApiPath.size).toBe(2); + expect(FileManager.arkTSModuleMap.size).toBe(1); + }); + + it('should clean singleton instance', () => { + FileManager.init(mockBuildConfig as any); + FileManager.cleanFileManagerObject(); + // Make tsc ignore the access of private member + // @ts-ignore + expect(FileManager.instance).toBeUndefined(); + }); + + it('should add staticApiPath and dynamicApiPath in initSDK', () => { + FileManager.initSDK(new Set(['/api1', '/api2']), '/sdk/path'); + expect(FileManager.staticApiPath.has('/api1')).toBe(true); + expect(FileManager.staticApiPath.has('/api2')).toBe(true); + expect(FileManager.dynamicApiPath.size).toBe(2); + }); + + it('should handle empty externalApiPath in initSDK', () => { + FileManager.initSDK(new Set(), '/sdk/path'); + expect(FileManager.staticApiPath.size).toBe(0); + expect(FileManager.dynamicApiPath.size).toBe(2); + }); + + it('should get correct language version by file path', () => { + FileManager.init(mockBuildConfig as any); + const fm = FileManager.getInstance(); + expect(fm.getLanguageVersionByFilePath('/mock/staticApi/abc.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_2); + const [dynPath] = Array.from(FileManager.dynamicApiPath); + expect(fm.getLanguageVersionByFilePath(`${dynPath}/abc.ets`)).toBe(LANGUAGE_VERSION.ARKTS_1_1); + expect(fm.getLanguageVersionByFilePath('/mock/project/main.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_2); + expect(fm.getLanguageVersionByFilePath('/mock/path/modA/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_2); + expect(fm.getLanguageVersionByFilePath('/other/path/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_1); + }); + + it('should return ARKTS_1_2 if first line is use static in hybrid module', () => { + FileManager.init({ + ...mockBuildConfig, + dependentModuleList: [ + { + packageName: 'modH', + modulePath: '/mock/hybrid', + language: LANGUAGE_VERSION.ARKTS_HYBRID + } + ] + } as any); + const fm = FileManager.getInstance(); + // Make tsc ignore the access of private member + // @ts-ignore + jest.spyOn(FileManager as any, 'isFirstLineUseStatic').mockReturnValue(true); + expect(fm.getLanguageVersionByFilePath('/mock/hybrid/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_2); + }); + + it('should handle empty dependentModuleList in initLanguageVersionFromDependentModuleMap', () => { + // Make tsc ignore the access of private member + // @ts-ignore + FileManager['initLanguageVersionFromDependentModuleMap']([]); + expect(FileManager.arkTSModuleMap.size).toBe(0); + }); + + it('should getInstance auto new when not initialized', () => { + // Make tsc ignore the access of private member + // @ts-ignore + FileManager.instance = undefined; + expect(FileManager.getInstance()).toBeInstanceOf(FileManager); + }); + + it('should return ARKTS_1_1 for hybrid module if first line is not use static', () => { + FileManager.init({ + dependentModuleList: [ + { + packageName: 'modH', + modulePath: '/mock/hybrid', + language: LANGUAGE_VERSION.ARKTS_HYBRID + } + ], + externalApiPaths: [], + buildSdkPath: '/mock/sdk', + compileFiles: [] + } as any); + const fm = FileManager.getInstance(); + // Make tsc ignore the access of private member + // @ts-ignore + jest.spyOn(FileManager as any, 'isFirstLineUseStatic').mockReturnValue(false); + expect(fm.getLanguageVersionByFilePath('/mock/hybrid/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_1); + }); + + it('should allow cleanFileManagerObject to be called multiple times', () => { + FileManager.init({ + dependentModuleList: [], + externalApiPaths: [], + buildSdkPath: '/mock/sdk', + compileFiles: [] + } as any); + FileManager.cleanFileManagerObject(); + expect(FileManager.getInstance()).toBeInstanceOf(FileManager); + FileManager.cleanFileManagerObject(); + // Make tsc ignore the access of private member + // @ts-ignore + expect(FileManager.instance).toBeUndefined(); + }); + + it('should return ARKTS_1_1 if staticApiPath and dynamicApiPath are empty', () => { + FileManager.cleanFileManagerObject(); + FileManager.staticApiPath.clear(); + FileManager.dynamicApiPath.clear(); + FileManager.arkTSModuleMap.clear(); + // Make tsc ignore the access of private member + // @ts-ignore + FileManager.buildConfig = { compileFiles: [] }; + const fm = FileManager.getInstance(); + expect(fm.getLanguageVersionByFilePath('/any/path/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_1); + }); + + it('should return module language if not hybrid', () => { + FileManager.init({ + dependentModuleList: [ + { + packageName: 'modB', + modulePath: '/mock/path/modB', + language: LANGUAGE_VERSION.ARKTS_1_2 + } + ], + externalApiPaths: [], + buildSdkPath: '/mock/sdk', + compileFiles: [] + } as any); + const fm = FileManager.getInstance(); + expect(fm.getLanguageVersionByFilePath('/mock/path/modB/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_2); + }); + + it('should isFirstLineUseStatic returns false when first line is not use static', () => { + jest.spyOn(utils, 'readFirstLineSync').mockReturnValue('not static'); + + // @ts-ignore + expect(FileManager['isFirstLineUseStatic']('anyfile.ets')).toBe(false); + }); + + it('should init does nothing if already initialized', () => { + FileManager.init(mockBuildConfig as any); + const instance = FileManager.getInstance(); + FileManager.init({ + ...mockBuildConfig, + buildSdkPath: '/another/path' + } as any); + expect(FileManager.getInstance()).toBe(instance); + }); + + it('should cleanFileManagerObject does nothing if instance is undefined', () => { + // @ts-ignore + FileManager.instance = undefined; + expect(() => FileManager.cleanFileManagerObject()).not.toThrow(); + }); + + it('should getLanguageVersionByFilePath handles undefined compileFiles', () => { + FileManager.cleanFileManagerObject(); + // @ts-ignore + FileManager.buildConfig = {}; + const fm = FileManager.getInstance(); + expect(fm.getLanguageVersionByFilePath('/any/path/file.ets')).toBe(LANGUAGE_VERSION.ARKTS_1_1); + }); + + it('should initSDK handles undefined externalApiPath', () => { + // @ts-ignore + expect(() => FileManager.initSDK(undefined, '/sdk/path')).not.toThrow(); + }); +}); \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/generate_arktsconfigTest/generate_arktsconfig.test.ts b/ets2panda/driver/build_system/test/ut/generate_arktsconfigTest/generate_arktsconfig.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..aa044c0a81a49358b4424a2dc0dd034eadff6557 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/generate_arktsconfigTest/generate_arktsconfig.test.ts @@ -0,0 +1,114 @@ +/* + * 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 * as fs from 'fs'; +import path from 'path'; +import { ArkTSConfigGenerator } from '../../../src/build/generate_arktsconfig'; +import { ModuleInfo } from '../../../src/types'; + +jest.mock('../../../src/build/generate_arktsconfig', () => { + const actual = jest.requireActual('../../../src/build/generate_arktsconfig'); + function MockArkTSConfigGenerator(this: any, ...args: any[]) { } + MockArkTSConfigGenerator.prototype = actual.ArkTSConfigGenerator.prototype; + Object.getOwnPropertyNames(actual.ArkTSConfigGenerator).forEach((key) => { + if (!['prototype', 'length', 'name'].includes(key)) { + (MockArkTSConfigGenerator as any)[key] = actual.ArkTSConfigGenerator[key]; + } + }); + + return { + ArkTSConfigGenerator: MockArkTSConfigGenerator, + __esModule: true, + }; +}); + +describe('test generate_arktsconfig.ts file api', () => { + test('test getInstance', () => { + expect(() => { + ArkTSConfigGenerator.getInstance(); + }).toThrow('buildConfig and moduleInfos is required for the first instantiation of ArkTSConfigGenerator.'); + }); + + test('test getOhmurl', () => { + test_getOhmurl(); + }); + + test('test writeArkTSConfigFile', () => { + test_writeArkTSConfigFile(); + }); +}); + + +function test_writeArkTSConfigFile() { + // Mock getInstance to bypass the private constructor + jest.spyOn(ArkTSConfigGenerator, 'getInstance').mockImplementation(() => { + return Object.create(ArkTSConfigGenerator.prototype); + }); + const generator = ArkTSConfigGenerator.getInstance(); + (generator as any).logger = { + printWarn: jest.fn(), + printErrorAndExit: jest.fn(() => { throw new Error('exit'); }) + }; + (generator as any).moduleInfos = new Map(); + + const moduleInfo: ModuleInfo = { + isMainModule: true, + packageName: 'test-pkg', + moduleRootPath: '/tmp/test-module', + moduleType: 'type', + sourceRoots: [], + entryFile: 'index.ets', + arktsConfigFile: 'arktsconfig.json', + compileFileInfos: [], + declgenV1OutPath: undefined, + declgenV2OutPath: undefined, + declgenBridgeCodePath: undefined, + byteCodeHar: false, + staticDepModuleInfos: new Map(), + dynamicDepModuleInfos: new Map(), + }; + + expect(() => { + generator.writeArkTSConfigFile(moduleInfo, false); + }).toThrow('exit'); +} + +function test_getOhmurl() { + const moduleInfo: ModuleInfo = { + isMainModule: true, + packageName: 'example-package', + moduleRootPath: '/path/to/module', + moduleType: 'type', + sourceRoots: ['/src'], + entryFile: 'index.ts', + arktsConfigFile: 'arktsconfig.json', + compileFileInfos: [], + declgenV1OutPath: undefined, + declgenV2OutPath: undefined, + declgenBridgeCodePath: undefined, + byteCodeHar: false, + staticDepModuleInfos: new Map(), + dynamicDepModuleInfos: new Map(), + }; + + const filePath = ''; + const expectedUrl = 'example-package/'; + jest.spyOn(ArkTSConfigGenerator, 'getInstance').mockImplementation(() => { + return Object.create(ArkTSConfigGenerator.prototype); + }); + const generator = ArkTSConfigGenerator.getInstance(); + + expect((generator as any).getOhmurl(filePath, moduleInfo)).toBe(expectedUrl); +} diff --git a/ets2panda/driver/build_system/test/ut/loggerTest/logger.test.ts b/ets2panda/driver/build_system/test/ut/loggerTest/logger.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..90c5bfd82d3b72d0502eebccb6939e3e1fd65244 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/loggerTest/logger.test.ts @@ -0,0 +1,200 @@ +/* + * 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 { Logger, LogDataFactory, LogData } from '../../../src/logger'; +import { SubsystemCode, ErrorCode } from '../../../src/error_code'; +import { BuildConfig, BUILD_TYPE, BUILD_MODE } from '../../../src/types'; + +function createMockBuildConfig(): BuildConfig { + return { + getHvigorConsoleLogger: jest.fn(() => ({ + printInfo: jest.fn(), + printWarn: jest.fn(), + printDebug: jest.fn(), + printError: jest.fn(), + printErrorAndExit: jest.fn(), + })), + packageName: 'mockpkg', + moduleType: 'shared', + moduleRootPath: '/mock/module', + sourceRoots: [], + byteCodeHar: false, + plugins: {}, + compileFiles: [], + dependentModuleList: [], + buildType: BUILD_TYPE.BUILD, + buildMode: BUILD_MODE.DEBUG, + hasMainModule: true, + arkts: {} as any, + arktsGlobal: {} as any, + declgenV1OutPath: undefined, + declgenV2OutPath: undefined, + declgenBridgeCodePath: undefined, + buildSdkPath: '', + loaderOutPath: '', + cachePath: '', + externalApiPaths: [], + enableDeclgenEts2Ts: false, + } as unknown as BuildConfig; +} + +describe('Logger class', () => { + let logger: Logger; + + beforeEach(() => { + Logger.destroyInstance(); + logger = Logger.getInstance(createMockBuildConfig()); + }); + + afterEach(() => { + Logger.destroyInstance(); + jest.restoreAllMocks(); + }); + + test('getInstance throws if not initialized', () => { + Logger.destroyInstance(); + expect(() => Logger.getInstance()).toThrow('projectConfig is required for the first instantiation.'); + }); + + test('getInstance returns singleton', () => { + const logger1 = Logger.getInstance(createMockBuildConfig()); + const logger2 = Logger.getInstance(); + expect(logger1).toBe(logger2); + }); + + test('destroyInstance resets singleton', () => { + const logger1 = Logger.getInstance(createMockBuildConfig()); + Logger.destroyInstance(); + const logger2 = Logger.getInstance(createMockBuildConfig()); + expect(logger1).not.toBe(logger2); + }); + + test('printInfo calls underlying logger', () => { + const spy = jest.fn(); + (logger as any).loggerMap[SubsystemCode.BUILDSYSTEM].printInfo = spy; + logger.printInfo('info'); + expect(spy).toHaveBeenCalledWith('info'); + }); + + test('printWarn calls underlying logger', () => { + const spy = jest.fn(); + (logger as any).loggerMap[SubsystemCode.BUILDSYSTEM].printWarn = spy; + logger.printWarn('warn'); + expect(spy).toHaveBeenCalledWith('warn'); + }); + + test('printDebug calls underlying logger', () => { + const spy = jest.fn(); + (logger as any).loggerMap[SubsystemCode.BUILDSYSTEM].printDebug = spy; + logger.printDebug('debug'); + expect(spy).toHaveBeenCalledWith('debug'); + }); + + test('printError sets hasErrorOccurred and calls printError', () => { + const spy = jest.fn(); + // insert '001' into the map, for test + (logger as any).loggerMap['001'] = { printError: spy }; + const logData = LogDataFactory.newInstance('00100001' as ErrorCode, 'desc'); + logger.printError(logData); + expect((logger as any).hasErrorOccurred).toBe(true); + expect(spy).toHaveBeenCalledWith(logData); + }); + + test('printErrorAndExit sets hasErrorOccurred and calls printErrorAndExit', () => { + const spy = jest.fn(); + (logger as any).loggerMap['001'] = { printErrorAndExit: spy }; + const logData = LogDataFactory.newInstance('00100001' as ErrorCode, 'desc'); + logger.printErrorAndExit(logData); + expect((logger as any).hasErrorOccurred).toBe(true); + expect(spy).toHaveBeenCalledWith(logData); + }); + + test('hasErrors and resetErrorFlag', () => { + expect(logger.hasErrors()).toBe(false); + (logger as any).hasErrorOccurred = true; + expect(logger.hasErrors()).toBe(true); + logger.resetErrorFlag(); + expect(logger.hasErrors()).toBe(false); + }); + + test('isValidErrorCode returns true for 8 digits', () => { + expect((logger as any).isValidErrorCode('12345678')).toBe(true); + expect((logger as any).isValidErrorCode('1234567')).toBe(false); + expect((logger as any).isValidErrorCode('abcdefgh')).toBe(false); + }); + + test('getLoggerFromSubsystemCode throws for invalid code', () => { + expect(() => (logger as any).getLoggerFromSubsystemCode('INVALID')).toThrow('Invalid subsystemCode.'); + }); + + test('getLoggerFromSubsystemCode returns logger', () => { + const fakeLogger = { + printInfo: jest.fn(), + printWarn: jest.fn(), + printDebug: jest.fn(), + printError: jest.fn(), + printErrorAndExit: jest.fn() + }; + (logger as any).loggerMap['FKLGR'] = fakeLogger; + expect((logger as any).getLoggerFromSubsystemCode('FKLGR')).toBe(fakeLogger); + }); + + test('getLoggerFromErrorCode throws for invalid errorCode', () => { + expect(() => (logger as any).getLoggerFromErrorCode('badcode')).toThrow('Invalid errorCode.'); + }); + + test('getLoggerFromErrorCode returns logger for valid code', () => { + const fakeLogger = { + printInfo: jest.fn(), + printWarn: jest.fn(), + printDebug: jest.fn(), + printError: jest.fn(), + printErrorAndExit: jest.fn(), + }; + (logger as any).loggerMap['001'] = fakeLogger; + expect((logger as any).getLoggerFromErrorCode('00100001')).toBe(fakeLogger); + }); +}); + +describe('LogDataFactory and LogData', () => { + test('LogDataFactory.newInstance creates LogData', () => { + const logData = LogDataFactory.newInstance('00100001' as ErrorCode, 'desc', 'cause', 'pos', ['sol1', 'sol2'], { foo: 'bar' }); + expect(logData).toBeInstanceOf(LogData); + expect(logData.code).toBe('00100001'); + expect(logData.description).toBe('desc'); + expect(logData.cause).toBe('cause'); + expect(logData.position).toBe('pos'); + expect(logData.solutions).toEqual(['sol1', 'sol2']); + expect(logData.moreInfo).toEqual({ foo: 'bar' }); + }); + + test('LogData.toString formats output', () => { + const logData = LogDataFactory.newInstance('00100001' as ErrorCode, 'desc', 'cause', 'pos', ['sol1'], { foo: 'bar' }); + const str = logData.toString(); + expect(str).toContain('ERROR Code: 00100001 desc'); + expect(str).toContain('Error Message: cause pos'); + expect(str).toContain('> sol1'); + expect(str).toContain('More Info:'); + expect(str).toContain('FOO: bar'); + }); + + test('LogData.toString omits empty fields', () => { + const logData = LogDataFactory.newInstance('00100001' as ErrorCode, 'desc', '', '', [''], undefined); + const str = logData.toString(); + expect(str).toContain('ERROR Code: 00100001 desc'); + expect(str).not.toContain('Error Message:'); + expect(str).not.toContain('More Info:'); + }); +}); diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config.json new file mode 100755 index 0000000000000000000000000000000000000000..000e0a1d00021ad62d75d32cafcd60e82b854546 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build1", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config1.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config1.json new file mode 100755 index 0000000000000000000000000000000000000000..0f4b843bced861e6408ad2746ec582558f465425 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config1.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "frameworkMode": true, + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "/root/testSuite/ets_frontend/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config2.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config2.json new file mode 100755 index 0000000000000000000000000000000000000000..5db55059d6735fa16935237dc0072b4d5d64467c --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config2.json @@ -0,0 +1,26 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/Calc.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + ], + "enableDeclgenEts2Ts": true, + "declgenBridgeCodePath": "test/ut/mock/demo_1.2_dep_hsp1.2/declgen/default/declgenBridgeCode", + "declgenV1OutPath": "test/ut/mock/demo_1.2_dep_hsp1.2/declgen/default/declgenV1", + "declgenV2OutPath": "test/ut/mock/demo_1.2_dep_hsp1.2/declgen/default/declgenV2" +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config3.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config3.json new file mode 100755 index 0000000000000000000000000000000000000000..18f3232dbd350d9b8d5390bf22609e1365727d07 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config3.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config4.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config4.json new file mode 100755 index 0000000000000000000000000000000000000000..9b4fa009f5f36f598e17e49bdb99a36a71d2c54e --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config4.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config5.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config5.json new file mode 100755 index 0000000000000000000000000000000000000000..9b4fa009f5f36f598e17e49bdb99a36a71d2c54e --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config5.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config6.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config6.json new file mode 100755 index 0000000000000000000000000000000000000000..b696a99c42e58567e26cfb76427dff9a7a08e7c9 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config6.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "language": "1.1", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.1" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config7.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config7.json new file mode 100755 index 0000000000000000000000000000000000000000..12a2810108783492b45a88663c9d477a7329b532 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config7.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "language": "hybrid", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "hybrid" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config8.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config8.json new file mode 100755 index 0000000000000000000000000000000000000000..d4ca4121f898d2164d07c770cc8d337a2b57c1e3 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config8.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "har", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + "hasMainModule": true, + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config9.json b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config9.json new file mode 100755 index 0000000000000000000000000000000000000000..7c21410ce6cfa1a0255d57973302b929dc41e7e1 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/build_config9.json @@ -0,0 +1,47 @@ +{ + "compileFiles": [ + "test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets", + "test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets" + ], + + "packageName": "entry", + "moduleType": "shared", + + "buildType": "build", + "buildMode": "Debug", + + "moduleRootPath": "test/ut/mock/demo_1.2_dep_hsp1.2/entry/", + "sourceRoots": ["./", "src/main1/ets"], + + "loaderOutPath": "test/ut/mock/dist", + "cachePath": "test/ut/mock/dist/cache", + + "enableDeclgenEts2Ts": false, + "declgenV1OutPath": "test/ut/mock/dist/declgen/decl_ets", + "declgenBridgeCodePath": "test/ut/mock/dist/declgen/ets", + + "buildSdkPath": "test/mock_sdk/", + "maxWorkers": 4, + "dependentModuleList": [ + { + "packageName": "harA", + "moduleName": "harA", + "moduleType": "har", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/harA", + "sourceRoots": ["./"], + "entryFile": "index.ets", + "language": "1.2", + "dependencies": [ "hspA" ] + }, + { + "packageName": "hspA", + "moduleName": "hspA", + "moduleType": "shared", + "modulePath": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA", + "sourceRoots": ["./"], + "entryFile": "test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets", + "language": "1.2" + } + ] +} \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.ets new file mode 100755 index 0000000000000000000000000000000000000000..750382839f54bc587083a8897ba6e92621ede399 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/entry/a.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. + */ +import {sub} from 'harA' + +function main() { + let a: string = "hello world" + console.log(a) + let ret = sub(2, 1) + console.log(ret) +} diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..46ec690949a54a32be627a9c5347eb0fcdcfe536 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.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' \ No newline at end of file diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/sub.ets new file mode 100755 index 0000000000000000000000000000000000000000..de553adf3a44c0218446f235b50b426a6816f44f --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/harA/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. + */ + +import { add } from 'hspA' + +export function sub(a: number, b: number) { + let sum = add(a, b) + console.log(sum) + return a - b +} diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/Calc.ets b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/Calc.ets new file mode 100755 index 0000000000000000000000000000000000000000..db03b551fc823831d910ed131f5852fe1ff3a61b --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/Calc.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 add(a: number, b: number) { + return a + b +} diff --git a/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/index.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb4ae32be3cc9f16c70ccf117e89e792a04c8989 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/mock/demo_1.2_dep_hsp1.2/hspA/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 { add } from './Calc' diff --git a/ets2panda/driver/build_system/test/ut/plugins_driverTest/plugins_driver.test.ts b/ets2panda/driver/build_system/test/ut/plugins_driverTest/plugins_driver.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..b5ade7c42b995fe09989624110366f344f821a86 --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/plugins_driverTest/plugins_driver.test.ts @@ -0,0 +1,162 @@ +/* + * 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 { PluginDriver, PluginHook} from '../../../src/plugins/plugins_driver'; + +jest.mock('../../../src/plugins/plugins_driver', () => { + const actual = jest.requireActual('../../../src/plugins/plugins_driver'); + + function MockPluginDriver(this: any, ...args: any[]) { + this.plugins = {}; + } + + MockPluginDriver.prototype = actual.PluginDriver.prototype; + + Object.getOwnPropertyNames(actual.PluginDriver).forEach((key) => { + if (!['prototype', 'length', 'name'].includes(key)) { + (MockPluginDriver as any)[key] = (actual.PluginDriver as any)[key]; + } + }); + + return { + ...actual, + PluginDriver: MockPluginDriver, + __esModule: true, + }; +}); +type PluginHandlerFunction = () => void; + +type PluginHandlerObject = { + order: 'pre' | 'post' | undefined + handler: PluginHandlerFunction +}; +type PluginHandler = PluginHandlerFunction | PluginHandlerObject; +interface Plugins { + name: string, + afterNew?: PluginHandler, + parsed?: PluginHandler, + scopeInited?: PluginHandler, + checked?: PluginHandler, + lowered?: PluginHandler, + asmGenerated?: PluginHandler, + binGenerated?: PluginHandler, + clean?: PluginHandler, +} + +jest.mock('path/to/valid/plugin', () => { + return { + validPlugin: () => { }, + }; +}, { virtual: true }); + +jest.mock('path/to/invalid/plugin', () => { + return { + invalidPlugin: {}, + }; +}, { virtual: true }); + +describe('test plugins_driver.ts file api', () => { + test('test initPlugins001', () => { + test_initPlugins001(); + }); + + test('test initPlugins002', () => { + test_initPlugins002(); + }); + + test('test getSortedPlugins', () => { + test_getSortedPlugins(); + }); +}); + +function test_initPlugins001() { + const driver = new PluginDriver(); + const result = driver.initPlugins(undefined as any); + expect(result).toBeUndefined(); +} + +function test_initPlugins002() { + const driver = new PluginDriver(); + const mockProjectConfig = { + plugins: { + invalidPlugin: 'path/to/invalid/plugin', + }, + compileFiles: [], + dependentModuleList: [], + buildType: 'build', + buildMode: 'debug', + packageName: 'test', + moduleRootPath: '/test/path', + sourceRoots: ['./'], + loaderOutPath: './dist', + cachePath: './dist/cache', + moduleType: 'har', + hasMainModule: false, + byteCodeHar: false, + arkts: {}, + arktsGlobal: {}, + declgenV1OutPath: './dist/declgen', + declgenV2OutPath: './dist/declgen/v2', + buildSdkPath: './sdk', + externalApiPaths: [], + enableDeclgenEts2Ts: false + }; + + let error; + try { + driver.initPlugins(mockProjectConfig as any); + } catch (e) { + error = e; + } + + expect(error).not.toBeUndefined(); +} + +function test_getSortedPlugins() { + const driver = new PluginDriver(); + const hook = PluginHook.PARSED; + + driver['allPlugins'] = new Map([ + [ + 'plugin1', + { + name: 'plugin1', + parsed: { order: 'pre', handler: jest.fn() }, + }, + ], + [ + 'plugin2', + { + name: 'plugin2', + parsed: jest.fn(), + }, + ], + [ + 'plugin3', + { + name: 'plugin3', + parsed: { order: 'post', handler: jest.fn() }, + }, + ], + ]); + + const result = driver['getSortedPlugins'](hook); + + expect(result).toEqual([ + { name: 'plugin1', handler: expect.any(Function) }, + { name: 'plugin2', handler: expect.any(Function) }, + { name: 'plugin3', handler: expect.any(Function) }, + ]); +} diff --git a/ets2panda/driver/build_system/test/ut/utilsTest/utils.test.ts b/ets2panda/driver/build_system/test/ut/utilsTest/utils.test.ts new file mode 100755 index 0000000000000000000000000000000000000000..aac65316a8f7ab8fbf5c8d6c3d38d6553137910f --- /dev/null +++ b/ets2panda/driver/build_system/test/ut/utilsTest/utils.test.ts @@ -0,0 +1,225 @@ +/* + * 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 { ensurePathExists, getFileHash } from '../../../src/utils'; +import * as fs from 'fs'; +import * as path from 'path'; +import { + ErrorCode, +} from '../../../src/error_code'; +import { + isWindows, isLinux, isMac, + changeFileExtension, changeDeclgenFileExtension, + toUnixPath, readFirstLineSync, safeRealpath +} from '../../../src/utils'; +import { DECL_ETS_SUFFIX } from '../../../src/pre_define'; + +describe('test getFileHash', () => { + const testFile = path.join(__dirname, 'testFile.txt'); + + beforeEach(() => { + fs.writeFileSync(testFile, 'Hello, World!', 'utf8'); + }); + + afterEach(() => { + if (fs.existsSync(testFile)) { + fs.unlinkSync(testFile); + } + }); + + it('test getFileHash001', () => { + test_getFileHash001(testFile); + }); + + it('test getFileHash002', () => { + test_getFileHash002(); + }); +}); + +describe('test ensurePathExists', () => { + const testDir = path.join(__dirname, 'testDir'); + + beforeEach(() => { + if (fs.existsSync(testDir)) { + fs.rmdirSync(testDir, { recursive: true }); + } + }); + + afterEach(() => { + if (fs.existsSync(testDir)) { + fs.rmdirSync(testDir, { recursive: true }); + } + }); + + it('test ensurePathExists001', () => { + test_ensurePathExists001(testDir); + }); + + it('test ensurePathExists002', () => { + test_ensurePathExists002(testDir); + }); +}); + +describe('utils', () => { + describe('isWindows/isLinux/isMac', () => { + it('should detect Linux', () => { + expect(isLinux()).toBe(true); + expect(isWindows()).toBe(false); + expect(isMac()).toBe(false); + }); + }); + + describe('changeFileExtension', () => { + it('should change extension when originExt is empty', () => { + expect(changeFileExtension('a/b/c.txt', '.js')).toBe('a/b/c.js'); + }); + it('should change extension when originExt is provided', () => { + expect(changeFileExtension('a/b/c.txt', '.js', '.txt')).toBe('a/b/c.js'); + }); + }); + + describe('changeDeclgenFileExtension', () => { + it('should use DECL_ETS_SUFFIX branch', () => { + const file = `foo${DECL_ETS_SUFFIX}`; + expect(changeDeclgenFileExtension(file, '.ts')).toBe('foo.ts'); + }); + it('should use default branch', () => { + expect(changeDeclgenFileExtension('foo.ets', '.ts')).toBe('foo.ts'); + }); + }); + + describe('toUnixPath', () => { + it('should replace backslashes with slashes', () => { + expect(toUnixPath('a\\b\\c')).toBe('a/b/c'); + }); + }); +}); + +describe('readFirstLineSync', () => { + const testFile = path.join(__dirname, 'testReadFirstLine.txt'); + + afterEach(() => { + if (fs.existsSync(testFile)) { + fs.unlinkSync(testFile); + } + }); + + it('should read first line of a file with single line', () => { + const content = 'Hello, World!'; + fs.writeFileSync(testFile, content, 'utf8'); + + const result = readFirstLineSync(testFile); + expect(result).toBe('Hello, World!'); + }); + + it('should read only first line of a multi-line file', () => { + const content = 'First line\nSecond line\nThird line'; + fs.writeFileSync(testFile, content, 'utf8'); + + const result = readFirstLineSync(testFile); + expect(result).toBe('First line'); + }); + + it('should trim the first line', () => { + const content = ' Whitespace around \nSecond line'; + fs.writeFileSync(testFile, content, 'utf8'); + + const result = readFirstLineSync(testFile); + expect(result).toBe('Whitespace around'); + }); + + it('should handle CRLF line endings', () => { + const content = 'Windows line\r\nSecond line'; + fs.writeFileSync(testFile, content, 'utf8'); + + const result = readFirstLineSync(testFile); + expect(result).toBe('Windows line'); + }); + + it('should return empty string for empty file', () => { + fs.writeFileSync(testFile, '', 'utf8'); + + const result = readFirstLineSync(testFile); + expect(result).toBe(''); + }); + + it('should throw error for non-existent file', () => { + const nonExistentFile = path.join(__dirname, 'nonExistentFile.txt'); + + expect(() => { + readFirstLineSync(nonExistentFile); + }).toThrow(); + }); +}); + +describe('safeRealpath', () => { + it('test safeRealpath001', () => { + const testDir = path.join(__dirname); + const mockLogger = { printInfo: jest.fn(), printError: jest.fn() }; + + const result = safeRealpath(testDir, mockLogger as any); + expect(result).toBe(fs.realpathSync(testDir)); + expect(mockLogger.printError).not.toHaveBeenCalled(); + }); + + it('test safeRealpath002', () => { + const nonExistentPath = path.join(__dirname, 'non-existent-directory'); + const mockLogger = { printInfo: jest.fn(), printError: jest.fn() }; + + expect(() => { + safeRealpath(nonExistentPath, mockLogger as any); + }).toThrow(); + + expect(mockLogger.printError).toHaveBeenCalledWith( + expect.objectContaining({ + code: ErrorCode.BUILDSYSTEM_PATH_RESOLVE_FAIL, + description: expect.stringContaining(`Error resolving path "${nonExistentPath}"`) + }) + ); + }); +}); + +function test_getFileHash001(testFile: string) { + const hash = getFileHash(testFile); + expect(hash).toBe('dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f'); +} + +function test_getFileHash002() { + let error: Error | undefined; + try { + getFileHash('/nonexistent/file.txt'); + } catch (e) { + error = e as Error; + } + expect(error).not.toBe(undefined); +} + +function test_ensurePathExists001(testDir: string) { + expect(fs.existsSync(testDir)).toBe(false); + ensurePathExists(path.join(testDir, 'file.txt')); + expect(fs.existsSync(testDir)).toBe(true); +} + +function test_ensurePathExists002(testDir: string) { + fs.mkdirSync(testDir, { recursive: true }); + let error; + try { + ensurePathExists(path.join(testDir, 'file.txt')); + } catch (e) { + error = e; + } + expect(error).toBe(undefined); +} diff --git a/ets2panda/driver/build_system/testSuite.md b/ets2panda/driver/build_system/testSuite.md new file mode 100755 index 0000000000000000000000000000000000000000..61d136295fb8448005c3438066e2434b218fceec --- /dev/null +++ b/ets2panda/driver/build_system/testSuite.md @@ -0,0 +1,537 @@ +# ArkTS1.2 build system test suite + +The test suite bases on [Jest](https://jestjs.io/) and aims to test the `build_system`. + +--- + +## Import Jest && Test Suite + +### 1. Edit the build_system/package.json file + +**Add test scripts** +Add the following to the `scripts` section in `package.json`(already in the code repository): + +```json +"scripts": { + "build_system_Utest": "jest --testMatch='**/test/ut/**/utils.test.ts' --testPathIgnorePatterns='test/e2e/'", + "build_system_Etest": "TEST=${test_script_name} jest test/e2e/compile.test.ts", +} +``` + +Build_system_Utest is for unit tests while build_system_Etest is for E2E tests. +The `TEST` environment variable is used to specify the test script to run for E2E tests. + +**Add dependencies** +Add the following to the `devDependencies` section in `package.json`(already in the code repository): + +```json +"devDependencies": { + "@babel/core": "^7.27.1", + "@babel/preset-env": "^7.27.2", + "@babel/preset-typescript": "^7.27.1", + "@types/jest": "^29.5.14", + "babel-jest": "^29.7.0", + "jest": "^29.7.0", + "ts-node": "^10.9.2" +} +``` + +**Babel configuration** + +Babel allows running tests without compiling test files with tsc first. +Add the following to `package.json`(already in the code repository): + +```json +"babel": { + "presets": [ + ["@babel/preset-env", { "targets": { "node": "current" } }], + "@babel/preset-typescript" + ] +} +``` + +### 2. Jest configuration + +Add the following to `build_system/jest.config.js`(already in the code repository): + +```js +module.exports = { + testEnvironment: "node", + verbose: true, + collectCoverage: true, + coverageDirectory: "/dist/coverage", + setupFilesAfterEnv: [ + "/testHook/jest.memory-usage.js", + "/testHook/jest.time-usage.js", + "/testHook/jest.abc-size.js" + ], + testMatch: [ + "/test/ut/**/*.test.[jt]s" + ], + testPathIgnorePatterns: [] +}; +``` + +--- + +## Running the Test Suite + +Before running the test suite, ensure that the build_system itself can be compiled locally. +End-to-end tests depend on the SDK. It is recommended to copy the SDK directly into `build_system/test/mock_sdk` and replace the original three folders. +After replacing the SDK, grant execute permissions to all files under `build_system/test/mock_sdk/build-tools/ets2panda/bin` and export the `LD_LIBRARY_PATH` environment variable. +Replace the SDK → grant execute permissions to bin/* → update paths → install dependencies via npm → run npm scripts → compile src successfully. + +1. Enter the `build_system` directory + + ```bash + cd ${absolute_path_to_build_system} + ``` + +2. Perform mock_sdk operations to ensure that the build_system itself and hap packages can be compiled locally: + + Copy the SDK for Linux (`ets/ets1.2/*`) to `build_system/test/mock_sdk`. + After copying, the mock_sdk directory should contain the folders `api`, `arkts`, `build-tools`, and `kits`. + + Grant execute permissions to the executables under `mock_sdk/build-tools/ets2panda/bin`: + ```bash + chmod +x test/mock_sdk/build-tools/ets2panda/bin/* + ``` + + Replace all `${absolute_path_to_build_system}` in e2e test code with the actual directory: + ```bash + find test -name 'build_config*.json' -exec sed -i 's|${absolute_path_to_build_system}|'"$(pwd)"'|g' {} + + find test -name 'decl-fileInfo.json' -exec sed -i 's|${absolute_path_to_build_system}|'"$(pwd)"'|g' {} + + ``` + + Export the `LD_LIBRARY_PATH` environment variable. To avoid exporting it every time, you can add it to your environment file. Be sure to replace with the actual directory: + ```bash + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${absolute_path_to_build_system}/test/mock_sdk/build-tools/ets2panda/lib + ``` + + Install dependencies and compile all files under `src`: + + ```bash + npm install + npm run build + ``` + +3. **[optional]** Customize the test suite by modifying Jest parameters in `jest.config.js`, such as including or excluding test files: + + ```js + module.exports = { + testEnvironment: "node", + verbose: true, + collectCoverage: true, + coverageDirectory: "/coverageReport", + setupFilesAfterEnv: [ + "/testHook/jest.memory-usage.js" + // "/testHook/jest.time-usage.js" + ], + testMatch: [ + "test/ut/sum.test.ts" + ], + testPathIgnorePatterns: [ + "/test/ut/skip/", + "/test/ut/sometest.test.ts" + ] + } + ``` + +--- + +## Unit Test Example + +Add an `osType.test.ts` file under `build_system/test/ut`: + +```typescript +import { isWindows, isLinux, isMac } from '../../src/utils'; + +describe('osType', () => { + it('should detect OS type correctly', () => { + expect(isWindows()).toBe(false); + expect(isLinux()).toBe(true); + expect(isMac()).toBe(false); + }); +}); +``` + +Run from the command line: + +```bash +npm run build_system_Utest +``` + +#### Recommended Practice + +For each test file, create a folder with the same name under `ut`. For example, for `osType.test.ts`, create a `ut/osType` folder. using camelCase naming convention. + +#### Existing UT +There are corresponding test files for each file under `src`, placed in folders with the same name as in `src`. +The `mock` folder contains mock files needed for some tests. +By default, all test files in this directory will be run. You can filter them by adjusting the Jest configuration. + +``` +ut +├── base_modeTest +│ └── base_mode.test.ts +├── entryTest +│ └── entry.test.ts +├── fileManagerTest +│ └── filemanager.test.ts +├── generate_arktsconfigTest +│ └── generate_arktsconfig.test.ts +├── loggerTest +│ └── logger.test.ts +├── mock +│ └── demo_1.2_dep_hsp1.2 +│ ├── build_config.json +│ ├── build_config1.json +│ ├── build_config2.json +│ ├── build_config3.json +│ ├── build_config4.json +│ ├── build_config5.json +│ ├── build_config6.json +│ ├── build_config7.json +│ ├── build_config8.json +│ ├── build_config9.json +│ ├── declgen +│ │ └── default +│ │ ├── declgenBridgeCode +│ │ │ └── entry +│ │ │ ├── Calc.ts +│ │ │ └── index.ts +│ │ └── declgenV1 +│ │ └── entry +│ │ ├── Calc.d.ets +│ │ └── index.d.ets +│ ├── entry +│ │ └── a.ets +│ ├── harA +│ │ ├── index.ets +│ │ └── sub.ets +│ └── hspA +│ ├── Calc.ets +│ └── index.ets +├── plugins_driverTest +│ └── plugins_driver.test.ts +├── safeRealpath.test.ts +└── utilsTest + └── utils.test.ts +``` + +--- + +## E2E Test Example + +The purpose of end-to-end tests is usually to check whether a project can be compiled, whether the `abc file` is generated correctly, and whether there are errors or exceptions during compilation. +End-to-end tests are run similarly to unit tests, but with different interface files. + +Add a `compile.test.ts` file under `build_system/test/e2e` (The latest version is already in the code repository): + +```typescript +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; + +function getAllModules(config: any) { + return [ + { packageName: config.packageName, modulePath: config.moduleRootPath, sourceRoots: config.sourceRoots || ['./'] }, + ...(config.dependentModuleList || []) + ]; +} + +function getAllSrcFiles(modules: any[]) { + let allSrcFiles: string[] = []; + for (const mod of modules) { + const moduleAbsPath = path.resolve(__dirname, '../../', mod.modulePath || mod.moduleRootPath || ''); + for (const root of mod.sourceRoots || ['./']) { + const srcRoot = path.resolve(moduleAbsPath, root); + if (fs.existsSync(srcRoot) && fs.statSync(srcRoot).isDirectory()) { + const files = fs.readdirSync(srcRoot) + .filter(f => f.endsWith('.ets')) + .map(f => path.join(srcRoot, f)); + allSrcFiles = allSrcFiles.concat(files); + } + } + } + return allSrcFiles; +} + +function getModuleNameForSrc(src: string, allModuleNames: string[], defaultName: string): string | undefined { + for (const mod of allModuleNames) { + if (src.includes(`/${mod}/`)) return mod; + } + return defaultName; +} + +function testHelper(testDir: string) { + const configPath = path.resolve(__dirname, '../..', testDir, 'build_config.json'); + if (!fs.existsSync(configPath)) { + throw new Error(`Missing ${configPath}`); + } + + const config = JSON.parse(fs.readFileSync(configPath, 'utf-8')); + const cachePath = path.resolve(__dirname, '../../', config.cachePath); + + const allModuleNames = [ + config.packageName, + ...(config.dependentModuleList?.map((dep: any) => dep.packageName) || []) + ]; + + const expectedOutputs = config.compileFiles.map((src: string) => { + const moduleName = getModuleNameForSrc(src, allModuleNames, config.packageName); + const baseName = path.basename(src, path.extname(src)); + return path.join(cachePath, moduleName, `${baseName}.abc`); + }); + + describe('Check Compilation Outputs', () => { + beforeAll(() => { + execSync(`node ./dist/entry.js ${configPath}`, { stdio: 'inherit' }); + }); + + it('Check outputs for compiled files', () => { + expectedOutputs.forEach(filePath => { + if (!fs.existsSync(filePath)) { + throw new Error(`Not found: ${filePath}`); + } + if (fs.statSync(filePath).size === 0) { + throw new Error(`${filePath} is empty`); + } + }); + }); + + it('Check outputs for non-compiled source files', () => { + const modules = getAllModules(config); + const allSrcFiles = getAllSrcFiles(modules); + const compiledSet = new Set( + config.compileFiles.map((cf: string) => path.resolve(__dirname, '../../', cf)) + ); + const notCompiled = allSrcFiles.filter(f => !compiledSet.has(f)); + notCompiled.forEach(srcFile => { + const moduleName = getModuleNameForSrc(srcFile, allModuleNames, config.packageName); + const baseName = path.basename(srcFile, path.extname(srcFile)); + const outputFile = path.join(cachePath, moduleName, `${baseName}.abc`); + if (fs.existsSync(outputFile)) { + throw new Error(`Non-compiled source file ${srcFile} generated output ${outputFile}`); + } + }); + }); + }); + + afterAll(() => { + execSync(`rimraf ${cachePath}`, { stdio: 'inherit' }); + }); +} + +const testDir = process.env.TEST; +if (!testDir) { + throw new Error('Test folder not found'); +} else if (testDir === 'all') { + const baseDir = path.resolve(__dirname, '../../test'); + const dirs = fs.readdirSync(baseDir) + .map(name => path.join('test', name)) + .filter(dir => fs.statSync(path.resolve(__dirname, '../..', dir)).isDirectory()) + .filter(dir => fs.existsSync(path.resolve(__dirname, '../..', dir, 'build_config.json'))); + if (dirs.length === 0) { + throw new Error('No tests found'); + } + for (const dir of dirs) { + testHelper(dir); + } +} else { + testHelper(testDir); +} +``` +Since the project under test may be very complex, with multiple `build_config.json` files and unknown compilation order, users are required to write scripts to specify the compilation process. +Usage: + + Modify the `build_system_Etest` script's TEST parameter to the test project script: + + ```json + "scripts": { + "entry1_2_external_har1_2:gen_abc": "npm run build && node ./dist/entry.js ${absolute_path_to_build_system}/test/e2e/entry1_2_external_har1_2/build_config.json", + "build_system_Etest": "TEST=entry1_2_external_har1_2:gen_abc jest --testMatch '${absolute_path_to_build_system}/test/e2e/*.test.ts'" + } + ``` + + Specify the full script name after TEST=. + + Run from the command line: + + ```bash + npm run build_system_Etest + ``` + + This will execute the test. + +To add tests, create a new test file/folder under `build_system/test/e2e`. The `build_system_Etest` script will automatically include the test. + +--- + +## How to Write Tests + +The test suite is based on Jest, using Jest's assertions and matcher mechanisms. + +### Global Configuration + +- Group tests: `describe(name, fn)`, multiple tests are included in fn as a group. +- Single test: `it(name, fn)`, fn contains the test implementation. All `it` can be replaced with the alias `test`. +- Failing test: `it.failing(name, fn, timeout)`, opposite of `it`: if fn succeeds, the test fails; if fn fails, the test passes. +- Todo: `it.todo(name)`, indicates the test is not yet written. +- Run before/after all tests: `afterAll(fn, timeout)`, `beforeAll(fn, timeout)`, fn is the implementation, optional timeout. +- Run before/after each test: `afterEach(fn, timeout)`, `beforeEach(fn, timeout)`, fn is the implementation, optional timeout. + +### Assertions + +`expect(expr)` creates an assertion object, e.g.`expect(isLinux())` + +### Matchers + +Matchers are methods provided by assertion objects and can be chained (method chaining). Jest provides many matchers; here are some common ones: + +- `toBe(value)`: Checks if values are equal +- `toHaveBeenCalled()`: Checks if a function was called, often used with mock functions +- `toHaveReturned()`: Checks if a function returned normally, often used with mock functions +- `toHaveLength(number)`: Checks array length +- `toBeInstanceOf(Class)`: Checks if an object is an instance of a class (like `instanceof`) +- `toContain(item)`: Checks for containment +- etc. See [official documentation](https://jestjs.io/docs/expect) for more matchers. + +### Mock Functions + +Example: Add an `osType.test.ts` file under `build_system/test/ut/osType`: + +```typescript +import * as utils from '../../src/utils'; + +describe('osTypeCheck', () => { + it('should detect OS type correctly', () => { + expect(utils.isWindows()).toBe(false); + expect(utils.isLinux()).toBe(true); + expect(utils.isMac()).toBe(false); + }); + it('mocked isWindows always return true', () => { + const spy = jest.spyOn(utils, 'isWindows').mockImplementation(() => true); + expect(utils.isWindows()).toBe(true); + expect(utils.isLinux()).toBe(true); + expect(utils.isMac()).toBe(false); + spy.mockRestore(); + }); +}); +``` + +Note: ES6 imports are read-only and cannot be modified, so you must use `import * as utils` to import the module. +Whether to mock the whole module or just a function depends on the specific situation. +Mock functions provide many interfaces for assertions and checks. See [official documentation](https://jestjs.io/docs/mock-function-api). + + +### Asynchronous Code + +Functions that return a Promise can be tested directly. If they return `Promise.resolve()`, the test passes; if they return `Promise.reject()`, the test fails. + +### Results + +Test results are printed to the command line by default. + +Example (may change in the future): + +``` +console.log + [Jest][osTypeCheck should detect OS type correctly] Peak memory change: 0.28 MB + + at Object.log (testHook/jest.memory-usage.js:12:11) + + console.log + [Jest][osTypeCheck should detect OS type correctly] Test time: 10 ms + + at Object.log (testHook/jest.time-usage.js:11:11) + + console.log + [Jest][osTypeCheck mocked isWindows always return true] Peak memory change: 0.28 MB + + at Object.log (testHook/jest.memory-usage.js:12:11) + + console.log + [Jest][osTypeCheck mocked isWindows always return true] Test time: 1 ms + + at Object.log (testHook/jest.time-usage.js:11:11) + + PASS test/ut/osType/osType.test.ts + osTypeCheck + ✓ should detect OS type correctly (11 ms) + ✓ mocked isWindows always return true (2 ms) + PASS test/ut/mockConsoleLog.test.ts + mockConsoleLog + ✓ should detect OS type correctly + +----------|---------|----------|---------|---------|------------------- +| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | +| ---------- | --------- | ---------- | --------- | --------- | ------------------- | +| All files | 35.29 | 0 | 50 | 35.29 | +| utils.ts | 35.29 | 0 | 50 | 35.29 | 38-58 | +| ---------- | --------- | ---------- | --------- | --------- | ------------------- | +Test Suites: 2 passed, 2 total +Tests: 3 passed, 3 total +Snapshots: 0 total +Time: 0.668 s, estimated 1 s +Ran all test suites. +``` + +The table is a summary of coverage, showing statement, branch, function, and line coverage for each file. +Test Suites is the number of test files executed. +Tests is the number of test/it blocks in the test files. +Since there may be command line output during compilation, it is recommended to redirect the output stream, for example, by outputting compilation information to a temporary file. + +--- + +## New Folder Structure + +``` +build_system +├── dist # Compiled output directory +│   └── coverage # Coverage output directory +├── src # Source code directory +├── test # Test directory +│   ├── ut # Unit tests +│   │   ├── mockOsType # Mock function tests +│   │   │ └── mockOsType.test.ts # Mock OS type test +│   │   ├── mockConsoleLog.test.ts # Mock console.log test +│   │   └── ... # More unit tests +│   └── e2e # End-to-end tests +│     ├── compile.test.ts # Compilation test +│   ├── abcGenerationTest # Example hap project +│     └── ... # More end-to-end tests +├── testHook # Test hook files +│   ├── jest.memory-usage.js # Memory usage monitoring +│   ├── jest.time-usage.js # Test time monitoring +│   └── jest.abc-size.js # abc file size monitoring +├── package.json # Project configuration file +└── jest.config.js # Jest configuration file +``` + +--- + +## Coverage Report + +A summary of coverage information is printed to the command line. +A detailed coverage report is output to the `dist/coverage` directory by default. You can change the output path by modifying the `coverageDirectory` field in `jest.config.js`. +Jest uses `Istanbul` to generate coverage reports. +The coverage report folder includes the following: + +``` +dist/coverage +├── clover.xml # Clover format coverage report +├── coverage-final.json # JSON format coverage report +├── lcov-report # Detailed HTML coverage report directory +│ ├── base.css +│ ├── block-navigation.js +│ ├── favicon.png +│ ├── index.html # Coverage report, open in browser for details +│ ├── prettify.css +│ ├── prettify.js +│ ├── sort-arrow-sprite.png +│ └── sorter.js +└── lcov.info # Standard LCOV format coverage data file +``` + +---