From 566ee0c84e2413757ae24b9e9964548afb32ed32 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Thu, 6 Jul 2023 15:37:19 +0800 Subject: [PATCH] Add api version Issue:https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I7IZCE Signed-off-by: ctw-ian Change-Id: Ib63ea34e3c95759d6c4164f1496364f862939479 --- compiler/main.js | 6 ++++++ .../src/fast_build/ark_compiler/common/common_mode.ts | 6 ++++++ .../fast_build/ark_compiler/common/process_ark_config.ts | 8 ++++++-- compiler/src/gen_abc_plugin.ts | 7 ++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/compiler/main.js b/compiler/main.js index 0357558b6..7f293dc7f 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -699,6 +699,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 037cc2bbd..81c733b62 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 25c657af3..b8313b7a6 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 @@ -101,16 +101,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/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index fdb06737f..016525d28 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -764,9 +764,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; } -- Gitee