From fe8b2597ad8814bc905d7668bfaaed49338a681d Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Thu, 2 Mar 2023 19:57:10 +0800 Subject: [PATCH] Add api version Signed-off-by: zhangrengao Change-Id: Ic9afbabc99e61135b44959078f0c37b59f9c9729 --- compiler/main.js | 6 ++++++ .../fast_build/ark_compiler/common/common_mode.ts | 6 ++++++ .../ark_compiler/common/process_ark_config.ts | 8 ++++++-- .../fast_build/ark_compiler/module/module_mode.ts | 9 +++++---- compiler/src/gen_abc_plugin.ts | 13 ++++++++++--- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 3091f5831..5280e8d56 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -627,6 +627,12 @@ function loadModuleInfo(projectConfig, envArgs) { buildJsonInfo.modulePathMap[buildJsonInfo.moduleName]) { projectConfig.moduleRootPath = buildJsonInfo.modulePathMap[buildJsonInfo.moduleName]; } + if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { + const moduleJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); + if (moduleJsonInfo.app.minAPIVersion) { + process.env.minPlatformVersion = moduleJsonInfo.app.minAPIVersion.toString(); + } + } } } diff --git a/compiler/src/fast_build/ark_compiler/common/common_mode.ts b/compiler/src/fast_build/ark_compiler/common/common_mode.ts index 708887df4..a158e2a12 100644 --- a/compiler/src/fast_build/ark_compiler/common/common_mode.ts +++ b/compiler/src/fast_build/ark_compiler/common/common_mode.ts @@ -94,6 +94,12 @@ export abstract class CommonMode { this.throwArkTsCompilerError('ArkTS:ERROR please set panda mode'); } + // Compatible api 8 ts2abc is archived and does not support target-api-version option + if (this.projectConfig.minPlatformVersion && this.projectConfig.minPlatformVersion !== '8') { + args.push('--target-api-version'); + args.push(this.projectConfig.minPlatformVersion); + } + return args; } diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index e8cb860e2..cc077d765 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -96,16 +96,20 @@ export function initArkProjectConfig(share: any) { projectConfig.packageDir = buildJsonInfo.packageManagerType === 'ohpm' ? OH_MODULES : NODE_MODULES; } } + + // For FA mode, minPlatformVersion is stored in manifest.json if (projectConfig.aceManifestPath && fs.existsSync(projectConfig.aceManifestPath)) { const manifestJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceManifestPath).toString()); if (manifestJsonInfo.minPlatformVersion) { - arkProjectConfig.minPlatformVersion = manifestJsonInfo.minPlatformVersion; + arkProjectConfig.minPlatformVersion = manifestJsonInfo.minPlatformVersion.toString(); } } + + // For Stage mode, minPlatformVersion is stored in module.json if (projectConfig.aceModuleJsonPath && fs.existsSync(projectConfig.aceModuleJsonPath)) { const moduleJsonInfo = JSON.parse(fs.readFileSync(projectConfig.aceModuleJsonPath).toString()); if (moduleJsonInfo.app.minAPIVersion) { - arkProjectConfig.minPlatformVersion = moduleJsonInfo.app.minAPIVersion; + arkProjectConfig.minPlatformVersion = moduleJsonInfo.app.minAPIVersion.toString(); } if (moduleJsonInfo.module) { arkProjectConfig.moduleName = moduleJsonInfo.module.name; diff --git a/compiler/src/fast_build/ark_compiler/module/module_mode.ts b/compiler/src/fast_build/ark_compiler/module/module_mode.ts index 33be92c1d..a305ca074 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_mode.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_mode.ts @@ -582,8 +582,9 @@ export class ModuleMode extends CommonMode { private mergeProtoToAbc() { mkdirsSync(this.projectConfig.aceModuleBuild); - const cmd: any = `"${this.arkConfig.mergeAbcPath}" --input "@${this.protoFilePath}" --outputFilePath "${ - this.projectConfig.aceModuleBuild}" --output ${MODULES_ABC} --suffix protoBin`; + const cmd: any = `"${this.arkConfig.mergeAbcPath}" --target-api-version ${this.projectConfig.minPlatformVersion} --input + "@${this.protoFilePath}" --outputFilePath "${this.projectConfig.aceModuleBuild}" --output ${MODULES_ABC} --suffix + protoBin`; try { childProcess.execSync(cmd, { windowsHide: true }); } catch (e) { @@ -622,8 +623,8 @@ export class ModuleMode extends CommonMode { return; } mkdirsSync(path.dirname(this.npmEntriesProtoFilePath)); - const cmd: string = `"${this.arkConfig.js2abcPath}" --compile-npm-entries "${ - this.npmEntriesInfoPath}" "${this.npmEntriesProtoFilePath}"`; + const cmd: string = `"${this.arkConfig.js2abcPath}" --target-api-version ${this.projectConfig.minPlatformVersion} + --compile-npm-entries "${this.npmEntriesInfoPath}" "${this.npmEntriesProtoFilePath}"`; try { childProcess.execSync(cmd, { windowsHide: true }); } catch (e) { diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index f49f05126..4c32f1e64 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -613,7 +613,8 @@ function processEntryToGenAbc(entryInfos: Map): void { js2Abc = path.join(arkDir, 'build-mac', 'bin', 'js2abc'); } validateFilePathLength(js2Abc, logger); - const singleCmd: any = `"${js2Abc}" --compile-npm-entries "${npmEntriesInfoPath}" "${npmEntriesProtoFilePath}`; + const singleCmd: any = `"${js2Abc}" --target-api-version "${process.env.minPlatformVersion}" --compile-npm-entries + "${npmEntriesInfoPath}" "${npmEntriesProtoFilePath}`; try { childProcess.execSync(singleCmd); } catch (e) { @@ -764,9 +765,14 @@ export function initAbcEnv() : string[] { if (projectConfig.compileMode === ESMODULE) { args.push('--merge-abc'); } - } else { + } else { logger.error(red, `ArkTS:ERROR please set panda module`, reset); } + if (process.env.minPlatformVersion && process.env.minPlatformVersion !== 'undefined' && + process.env.minPlatformVersion !== '8') { + args.push('--target-api-version'); + args.push(process.env.minPlatformVersion); + } return args; } @@ -1189,7 +1195,8 @@ function mergeProtoToAbc(): void { mergeAbc = path.join(arkDir, 'build-mac', 'bin', 'merge_abc'); } mkdirsSync(projectConfig.buildPath); - const singleCmd: any = `"${mergeAbc}" --input "@${protoFilePath}" --outputFilePath "${projectConfig.buildPath}" --output ${MODULES_ABC} --suffix protoBin`; + const singleCmd: any = `"${mergeAbc}" --target-api-version "${process.env.minPlatformVersion}" --input + "@${protoFilePath}" --outputFilePath "${projectConfig.buildPath}" --output ${MODULES_ABC} --suffix protoBin`; try { childProcess.execSync(singleCmd); } catch (e) { -- Gitee