From c7e7080af6eb061f0681941b6c20e545cf750b8e Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Mon, 13 Jun 2022 12:25:06 +0200 Subject: [PATCH] [K/N] Allow control of BundleShortVersionString and BundleVersion Adding -Xbundle-version and -Xbundle-short-version-string compiler arguments. These can be used in the freeCompilerArgs in the gradle configuration to control the version strings in the Info.plist in generated frameworks. ``` version = "1.0" macosX64("native") { binaries.framework { compilation.kotlinOptions.freeCompilerArgs += "-Xbundle-version=$version" } } ``` ^KT-33117 Fixed. --- .../src/org/jetbrains/kotlin/cli/bc/K2Native.kt | 2 ++ .../kotlin/cli/bc/K2NativeCompilerArguments.kt | 14 ++++++++++++++ .../backend/konan/KonanConfigurationKeys.kt | 4 ++++ .../kotlin/backend/konan/objcexport/ObjCExport.kt | 8 ++++++-- kotlin-native/backend.native/tests/build.gradle | 15 ++++++++++++--- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index 262c3687f88..acb3905ce26 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -382,6 +382,8 @@ class K2Native : CLICompiler() { }) putIfNotNull(RUNTIME_LOGS, arguments.runtimeLogs) putIfNotNull(BUNDLE_ID, parseBundleId(arguments, outputKind, configuration)) + putIfNotNull(BUNDLE_SHORT_VERSION_STRING, arguments.bundleShortVersionString) + putIfNotNull(BUNDLE_VERSION, arguments.bundleVersion) put(MEANINGFUL_BRIDGE_NAMES, arguments.meaningfulBridgeNames) arguments.testDumpOutputPath?.let { put(TEST_DUMP_OUTPUT_PATH, it) } put(PARTIAL_LINKAGE, arguments.partialLinkage) diff --git a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index 448b658be13..55daec390c4 100644 --- a/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/kotlin-native/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -109,6 +109,20 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { ) var bundleId: String? = null + @Argument( + value = "-Xbundle-short-version-string", + valueDescription = "", + description = "Bundle short version string to be set in Info.plist of a produced framework" + ) + var bundleShortVersionString: String? = null + + @Argument( + value = "-Xbundle-version", + valueDescription = "", + description = "Bundle version to be set in Info.plist of a produced framework" + ) + var bundleVersion: String? = null + @Argument( value = "-Xcache-directory", valueDescription = "", diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index 0edfc8d9f0f..3a74c7c4a28 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -14,6 +14,10 @@ class KonanConfigKeys { // Keep the list lexically sorted. val BUNDLE_ID: CompilerConfigurationKey = CompilerConfigurationKey.create("bundle ID to be set in Info.plist of a produced framework") + val BUNDLE_SHORT_VERSION_STRING: CompilerConfigurationKey + = CompilerConfigurationKey.create("bundle short version string to be set in Info.plist of the produced framework") + val BUNDLE_VERSION: CompilerConfigurationKey + = CompilerConfigurationKey.create("bundle version to be set in Info.plist of the produced framework") val CHECK_DEPENDENCIES: CompilerConfigurationKey = CompilerConfigurationKey.create("check dependencies and download the missing ones") val DEBUG: CompilerConfigurationKey diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt index dc6188d25d5..593fee16480 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/ObjCExport.kt @@ -8,6 +8,8 @@ package org.jetbrains.kotlin.backend.konan.objcexport import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.Context import org.jetbrains.kotlin.backend.konan.KonanConfigKeys.Companion.BUNDLE_ID +import org.jetbrains.kotlin.backend.konan.KonanConfigKeys.Companion.BUNDLE_SHORT_VERSION_STRING +import org.jetbrains.kotlin.backend.konan.KonanConfigKeys.Companion.BUNDLE_VERSION import org.jetbrains.kotlin.backend.konan.descriptors.getPackageFragments import org.jetbrains.kotlin.backend.konan.descriptors.isInterface import org.jetbrains.kotlin.backend.konan.getExportedDependencies @@ -164,6 +166,8 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { val file = directory.child("Info.plist") val bundleId = guessBundleID(name) + val bundleShortVersionString = context.configuration[BUNDLE_SHORT_VERSION_STRING] ?: "1.0" + val bundleVersion = context.configuration[BUNDLE_VERSION] ?: "1" val platform = properties.platformName() val minimumOsVersion = properties.osVersionMin @@ -184,13 +188,13 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) { CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + $bundleShortVersionString CFBundleSupportedPlatforms $platform CFBundleVersion - 1 + $bundleVersion """.trimIndent()) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 2e594b6f2b2..fe0cfca33a9 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -5684,15 +5684,24 @@ if (isAppleTarget(project)) { framework("Foo") { sources = ["framework/bundle_id/main.kt", "framework/bundle_id/lib.kt"] + opts = ["-Xbundle-version=FooBundleVersion", "-Xbundle-short-version-string=FooBundleShortVersionString"] } swiftSources = [] doLast { def frameworkPath = "$testOutputFramework/testFrameworkBundleId/$target/Foo.framework" - def pattern = ~"CFBundleIdentifier\n\\s*Foo" + def bundleIdPattern = ~"CFBundleIdentifier\n\\s*Foo" + def bundleShortVersionStringPattern = ~"CFBundleShortVersionString\n\\s*FooBundleShortVersionString" + def bundleVersionPattern = ~"CFBundleVersion\n\\s*FooBundleVersion" def plistContent = file("$frameworkPath/Resources/Info.plist").text - if (!pattern.matcher(plistContent).find()) { - throw new Error("Unexpected Info.plist content:\n$plistContent") + if (!bundleIdPattern.matcher(plistContent).find()) { + throw new Error("Unexpected CFBundleIdentifier in Info.plist:\n$plistContent") + } + if (!bundleShortVersionStringPattern.matcher(plistContent).find()) { + throw new Error("Unexpected CFBundleShortVersionString in Info.plist:\n$plistContent") + } + if (!bundleVersionPattern.matcher(plistContent).find()) { + throw new Error("Unexpected CFBundleVersion in Info.plist:\n$plistContent") } } }