1/* 2 * Copyright (c) 2025 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 { BaseMode } from './base_mode'; 17import { BuildConfig, CompileFileInfo, ModuleInfo } from '../types'; 18import { LogData, LogDataFactory } from '../logger'; 19import { changeFileExtension } from '../utils'; 20import { ABC_SUFFIX } from '../pre_define'; 21import path from 'path'; 22import { ErrorCode } from '../error_code'; 23 24export class BuildFrameworkMode extends BaseMode { 25 frameworkMode: boolean; 26 useEmptyPackage: boolean; 27 28 constructor(buildConfig: BuildConfig) { 29 super(buildConfig); 30 this.mergedAbcFile = buildConfig.loaderOutPath as string; 31 this.frameworkMode = buildConfig.frameworkMode ?? false; 32 this.useEmptyPackage = buildConfig.useEmptyPackage ?? false; 33 } 34 35 public async run(): Promise<void> { 36 super.run(); 37 } 38 39 protected generateModuleInfos(): void { 40 this.collectModuleInfos(); 41 this.generateArkTSConfigForModules(); 42 this.collectCompileFiles(); 43 } 44 45 protected collectCompileFiles(): void { 46 this.entryFiles.forEach((file: string) => { 47 for (const [packageName, moduleInfo] of this.moduleInfos) { 48 if (!file.startsWith(moduleInfo.moduleRootPath)) { 49 continue; 50 } 51 let filePathFromModuleRoot: string = path.relative(moduleInfo.moduleRootPath, file); 52 let filePathInCache: string = path.join(this.cacheDir, moduleInfo.packageName, filePathFromModuleRoot); 53 let abcFilePath: string = path.resolve(changeFileExtension(filePathInCache, ABC_SUFFIX)); 54 this.abcFiles.add(abcFilePath); 55 let fileInfo: CompileFileInfo = { 56 filePath: file, 57 dependentFiles: [], 58 abcFilePath: abcFilePath, 59 arktsConfigFile: moduleInfo.arktsConfigFile, 60 packageName: moduleInfo.packageName 61 }; 62 moduleInfo.compileFileInfos.push(fileInfo); 63 this.compileFiles.set(file, fileInfo); 64 return; 65 } 66 const logData: LogData = LogDataFactory.newInstance( 67 ErrorCode.BUILDSYSTEM_FILE_NOT_BELONG_TO_ANY_MODULE_FAIL, 68 'File does not belong to any module in moduleInfos.', 69 '', 70 file 71 ); 72 this.logger.printError(logData); 73 }); 74 } 75 76 protected getMainModuleInfo(): ModuleInfo { 77 let moduleInfo = super.getMainModuleInfo(); 78 moduleInfo.frameworkMode = this.frameworkMode; 79 moduleInfo.useEmptyPackage = this.useEmptyPackage; 80 return moduleInfo; 81 } 82} 83