From cbc5b350f752ba671b488665ba1a99f8fd8f8a35 Mon Sep 17 00:00:00 2001 From: wuhailong Date: Tue, 10 Jun 2025 16:27:21 +0800 Subject: [PATCH] Modify cache file for glue code Issue: #ICE1NU Signed-off-by: wuhailong Change-Id: Ie149d8b971991571af013ed01a82a0b7ae88093f --- .../ark_compiler/module/module_mode.ts | 10 ++-- .../ark_compiler/module/module_source_file.ts | 2 +- compiler/src/process_arkts_evolution.ts | 17 +++++- .../mock/rollup_mock/common.ts | 3 +- .../mock/rollup_mock/module_info.ts | 2 +- .../module/module_mode.test.ts | 56 ++++++++++++++++++- 6 files changed, 79 insertions(+), 11 deletions(-) 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 562661f77..9073aefb7 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -120,11 +120,12 @@ import { } from '../logger'; import { addDeclFilesConfig, + arkTSModuleMap, ArkTSEvolutionModule, getDeclgenBridgeCodePath, - pkgDeclFilesConfig, - arkTSModuleMap, - isArkTSEvolutionFile + genCachePathForBridgeCode, + isArkTSEvolutionFile, + pkgDeclFilesConfig } from '../../../process_arkts_evolution'; export class ModuleInfo { @@ -521,7 +522,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/fast_build/ark_compiler/module/module_source_file.ts b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts index 8d9771f04..6d7407b47 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_source_file.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts @@ -432,7 +432,7 @@ export class ModuleSourceFile { ModuleSourceFile.logger, parentEvent, this.metaInfo); } } else { - await writeBridgeCodeFileSyncByNode( this.source, this.moduleId); + await writeBridgeCodeFileSyncByNode( this.source, this.moduleId, this.metaInfo); } } diff --git a/compiler/src/process_arkts_evolution.ts b/compiler/src/process_arkts_evolution.ts index 272db9e37..5e8ca1673 100644 --- a/compiler/src/process_arkts_evolution.ts +++ b/compiler/src/process_arkts_evolution.ts @@ -201,14 +201,25 @@ export function cleanUpProcessArkTSEvolutionObj(): void { fullNameToTmpVar = new Map(); } -export async function writeBridgeCodeFileSyncByNode(node: ts.SourceFile, moduleId: string): Promise { +export async function writeBridgeCodeFileSyncByNode(node: ts.SourceFile, moduleId: string, + metaInfo: Object): Promise { const printer: ts.Printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); const writer: ts.EmitTextWriter = ts.createTextWriter( // @ts-ignore ts.getNewLineCharacter({ newLine: ts.NewLineKind.LineFeed, removeComments: false })); printer.writeFile(node, writer, undefined); - mkdirsSync(path.dirname(moduleId)); - fs.writeFileSync(moduleId, writer.getText()); + const cacheFilePath: string = genCachePathForBridgeCode(moduleId, metaInfo); + mkdirsSync(path.dirname(cacheFilePath)); + fs.writeFileSync(cacheFilePath, writer.getText()); +} + +export function genCachePathForBridgeCode(moduleId: string, metaInfo: Object, cachePath?: string): string { + const bridgeCodePath: string = getDeclgenBridgeCodePath(metaInfo.pkgName); + const filePath: string = toUnixPath(moduleId); + const relativeFilePath: string = filePath.replace( + toUnixPath(path.join(bridgeCodePath, metaInfo.pkgName)), metaInfo.moduleName); + const cacheFilePath: string = path.join(cachePath ? cachePath : process.env.cachePath, relativeFilePath); + return cacheFilePath; } export function getDeclgenBridgeCodePath(pkgName: string): string { 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 123f315d9..fd2db982c 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 abce70bef..008cf81f2 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 42364286d..3239995d8 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 { @@ -101,6 +102,7 @@ import { LogData, LogDataFactory } from '../../../lib/fast_build/ark_compiler/logger'; +import { arkTSEvolutionModuleMap } from '../../../lib/process_arkts_evolution'; function checkGenerateEs2AbcCmdExpect(cmdArgs: Array, compatibleSdkVersion: string, byteCodeHar: boolean): void { const fileThreads: number = cpus(); @@ -789,6 +791,58 @@ 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); + moduleMode.addModuleInfoItemMock(this.rollup); + 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(); const moduleMode = new ModuleModeMock(this.rollup); -- Gitee