[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.
This commit is contained in:
Mads Ager
2022-06-13 12:25:06 +02:00
committed by Space
parent fcdab3995a
commit c7e7080af6
5 changed files with 38 additions and 5 deletions
@@ -382,6 +382,8 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
})
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)
@@ -109,6 +109,20 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
)
var bundleId: String? = null
@Argument(
value = "-Xbundle-short-version-string",
valueDescription = "<short version string>",
description = "Bundle short version string to be set in Info.plist of a produced framework"
)
var bundleShortVersionString: String? = null
@Argument(
value = "-Xbundle-version",
valueDescription = "<version>",
description = "Bundle version to be set in Info.plist of a produced framework"
)
var bundleVersion: String? = null
@Argument(
value = "-Xcache-directory",
valueDescription = "<path>",
@@ -14,6 +14,10 @@ class KonanConfigKeys {
// Keep the list lexically sorted.
val BUNDLE_ID: CompilerConfigurationKey<String>
= CompilerConfigurationKey.create("bundle ID to be set in Info.plist of a produced framework")
val BUNDLE_SHORT_VERSION_STRING: CompilerConfigurationKey<String>
= CompilerConfigurationKey.create("bundle short version string to be set in Info.plist of the produced framework")
val BUNDLE_VERSION: CompilerConfigurationKey<String>
= CompilerConfigurationKey.create("bundle version to be set in Info.plist of the produced framework")
val CHECK_DEPENDENCIES: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("check dependencies and download the missing ones")
val DEBUG: CompilerConfigurationKey<Boolean>
@@ -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) {
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$bundleShortVersionString</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>$platform</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>$bundleVersion</string>
""".trimIndent())
@@ -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 = ~"<key>CFBundleIdentifier</key>\n\\s*<string>Foo</string>"
def bundleIdPattern = ~"<key>CFBundleIdentifier</key>\n\\s*<string>Foo</string>"
def bundleShortVersionStringPattern = ~"<key>CFBundleShortVersionString</key>\n\\s*<string>FooBundleShortVersionString</string>"
def bundleVersionPattern = ~"<key>CFBundleVersion</key>\n\\s*<string>FooBundleVersion</string>"
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")
}
}
}