diff --git a/compiler/main.js b/compiler/main.js index 3091f5831661f8db875386c2c9aa80cbc82ab9d3..5280e8d5669b061ff5f0caa928d493aaaffc294f 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 708887df4e870af35a6d4cce3e13855e9e10d667..a158e2a1257783eaf077bd1c1c60fa459e56496d 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 e8cb860e2586d1f76aab72d57b19d47983c5404e..cc077d7656ba5287943d870487a123bb6e5146be 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 33be92c1d46c1c8d7b66383958ec483906e6b45b..a305ca0740de17aaec6807f90612bb7de68981e4 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 f49f05126f95a685ba3ed1bb6bf6adb10f7bcdbe..4c32f1e6417635b444febfa0231d8c8cf798131e 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) {