diff --git a/compiler/src/fast_build/ark_compiler/error_code.ts b/compiler/src/fast_build/ark_compiler/error_code.ts index 29dd70e204e9b8815676898c102a0936a11f6a5c..ec00bd97b949fbcef69afa14b4305c9093df9625 100644 --- a/compiler/src/fast_build/ark_compiler/error_code.ts +++ b/compiler/src/fast_build/ark_compiler/error_code.ts @@ -63,6 +63,7 @@ export enum ErrorCode { ETS2BUNDLE_EXTERNAL_CLASS_HAS_NO_CONSTRUCTOR_WITHOUT_ARGS = '10311012', ETS2BUNDLE_EXTERNAL_UNION_TYPE_AMBIGUITY = '10311013', ETS2BUNDLE_EXTERNAL_ALIAS_CONFIG_FORMAT_INVALID = '10311014', + ETS2BUNDLE_EXTERNAL_GET_LANGUAGE_VERSION_FAILED = '10311015', // CONSTANTS FOR ES2ABC ERROR CODE ES2ABC_SYNTAX_ERROR_ERROR_CODE = '10705000', ES2ABC_PATCH_FIX_ERROR_ERROR_CODE = '10706001' diff --git a/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts b/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts index ca0a6042aa50195e82fc7c57f3a6935a9213cba0..f6c15391940c20df223bd0fd5835b807a7634096 100644 --- a/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts +++ b/compiler/src/fast_build/ark_compiler/interop/interop_manager.ts @@ -103,6 +103,7 @@ export class FileManager { const convertedMap = new Map(); for (const [key, module] of dependentModuleMap) { + module.dynamicFiles = module.dynamicFiles.map(toUnixPath); const convertedModule: ArkTSEvolutionModule = { ...module, modulePath: toUnixPath(module.modulePath), @@ -168,19 +169,17 @@ export class FileManager { staticSDKGlueCodePaths?: Set, checkFileExist: boolean = true ): void { - const isDynamicValid = !dynamicSDKPath || hasExistingPaths(dynamicSDKPath); - const isStaticBaseValid = !staticSDKBaseUrl || hasExistingPaths(staticSDKBaseUrl); - const isGlueCodeValid = !staticSDKGlueCodePaths || hasExistingPaths(staticSDKGlueCodePaths); - FileManager.isInteropSDKEnabled = isDynamicValid && isStaticBaseValid && isGlueCodeValid; - if (!FileManager.isInteropSDKEnabled && checkFileExist) { - return; - } - if (dynamicSDKPath) { for (const path of dynamicSDKPath) { FileManager.dynamicLibPath.add(toUnixPath(path)); } } + const isStaticBaseValid = !staticSDKBaseUrl || hasExistingPaths(staticSDKBaseUrl); + const isGlueCodeValid = !staticSDKGlueCodePaths || hasExistingPaths(staticSDKGlueCodePaths); + FileManager.isInteropSDKEnabled = isStaticBaseValid && isGlueCodeValid; + if (!FileManager.isInteropSDKEnabled && checkFileExist) { + return; + } if (staticSDKBaseUrl) { for (const path of staticSDKBaseUrl) { FileManager.staticSDKDeclPath.add(toUnixPath(path)); @@ -221,7 +220,13 @@ export class FileManager { if (sdkMatch) { return sdkMatch; } - + const errInfo: LogData = LogDataFactory.newInstance( + ErrorCode.ETS2BUNDLE_EXTERNAL_GET_LANGUAGE_VERSION_FAILED, + ArkTSErrorDescription, + 'Failed to get language version.', + `Failed to get language version for file: ${filePath}`, + ); + FileManager.logError(errInfo); return undefined; } @@ -229,48 +234,60 @@ export class FileManager { languageVersion: string, pkgName: string } | undefined { - for (const [_, moduleInfo] of FileManager.arkTSModuleMap) { + let matchedModuleInfo: ArkTSEvolutionModule; + + for (const [, moduleInfo] of FileManager.arkTSModuleMap) { if (!path.startsWith(moduleInfo.modulePath)) { continue; } - const isHybrid = moduleInfo.language === HYBRID; - const pkgName = moduleInfo.packageName; - - if (!isHybrid) { - return { - languageVersion: moduleInfo.language, - pkgName - }; + if (!matchedModuleInfo || + moduleInfo.modulePath.length > matchedModuleInfo.modulePath.length) { + matchedModuleInfo = moduleInfo; } + } - const isDynamic = - moduleInfo.dynamicFiles.includes(path) || - (moduleInfo.declgenV2OutPath && path.startsWith(moduleInfo.declgenV2OutPath)); + if (!matchedModuleInfo) { + return undefined; + } - if (isDynamic) { - return { - languageVersion: ARKTS_1_1, - pkgName - }; - } + const isHybrid = matchedModuleInfo.language === HYBRID; + const pkgName = matchedModuleInfo.packageName; - const isStatic = - moduleInfo.staticFiles.includes(path) || - (moduleInfo.declgenV1OutPath && path.startsWith(moduleInfo.declgenV1OutPath)) || - (moduleInfo.declgenBridgeCodePath && path.startsWith(moduleInfo.declgenBridgeCodePath)); + if (!isHybrid) { + return { + languageVersion: matchedModuleInfo.language, + pkgName + }; + } - if (isStatic) { - return { - languageVersion: ARKTS_1_2, - pkgName - }; - } + const isDynamic = + matchedModuleInfo.dynamicFiles.includes(path) || + (matchedModuleInfo.declgenV2OutPath && path.startsWith(matchedModuleInfo.declgenV2OutPath)); + + if (isDynamic) { + return { + languageVersion: ARKTS_1_1, + pkgName + }; + } + + const isStatic = + matchedModuleInfo.staticFiles.includes(path) || + (matchedModuleInfo.declgenV1OutPath && path.startsWith(matchedModuleInfo.declgenV1OutPath)) || + (matchedModuleInfo.declgenBridgeCodePath && path.startsWith(matchedModuleInfo.declgenBridgeCodePath)); + + if (isStatic) { + return { + languageVersion: ARKTS_1_2, + pkgName + }; } return undefined; } + private static logError(error: LogData): void { if (FileManager.sharedObj) { CommonLogger.getInstance(FileManager.sharedObj).printErrorAndExit(error); diff --git a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts index ee322322314caf8a5873f1f124c20aa39280a5b1..418b0b5ec0d943de1731fdf94514fa0108250d9d 100644 --- a/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts +++ b/compiler/src/fast_build/ark_compiler/interop/run_declgen_standalone.ts @@ -41,7 +41,7 @@ export function run(param: Params): boolean { DeclfileProductor.init(param); param.tasks.forEach(task => { const moduleInfo = FileManager.arkTSModuleMap.get(task.packageName); - if (moduleInfo.dynamicFileList.length <= 0) { + if (moduleInfo?.dynamicFiles.length <= 0) { return; } if (task.buildTask === BuildType.DECLGEN) { @@ -52,6 +52,7 @@ export function run(param: Params): boolean { //todo } }); + FileManager.cleanFileManagerObject(); return true; } diff --git a/compiler/src/fast_build/ark_compiler/interop/type.ts b/compiler/src/fast_build/ark_compiler/interop/type.ts index 61e90bfde6bf50ac43736e01d5d2dd101cfcca34..fdb5abe7925f0155b7a384a88ebe8530780a287e 100644 --- a/compiler/src/fast_build/ark_compiler/interop/type.ts +++ b/compiler/src/fast_build/ark_compiler/interop/type.ts @@ -89,21 +89,6 @@ interface DeclFileConfig { declPath: string; ohmUrl: string; } -export interface ArkTSEvolutionModule { - language: string; - packageName: string; - pkgPath: string; - moduleName: string; - modulePath: string; - declgenV1OutPath?: string; - declgenV2OutPath?: string; - declgenBridgeCodePath?: string; - declFilesPath?: string; - dynamicFileList: string[]; - staticFileList: string[]; - cachePath: string; - byteCodeHarInfo?: Object; -} export const ARKTS_1_2: string = '1.2'; export const ARKTS_1_1: string = '1.1'; diff --git a/compiler/src/process_arkts_evolution.ts b/compiler/src/process_arkts_evolution.ts index 5e8ca16733bf68e390ae6dbbca9b241acf0cb97d..81acad3a8672e8cab3b1e40377531ff093d58d5b 100644 --- a/compiler/src/process_arkts_evolution.ts +++ b/compiler/src/process_arkts_evolution.ts @@ -120,29 +120,49 @@ export function getArkTSEvoDeclFilePath(resolvedFileInfo: ResolvedFileInfo): str const { moduleRequest, resolvedFileName } = resolvedFileInfo; let arktsEvoDeclFilePath: string = moduleRequest; const combinedMap = new Map([...arkTSEvolutionModuleMap, ...arkTSHybridModuleMap]); - for (const [pkgName, arkTSEvolutionModuleInfo] of combinedMap) { - const declgenV1OutPath: string = toUnixPath(arkTSEvolutionModuleInfo.declgenV1OutPath); - const modulePath: string = toUnixPath(arkTSEvolutionModuleInfo.modulePath); - const declgenBridgeCodePath: string = toUnixPath(arkTSEvolutionModuleInfo.declgenBridgeCodePath); - if (resolvedFileName && resolvedFileName.startsWith(modulePath + '/') && - !resolvedFileName.startsWith(declgenBridgeCodePath + '/')) { - arktsEvoDeclFilePath = resolvedFileName - .replace(modulePath, toUnixPath(path.join(declgenV1OutPath, pkgName))) - .replace(EXTNAME_ETS, EXTNAME_D_ETS); - break; + + let bestMatch: { + pkgName: string; + declgenV1OutPath: string; + modulePath: string; + } | null = null; + + for (const [pkgName, info] of combinedMap) { + const declgenV1OutPath = toUnixPath(info.declgenV1OutPath); + const modulePath = toUnixPath(info.modulePath); + const declgenBridgeCodePath = toUnixPath(info.declgenBridgeCodePath); + + if ( + resolvedFileName && + resolvedFileName.startsWith(modulePath + '/') && + !resolvedFileName.startsWith(declgenBridgeCodePath + '/') + ) { + if (!bestMatch || modulePath.length > bestMatch.modulePath.length) { + bestMatch = { pkgName, declgenV1OutPath, modulePath }; + } } + if (moduleRequest === pkgName) { - arktsEvoDeclFilePath = path.join(declgenV1OutPath, pkgName, 'Index.d.ets'); - break; + return path.join(declgenV1OutPath, pkgName, 'Index.d.ets'); } + if (moduleRequest.startsWith(pkgName + '/')) { - arktsEvoDeclFilePath = moduleRequest.replace( - pkgName, - toUnixPath(path.join(declgenV1OutPath, pkgName, 'src/main/ets')) - ) + EXTNAME_D_ETS; - break; + return ( + moduleRequest.replace( + pkgName, + toUnixPath(path.join(declgenV1OutPath, pkgName, 'src/main/ets')) + ) + EXTNAME_D_ETS + ); } } + + if (bestMatch) { + const { pkgName, declgenV1OutPath, modulePath } = bestMatch; + arktsEvoDeclFilePath = resolvedFileName + .replace(modulePath, toUnixPath(path.join(declgenV1OutPath, pkgName))) + .replace(EXTNAME_ETS, EXTNAME_D_ETS); + } + return arktsEvoDeclFilePath; }