diff --git a/compiler/src/gen_merged_abc.ts b/compiler/src/gen_merged_abc.ts index c847d2e00fd7215a99281ac088140ffc461861c9..cd67da5d71d8cb5fe7a921dc52d46eec82282ae9 100644 --- a/compiler/src/gen_merged_abc.ts +++ b/compiler/src/gen_merged_abc.ts @@ -25,7 +25,8 @@ import { FILESINFO_TXT, MODULES_CACHE, NPMENTRIES_TXT, - NODE_MODULES + NODE_MODULES, + PATCH_SYMBOL_TABLE } from './pre_define'; import { EntryInfo, @@ -41,6 +42,9 @@ import { const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; +projectConfig.patch = false +projectConfig.enableMap = false + function generateCompileFilesInfo(moduleInfos: Array) { const tempModuleInfos: ModuleInfo[] = Array(); moduleInfos.forEach((item) => { @@ -88,8 +92,23 @@ export function generateMergedAbc(moduleInfos: Array, entryInfos: Ma validateFilePathLength(cacheFilePath); const fileThreads = os.cpus().length < 16 ? os.cpus().length : 16; mkdirsSync(projectConfig.buildPath); - const genAbcCmd: string = - `${initAbcEnv().join(' ')} "@${filesInfoPath}" --npm-module-entry-list "${npmEntriesInfoPath}" --cache-file "${cacheFilePath}" --output "${outputABCPath}" --file-threads "${fileThreads}"`; + let genAbcCmd: string = + `${initAbcEnv().join(' ')} "@${filesInfoPath}" --npm-module-entry-list "${npmEntriesInfoPath}" --output "${outputABCPath}" --file-threads "${fileThreads}"`; + + projectConfig.inOldSymbolTablePath = projectConfig.projectRootPath; // temp symbol table path for hot patch + if (projectConfig.patch) { + let oldHapSymbolTable = path.join(projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE); + genAbcCmd += ` --input-symbol-table "${oldHapSymbolTable}" --generate-patch`; + } + + if (!projectConfig.enableMap) { + 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); + genAbcCmd += ` --dump-symbol-table "${oldHapSymbolTable}"`; + } + logger.debug('gen abc cmd is: ', genAbcCmd); try { if (process.env.watchMode === 'true') { @@ -109,7 +128,13 @@ export function generateMergedAbc(moduleInfos: Array, entryInfos: Ma }); child.stderr.on('data', (data: any) => { - logger.debug(red, data.toString(), reset); + if (projectConfig.patch) { + let patchErr :string[] = + data.split(os.EOL).filter(line => line.includes("[Patch]") || line.includes("Error:")); + logger.error(red, patchErr.join(os.EOL), reset); + } else { + logger.debug(red, data.toString(), reset); + } }); } } catch (e) { diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index e356f095e9ce69a117d9c10099e89a291eddebe2..804579ef84ed3f64bc5947a52f69e6666601c74e 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -273,6 +273,7 @@ export const EXTNAME_CJS: string = '.cjs'; export const EXTNAME_D_TS: string = '.d.ts'; export const EXTNAME_ABC: string = '.abc'; export const EXTNAME_PROTO_BIN: string = '.protoBin'; +export const PATCH_SYMBOL_TABLE: string = "symbol.txt"; export const SUCCESS: number = 0; export const FAIL: number = 1;