• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: any) {
28    super(rollupObject);
29    this.patch = false;
30    this.inOldSymbolTablePath = '';
31    this.enableMap = false;
32  }
33
34  generateAbc(rollupObject: any) {
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);
39    this.buildModuleSourceMapInfo();
40
41    this.generateEs2AbcCmdForHotfix();
42    this.generateMergedAbcOfEs2Abc();
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
55    if (this.projectConfig.patch) {
56      const oldHapSymbolTable: string = path.join(this.projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE);
57      this.cmdArgs.push('--input-symbol-table');
58      this.cmdArgs.push(`"${oldHapSymbolTable}"`);
59      this.cmdArgs.push('--generate-patch');
60    }
61
62    if (this.projectConfig.enableMap) {
63      // when generating map, cache is forbiden to avoid uncomplete symbol table
64      const oldHapSymbolTable: string = path.join(this.projectConfig.inOldSymbolTablePath, PATCH_SYMBOL_TABLE);
65      this.cmdArgs.push('--dump-symbol-table');
66      this.cmdArgs.push(`"${oldHapSymbolTable}"`);
67    }
68
69    this.cmdArgs.push('--merge-abc');
70  }
71}
72