• 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 { ModuleMode } from './module_mode';
17import { isEs2Abc, isTs2Abc } from '../../../ark_utils';
18import { SourceMapGenerator } from '../generate_sourcemap';
19
20export class ModuleBuildMode extends ModuleMode {
21  constructor(rollupObject: Object) {
22    super(rollupObject);
23  }
24
25  generateAbc(rollupObject: Object, parentEvent: Object): void {
26    this.prepareForCompilation(rollupObject, parentEvent);
27    SourceMapGenerator.getInstance().buildModuleSourceMapInfo(parentEvent);
28    this.executeArkCompiler(parentEvent);
29  }
30
31  executeArkCompiler(parentEvent: Object): void {
32    if (isEs2Abc(this.projectConfig)) {
33      this.generateEs2AbcCmd();
34      this.addCacheFileArgs();
35      this.genDescriptionsForMergedEs2abc(!!this.projectConfig.byteCodeHarInfo);
36      this.generateMergedAbcOfEs2Abc(parentEvent);
37    } else if (isTs2Abc(this.projectConfig)) {
38      this.filterModulesByHashJson();
39      const splittedModules: any[] = this.getSplittedModulesByNumber();
40      this.invokeTs2AbcWorkersToGenProto(splittedModules);
41      this.processTs2abcWorkersToGenAbc();
42    } else {
43      this.throwArkTsCompilerError('ArkTS:INTERNAL ERROR: Invalid compilation mode.');
44    }
45  }
46}
47