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 { 18 isEs2Abc, 19 isTs2Abc 20} from '../../../ark_utils'; 21import { SourceMapGenerator } from '../generate_sourcemap'; 22import { 23 TS2ABC, 24 ES2ABC 25} from '../common/ark_define'; 26import { 27 ArkTSInternalErrorDescription, 28 ErrorCode 29} from '../error_code'; 30import { 31 LogData, 32 LogDataFactory 33} from '../logger'; 34 35export class ModuleBuildMode extends ModuleMode { 36 constructor(rollupObject: Object) { 37 super(rollupObject); 38 } 39 40 generateAbc(rollupObject: Object, parentEvent: Object): void { 41 this.prepareForCompilation(rollupObject, parentEvent); 42 SourceMapGenerator.getInstance().buildModuleSourceMapInfo(parentEvent); 43 this.executeArkCompiler(parentEvent); 44 } 45 46 executeArkCompiler(parentEvent: Object): void { 47 if (isEs2Abc(this.projectConfig)) { 48 this.generateEs2AbcCmd(); 49 this.addCacheFileArgs(); 50 this.genDescriptionsForMergedEs2abc(!!this.projectConfig.byteCodeHarInfo); 51 this.generateMergedAbcOfEs2Abc(parentEvent); 52 } else if (isTs2Abc(this.projectConfig)) { 53 this.filterModulesByHashJson(); 54 const splittedModules: any[] = this.getSplittedModulesByNumber(); 55 this.invokeTs2AbcWorkersToGenProto(splittedModules); 56 this.processTs2abcWorkersToGenAbc(); 57 } else { 58 const errInfo: LogData = LogDataFactory.newInstance( 59 ErrorCode.ETS2BUNDLE_INTERNAL_INVALID_COMPILE_MODE, 60 ArkTSInternalErrorDescription, 61 'Invalid compilation mode. ' + 62 `ProjectConfig.pandaMode should be either ${TS2ABC} or ${ES2ABC}.` 63 ); 64 this.logger.printErrorAndExit(errInfo); 65 } 66 } 67} 68