From 08ed379b20fe371832a609adb0e89d6d2caee1a5 Mon Sep 17 00:00:00 2001 From: chenqy930 Date: Fri, 10 Mar 2023 15:38:55 +0800 Subject: [PATCH] Optimize es2abc incremental build Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I6LQWC Signed-off-by: chenqy930 Change-Id: If8c1da751b2c585505f43ece0272be4a0320b202 --- .../ark_compiler/module/module_mode.ts | 25 +++++++++++++------ compiler/src/gen_merged_abc.ts | 25 +++++++++++++++++-- 2 files changed, 41 insertions(+), 9 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 ff8773564..c1cc30a31 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -97,12 +97,6 @@ export class ModuleInfo { } export class PackageEntryInfo { - // There are two types of modules : node_modules and oh_modules. Only one type exists in a project. - // And there are two types of directories modules placed in: project root directory and entry directory. - // take json5, a node_moduels placed in project root directory, as an example: - // pkgEntryPath will be 'pkg_modules/0/json5', pkgBuildPath will be 'pkg_modules/0/json5/index' - // 'pkg_modules' represents both oh_modules and node_moduels - // '0' represents this module is placed in project root dir, modules placed in entry dir will be '1' pkgEntryPath: string; pkgBuildPath: string; constructor(pkgEntryPath: string, pkgBuildPath: string) { @@ -312,7 +306,7 @@ export class ModuleMode extends CommonMode { addCacheFileArgs() { this.cmdArgs.push('--cache-file'); - this.cmdArgs.push(`"${this.cacheFilePath}"`); + this.cmdArgs.push(`"@${this.cacheFilePath}"`); } private generateCompileFilesInfo() { @@ -332,9 +326,26 @@ export class ModuleMode extends CommonMode { fs.writeFileSync(this.npmEntriesInfoPath, entriesInfo, 'utf-8'); } + private generateAbcCacheFilesInfo(): void { + let abcCacheFilesInfo: string = ''; + + // generate source file cache + this.moduleInfos.forEach((info) => { + let abcCacheFilePath: string = changeFileExtension(info.cacheFilePath, EXTNAME_PROTO_BIN); + abcCacheFilesInfo += `${info.cacheFilePath};${abcCacheFilePath}\n`; + }); + + // generate npm entries cache + let npmEntriesCacheFilePath: string = changeFileExtension(this.npmEntriesInfoPath, EXTNAME_PROTO_BIN); + abcCacheFilesInfo += `${this.npmEntriesInfoPath};${npmEntriesCacheFilePath}\n`; + + fs.writeFileSync(this.cacheFilePath, abcCacheFilesInfo, 'utf-8'); + } + private genDescriptionsForMergedEs2abc() { this.generateCompileFilesInfo(); this.generateNpmEntriesInfo(); + this.generateAbcCacheFilesInfo(); } generateMergedAbcOfEs2Abc() { diff --git a/compiler/src/gen_merged_abc.ts b/compiler/src/gen_merged_abc.ts index b57b57776..a407332c4 100644 --- a/compiler/src/gen_merged_abc.ts +++ b/compiler/src/gen_merged_abc.ts @@ -27,7 +27,8 @@ import { NPMENTRIES_TXT, NODE_MODULES, PACKAGES, - PATCH_SYMBOL_TABLE + PATCH_SYMBOL_TABLE, + EXTNAME_PROTO_BIN } from './pre_define'; import { EntryInfo, @@ -81,6 +82,24 @@ export function generateNpmEntriesInfo(entryInfos: Map) { fs.writeFileSync(npmEntriesInfoPath, entriesInfo, 'utf-8'); } +function generateAbcCacheFilesInfo(moduleInfos: Array, npmEntriesInfoPath: string, cacheFilePath: string): void { + let abcCacheFilesInfo: string = ''; + + // generate source file cache + moduleInfos.forEach((info) => { + let tempFilePathWithoutExt: string = info.tempFilePath.substring(0, info.tempFilePath.lastIndexOf('.')); + let abcCacheFilePath: string = tempFilePathWithoutExt + EXTNAME_PROTO_BIN; + abcCacheFilesInfo += `${info.tempFilePath};${abcCacheFilePath}\n`; + }); + + // generate npm entries cache + let npmEntriesCacheFileWithoutExt: string = npmEntriesInfoPath.substring(0, npmEntriesInfoPath.lastIndexOf('.')); + let npmEntriesCacheFilePath: string = npmEntriesCacheFileWithoutExt + EXTNAME_PROTO_BIN; + abcCacheFilesInfo += `${npmEntriesInfoPath};${npmEntriesCacheFilePath}\n`; + + fs.writeFileSync(cacheFilePath, abcCacheFilesInfo, 'utf-8'); +} + export function generateMergedAbc(moduleInfos: Array, entryInfos: Map, outputABCPath: string) { generateCompileFilesInfo(moduleInfos); generateNpmEntriesInfo(entryInfos); @@ -89,6 +108,8 @@ export function generateMergedAbc(moduleInfos: Array, entryInfos: Ma const npmEntriesInfoPath: string = path.join(process.env.cachePath, NPMENTRIES_TXT); const cacheFilePath: string = path.join(process.env.cachePath, MODULES_CACHE); validateFilePathLength(cacheFilePath, logger); + generateAbcCacheFilesInfo(moduleInfos, npmEntriesInfoPath, cacheFilePath); + const fileThreads = os.cpus().length < 16 ? os.cpus().length : 16; mkdirsSync(projectConfig.buildPath); let genAbcCmd: string = @@ -104,7 +125,7 @@ export function generateMergedAbc(moduleInfos: Array, entryInfos: Ma } if (!projectConfig.enableMap) { - genAbcCmd += ` --cache-file "${cacheFilePath}"`; + genAbcCmd += ` --cache-file "@${cacheFilePath}"`; } else { // when generating map, cache is forbiden to avoid uncomplete symbol table let oldHapSymbolTable = path.join(projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE); -- Gitee