diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index 4a3c9ed104c2e760ce4a1cb5412142f82cdfabee..a86646caa7b0f8add8c6bbe10913360fe2fc14e9 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -530,7 +530,8 @@ export class ModuleMode extends CommonMode { let moduleName: string = metaInfo.moduleName; let recordName: string = ''; - let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? originalFilePath : + let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? + genCachePathForBridgeCode(originalFilePath, metaInfo, this.projectConfig.cachePath) : this.genFileCachePath(filePath, this.projectConfig.projectRootPath, this.projectConfig.cachePath, metaInfo); let packageName: string = ''; diff --git a/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts index 4a3c9ed104c2e760ce4a1cb5412142f82cdfabee..a86646caa7b0f8add8c6bbe10913360fe2fc14e9 100644 --- a/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/interop/src/fast_build/ark_compiler/module/module_mode.ts @@ -530,7 +530,8 @@ export class ModuleMode extends CommonMode { let moduleName: string = metaInfo.moduleName; let recordName: string = ''; - let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? originalFilePath : + let cacheFilePath: string = isArkTSEvolutionFile(filePath, metaInfo) ? + genCachePathForBridgeCode(originalFilePath, metaInfo, this.projectConfig.cachePath) : this.genFileCachePath(filePath, this.projectConfig.projectRootPath, this.projectConfig.cachePath, metaInfo); let packageName: string = ''; diff --git a/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts b/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..3d49ac670b30bd21d533abf9272687ad060bdf55 --- /dev/null +++ b/compiler/test/ark_compiler_ut/interop/process_arkts_evolution.test.ts @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use rollupObject 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 { expect } from 'chai'; +import mocha from 'mocha'; +import sinon from 'sinon'; + +import { + collectArkTSEvolutionModuleInfo, + addDeclFilesConfig, + pkgDeclFilesConfig, + arkTSModuleMap +} from '../../../lib/fast_build/ark_compiler/interop/process_arkts_evolution'; +import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; +import { + BUNDLE_NAME_DEFAULT, + HAR_DECLGENV2OUTPATH +} from '../mock/rollup_mock/common'; +import { CommonLogger } from '../../../lib/fast_build/ark_compiler/logger'; +import { ErrorCode } from '../../../lib/fast_build/ark_compiler/error_code'; + +mocha.describe('process arkts evolution tests', function () { + mocha.before(function () { + this.rollup = new RollUpPluginMock(); + }); + + mocha.after(() => { + delete this.rollup; + }); + + mocha.it('1-1: test error message of collectArkTSEvolutionModuleInfo (useNormalizedOHMUrl is false)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = false; + this.rollup.share.projectConfig.dependentModuleMap.set('evohar', { language: '1.2' }); + const throwArkTsCompilerErrorStub = sinon.stub(CommonLogger.getInstance(this.rollup.share), 'printErrorAndExit'); + try { + collectArkTSEvolutionModuleInfo(this.rollup.share); + } catch (e) { + } + expect(throwArkTsCompilerErrorStub.getCall(0).args[0].code === ErrorCode.ETS2BUNDLE_EXTERNAL_COLLECT_INTEROP_INFO_FAILED).to.be.true; + throwArkTsCompilerErrorStub.restore(); + }); + + mocha.it('1-2: test error message of collectArkTSEvolutionModuleInfo (1.2 module information is incorrect)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.dependentModuleMap.set('evohar', { language: '1.2' }); + const throwArkTsCompilerErrorStub = sinon.stub(this.rollup.share, 'throwArkTsCompilerError'); + try { + collectArkTSEvolutionModuleInfo(this.rollup.share); + } catch(e) { + } + const errMsg: string = 'ArkTS:INTERNAL ERROR: Failed to collect arkTs evolution module info.\n' + + `Error Message: Failed to collect arkTs evolution module "evohar" info from rollup.`; + expect(throwArkTsCompilerErrorStub.getCall(0).args[1] === errMsg).to.be.true; + throwArkTsCompilerErrorStub.restore(); + }); + + mocha.it('1-3: test error message of collectArkTSEvolutionModuleInfo (1.1 module information is incorrect)', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.dependentModuleMap.set('har', { language: '1.1' }); + const throwArkTsCompilerErrorStub = sinon.stub(this.rollup.share, 'throwArkTsCompilerError'); + try { + collectArkTSEvolutionModuleInfo(this.rollup.share); + } catch(e) { + } + const errMsg: string = 'ArkTS:INTERNAL ERROR: Failed to collect arkTs evolution module info.\n' + + `Error Message: Failed to collect arkTs evolution module "har" info from rollup.`; + expect(throwArkTsCompilerErrorStub.getCall(0).args[1] === errMsg).to.be.true; + throwArkTsCompilerErrorStub.restore(); + }); + + mocha.it('2-1: test generate declFilesInfo in mixed compilation', function () { + pkgDeclFilesConfig['har'] = { + packageName: 'har', + files: {} + }; + const filePath = '/har/Index.ets' + const projectConfig = { + mainModuleName: 'entry', + bundleName: BUNDLE_NAME_DEFAULT, + pkgContextInfo: { + 'har': { + packageName: 'har', + version: '1.0.0', + isSO: false + } + } + } + arkTSModuleMap.set('har', { + language: '1.1', + pkgName: 'har', + declgenV2OutPath: HAR_DECLGENV2OUTPATH + }) + addDeclFilesConfig(filePath, projectConfig, undefined, '/har', 'har'); + const expectDeclPath: string = `${HAR_DECLGENV2OUTPATH}/Index.d.ets`; + const expectOhmUrl: string = `@normalized:N&entry&${BUNDLE_NAME_DEFAULT}&har/Index&1.0.0`; + expect(pkgDeclFilesConfig['har'].files.length !== 0).to.be.true; + expect(pkgDeclFilesConfig['har'].files['Index'].length !== 0).to.be.true; + expect(pkgDeclFilesConfig['har'].files['Index'].declPath === expectDeclPath).to.be.true; + expect(pkgDeclFilesConfig['har'].files['Index'].ohmUrl === expectOhmUrl).to.be.true; + arkTSModuleMap.clear(); + }); +}); \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts index 123f315d9c320526cd48e88df059975bf4a9887d..fd2db982cc6825d5490d8cb28241fed2c2ca8fdd 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/common.ts @@ -83,4 +83,5 @@ export const NEWFILE: string = 'newFile'; export const DECLFILESPATH: string = '/entry/build/default/intermediates/loader_out/default/etsFortgz/decl-fileInfo.json'; export const DECLGENV2OUTPATH: string = '/entry/build/default/intermediates/declgen/default/declgenV2'; -export const HAR_DECLGENV2OUTPATH: string = '/har/build/default/intermediates/declgen/default/declgenV2'; \ No newline at end of file +export const HAR_DECLGENV2OUTPATH: string = '/har/build/default/intermediates/declgen/default/declgenV2'; +export const HAR_BRIDGECODEPATH: string = '/har/build/default/intermediates/declgen/default/declgenBridgeCode'; \ No newline at end of file diff --git a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts index abce70bef037514febf86c4db8c480144c1d1e96..008cf81f21954207b341b62895b6cdd03810235f 100644 --- a/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts +++ b/compiler/test/ark_compiler_ut/mock/rollup_mock/module_info.ts @@ -36,7 +36,7 @@ class Meta { this.belongModulePath = `${PROJECT_ROOT}/${DEFAULT_PROJECT}/${DEFAULT_ENTRY}`; this.hostModulesInfo = []; this.moduleName = entryModuleName; - this.pkgName = ''; + this.pkgName = 'entry'; this.isLocalDependency = true; this.isNodeEntryFile = false; this.pkgPath = modulePath; diff --git a/compiler/test/ark_compiler_ut/module/module_mode.test.ts b/compiler/test/ark_compiler_ut/module/module_mode.test.ts index 89040a93d800c74e873924364b8dc6bc451b32be..c1252972be6149c038b791a590495da5f48dd970 100644 --- a/compiler/test/ark_compiler_ut/module/module_mode.test.ts +++ b/compiler/test/ark_compiler_ut/module/module_mode.test.ts @@ -58,7 +58,8 @@ import { ENTRY_MODULE_NAME_DEFAULT, TEST, NEWFILE, - ENTRY_MODULE_VERSION_DEFAULT + ENTRY_MODULE_VERSION_DEFAULT, + HAR_BRIDGECODEPATH } from '../mock/rollup_mock/common'; import projectConfig from '../utils/processProjectConfig'; import { @@ -789,6 +790,60 @@ mocha.describe('test module_mode file api', function () { }); SourceMapGenerator.cleanSourceMapObject(); }); + + mocha.it('2-8: test addModuleInfoItem under build mixCompile', function () { + this.rollup.build(); + this.rollup.share.projectConfig.useNormalizedOHMUrl = true; + this.rollup.share.projectConfig.pkgContextInfo = { + 'har': { + 'packageName': 'har', + 'bundleName': '', + 'moduleName': '', + 'version': '1.0.0', + 'entryPath': 'Index.ets', + 'isSO': false + }, + 'entry': { + 'packageName': 'entry', + 'bundleName': '', + 'moduleName': '', + 'version': '', + 'entryPath': 'Index.ets', + 'isSO': false + } + } + const arkTSEvoFile = path.join(HAR_BRIDGECODEPATH, 'har','Index.ts'); + const arkTSEvolutionModuleInfo = { + language: '1.2', + packageName: 'har', + moduleName: 'har', + declgenBridgeCodePath: HAR_BRIDGECODEPATH, + } + arkTSEvolutionModuleMap.set('har', arkTSEvolutionModuleInfo) + this.rollup.share.allFiles.add(arkTSEvoFile); + const moduleInfoMock = { + id: arkTSEvoFile, + meta: { + 'pkgName': 'har', + 'moduleName': 'har', + 'language': '1.2' + } + }; + + this.rollup.moduleInfos.push(moduleInfoMock); + const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup); + sourceMapGenerator.setNewSoureMaps(false); + const moduleMode = new ModuleModeMock(this.rollup); + process.env.mixCompile = 'true'; + moduleMode.addModuleInfoItemMock(this.rollup); + process.env.mixCompile = 'false'; + const cacheFilePath = moduleMode.moduleInfos.get(toUnixPath(arkTSEvoFile)).cacheFilePath; + const expectCacheFilePath = path.join(moduleMode.projectConfig.cachePath, 'har/Index.ts'); + expect(cacheFilePath === expectCacheFilePath).to.be.true; + this.rollup.share.projectConfig.useNormalizedOHMUrl = false; + this.rollup.share.allFiles.delete(arkTSEvoFile); + SourceMapGenerator.cleanSourceMapObject(); + }); mocha.it('3-1-1: test updateCachedSourceMaps under build debug: cacheSourceMapPath not exist', function () { this.rollup.build();