1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import path from 'path'; 17 18import { ModuleMode } from './module_mode'; 19import { PATCH_SYMBOL_TABLE } from '../common/ark_define'; 20import { getEs2abcFileThreadNumber } from '../utils'; 21 22export class ModuleHotfixMode extends ModuleMode { 23 patch: boolean; 24 inOldSymbolTablePath: string; 25 enableMap: boolean; 26 27 constructor(rollupObject: Object) { 28 super(rollupObject); 29 this.patch = false; 30 this.inOldSymbolTablePath = ''; 31 this.enableMap = false; 32 } 33 34 generateAbc(rollupObject: Object, parentEvent: Object): void { 35 this.patch = this.projectConfig.patch || false; 36 this.inOldSymbolTablePath = this.projectConfig.inOldSymbolTablePath || this.projectConfig.projectRootPath; 37 this.enableMap = this.projectConfig.enableMap || false; 38 this.prepareForCompilation(rollupObject, parentEvent); 39 this.buildModuleSourceMapInfo(parentEvent); 40 41 this.generateEs2AbcCmdForHotfix(); 42 this.generateMergedAbcOfEs2Abc(parentEvent); 43 } 44 45 private generateEs2AbcCmdForHotfix() { 46 const fileThreads = getEs2abcFileThreadNumber(); 47 this.cmdArgs.push(`"@${this.filesInfoPath}"`); 48 this.cmdArgs.push('--npm-module-entry-list'); 49 this.cmdArgs.push(`"${this.npmEntriesInfoPath}"`); 50 this.cmdArgs.push('--output'); 51 this.cmdArgs.push(`"${this.moduleAbcPath}"`); 52 this.cmdArgs.push('--file-threads'); 53 this.cmdArgs.push(`"${fileThreads}"`); 54 this.cmdArgs.push(`"--target-api-version=${this.projectConfig.compatibleSdkVersion}"`); 55 56 if (this.projectConfig.patch) { 57 const oldHapSymbolTable: string = path.join(this.projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE); 58 this.cmdArgs.push('--input-symbol-table'); 59 this.cmdArgs.push(`"${oldHapSymbolTable}"`); 60 this.cmdArgs.push('--generate-patch'); 61 } 62 63 if (this.projectConfig.enableMap) { 64 // when generating map, cache is forbiden to avoid uncomplete symbol table 65 const oldHapSymbolTable: string = path.join(this.projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE); 66 this.cmdArgs.push('--dump-symbol-table'); 67 this.cmdArgs.push(`"${oldHapSymbolTable}"`); 68 } 69 70 this.cmdArgs.push('--merge-abc'); 71 } 72} 73