diff --git a/ets2panda/driver/build_system/src/build/base_mode.ts b/ets2panda/driver/build_system/src/build/base_mode.ts index 50983025a8cba0bc0ccd4bc4f0cedba0c055cb02..5fe24b60f5a8c361b02e41a0527dac61855bca7e 100644 --- a/ets2panda/driver/build_system/src/build/base_mode.ts +++ b/ets2panda/driver/build_system/src/build/base_mode.ts @@ -333,6 +333,9 @@ export abstract class BaseMode { } this.collectDependencyModules(packageName, module, dynamicDepModules, staticDepModules); }); + if (moduleInfo.language === LANGUAGE_VERSION.ARKTS_HYBRID) { + dynamicDepModules.set(moduleInfo.packageName, moduleInfo); + } return [dynamicDepModules, staticDepModules]; } @@ -370,8 +373,9 @@ export abstract class BaseMode { } protected generateArkTSConfigForModules(): void { - this.moduleInfos.forEach((moduleInfo: ModuleInfo, _: string) => { - ArkTSConfigGenerator.getInstance(this.buildConfig, this.moduleInfos).writeArkTSConfigFile(moduleInfo, this.enableDeclgenEts2Ts); + this.moduleInfos.forEach((moduleInfo: ModuleInfo, moduleRootPath: string) => { + ArkTSConfigGenerator.getInstance(this.buildConfig, this.moduleInfos) + .writeArkTSConfigFile(moduleInfo, this.enableDeclgenEts2Ts, this.buildConfig); }); } @@ -401,7 +405,10 @@ export abstract class BaseMode { ); this.logger.printError(logData); } - const moduleInfo: ModuleInfo = { + if (this.moduleInfos.has(module.packageName)) { + return; + } + let moduleInfo: ModuleInfo = { isMainModule: false, packageName: module.packageName, moduleRootPath: module.modulePath, @@ -427,21 +434,24 @@ export abstract class BaseMode { } protected getMainModuleInfo(): ModuleInfo { + const mainModuleInfo = this.dependentModuleList.find((module: DependentModuleConfig) => module.packageName === this.packageName); return { - isMainModule: this.hasMainModule, - packageName: this.packageName, - moduleRootPath: this.moduleRootPath, - moduleType: this.moduleType, - sourceRoots: this.sourceRoots, - entryFile: '', - arktsConfigFile: path.resolve(this.cacheDir, this.packageName, ARKTSCONFIG_JSON_FILE), - dynamicDepModuleInfos: new Map(), - staticDepModuleInfos: new Map(), - compileFileInfos: [], - declgenV1OutPath: this.declgenV1OutPath, - declgenV2OutPath: this.declgenV2OutPath, - declgenBridgeCodePath: this.declgenBridgeCodePath, - byteCodeHar: this.byteCodeHar + isMainModule: this.hasMainModule, + packageName: this.packageName, + moduleRootPath: this.moduleRootPath, + moduleType: this.moduleType, + sourceRoots: this.sourceRoots, + entryFile: '', + arktsConfigFile: path.resolve(this.cacheDir, this.packageName, ARKTSCONFIG_JSON_FILE), + dynamicDepModuleInfos: new Map(), + staticDepModuleInfos: new Map(), + compileFileInfos: [], + declgenV1OutPath: this.declgenV1OutPath, + declgenV2OutPath: this.declgenV2OutPath, + declgenBridgeCodePath: this.declgenBridgeCodePath, + byteCodeHar: this.byteCodeHar, + language: mainModuleInfo?.language ?? LANGUAGE_VERSION.ARKTS_1_2, + declFilesPath: mainModuleInfo?.declFilesPath, }; } @@ -616,17 +626,10 @@ export abstract class BaseMode { return; } this.entryFiles.forEach((file: string) => { - // Skip the declaration files when compiling abc - if (file.endsWith(DECL_ETS_SUFFIX)) { - return; - } for (const [_, moduleInfo] of this.moduleInfos) { if (!file.startsWith(moduleInfo.moduleRootPath)) { continue; } - if (moduleInfo.moduleType === OHOS_MODULE_TYPE.HAR && moduleInfo.byteCodeHar) { - return; - } const filePathFromModuleRoot: string = path.relative(moduleInfo.moduleRootPath, file); const filePathInCache: string = path.join(this.cacheDir, moduleInfo.packageName, filePathFromModuleRoot); const abcFilePath: string = path.resolve(changeFileExtension(filePathInCache, ABC_SUFFIX)); @@ -781,7 +784,7 @@ export abstract class BaseMode { } } - public async runParallell(): Promise { + public async runParallel(): Promise { this.generateModuleInfos(); if (!cluster.isPrimary) { diff --git a/ets2panda/driver/build_system/src/build/build_mode.ts b/ets2panda/driver/build_system/src/build/build_mode.ts index b1643a8d9cda2511dd6cad9188b4885c4d9c3f5a..a8bfd4277833ea1ca256eb25ca854249b2567fa1 100644 --- a/ets2panda/driver/build_system/src/build/build_mode.ts +++ b/ets2panda/driver/build_system/src/build/build_mode.ts @@ -26,6 +26,6 @@ export class BuildMode extends BaseMode { } public async run(): Promise { - await super.run(); + await super.runParallel(); } } \ No newline at end of file diff --git a/ets2panda/driver/build_system/src/build/generate_arktsconfig.ts b/ets2panda/driver/build_system/src/build/generate_arktsconfig.ts index 0e799bda50af5ad77a178655f66dc020bf7a3dec..bc8c1f2064b6d96a8bf49d0e38403af7c71c77b3 100644 --- a/ets2panda/driver/build_system/src/build/generate_arktsconfig.ts +++ b/ets2panda/driver/build_system/src/build/generate_arktsconfig.ts @@ -29,7 +29,9 @@ import { ensurePathExists, getInteropFilePathByApi, getOhmurlByApi, - safeRealpath + isSubPathOf, + safeRealpath, + toUnixPath } from '../utils'; import { AliasConfig, @@ -235,7 +237,11 @@ export class ArkTSConfigGenerator { }); } - public writeArkTSConfigFile(moduleInfo: ModuleInfo, enableDeclgenEts2Ts: boolean): void { + public writeArkTSConfigFile( + moduleInfo: ModuleInfo, + enableDeclgenEts2Ts: boolean, + buildConfig: BuildConfig + ): void { if (!moduleInfo.sourceRoots || moduleInfo.sourceRoots.length === 0) { const logData: LogData = LogDataFactory.newInstance( ErrorCode.BUILDSYSTEM_SOURCEROOTS_NOT_SET_FAIL, @@ -246,6 +252,8 @@ export class ArkTSConfigGenerator { let pathSection = this.getPathSection(moduleInfo); let dependenciesSection: string[] = []; this.getDependenciesSection(moduleInfo, dependenciesSection); + this.getAllFilesToPathSectionForHybrid(moduleInfo, buildConfig); + let dynamicPathSection: Record = {}; if (!enableDeclgenEts2Ts) { @@ -320,4 +328,30 @@ export class ArkTSConfigGenerator { ohmUrl: getOhmurlByApi(aliasConfig.originalAPIName) } } + + public getAllFilesToPathSectionForHybrid( + moduleInfo: ModuleInfo, + buildConfig: BuildConfig + ): void { + if (moduleInfo?.language !== LANGUAGE_VERSION.ARKTS_HYBRID) { + return; + } + + const projectRoot = toUnixPath(buildConfig.projectRootPath) + '/'; + const moduleRoot = toUnixPath(moduleInfo.moduleRootPath); + + for (const file of buildConfig.compileFiles) { + const unixFilePath = toUnixPath(file); + + if (!isSubPathOf(unixFilePath, moduleRoot)) { + continue; + } + + let relativePath = unixFilePath.startsWith(projectRoot) + ? unixFilePath.substring(projectRoot.length) + : unixFilePath; + const keyWithoutExtension = relativePath.replace(/\.[^/.]+$/, ''); + this.pathSection[keyWithoutExtension] = [file]; + } + } } \ No newline at end of file diff --git a/ets2panda/driver/build_system/src/types.ts b/ets2panda/driver/build_system/src/types.ts index 84dd9b5082ec9f4d6b405f193c986032e91cd334..8fe806e61f7bb69dcec190550db46de2e0aad18f 100644 --- a/ets2panda/driver/build_system/src/types.ts +++ b/ets2panda/driver/build_system/src/types.ts @@ -113,6 +113,7 @@ export interface PathConfig { aliasPaths: Map; interopSDKPaths: Set; dynamicInteroSDKBasePath:string; + projectRootPath: string; } /** diff --git a/ets2panda/driver/build_system/src/utils.ts b/ets2panda/driver/build_system/src/utils.ts index 67fa0bcedd1b80b6d8265afde3002c0fd2fd4c9d..429d5c34987cfdc685b2f68710b768ba5fc41b05 100644 --- a/ets2panda/driver/build_system/src/utils.ts +++ b/ets2panda/driver/build_system/src/utils.ts @@ -141,4 +141,10 @@ export function getOhmurlByApi(api: string): string { }); } return ''; +} + +export function isSubPathOf(targetPath: string, parentDir: string): boolean { + const resolvedParent = toUnixPath(path.resolve(parentDir)); + const resolvedTarget = toUnixPath(path.resolve(targetPath)); + return resolvedTarget === resolvedParent || resolvedTarget.startsWith(resolvedParent + '/'); } \ No newline at end of file