[K/N] Deprecate -Xbundle-id and use binary options for Info.plist.

This commit is contained in:
Mads Ager
2022-06-16 15:54:33 +02:00
committed by Space
parent c7e7080af6
commit ef499fedbb
6 changed files with 35 additions and 30 deletions
@@ -382,8 +382,6 @@ 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)
@@ -105,24 +105,10 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
@Argument(
value = "-Xbundle-id",
valueDescription = "<id>",
description = "Bundle ID to be set in Info.plist of a produced framework"
description = "Bundle ID to be set in Info.plist of a produced framework. Deprecated. Please use -Xbinary=bundleId=<id>."
)
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>",
@@ -31,6 +31,10 @@ object BinaryOptions : BinaryOptionRegistry() {
val gcSchedulerType by option<GCSchedulerType>()
val linkRuntime by option<RuntimeLinkageStrategyBinaryOption>()
val bundleId by stringOption()
val bundleShortVersionString by stringOption()
val bundleVersion by stringOption()
}
open class BinaryOption<T : Any>(
@@ -66,6 +70,15 @@ open class BinaryOptionRegistry {
}
}
protected fun stringOption(): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<String>>> =
PropertyDelegateProvider { _, property ->
val option = BinaryOption(property.name, StringValueParser)
register(option)
ReadOnlyProperty { _, _ ->
option.compilerConfigurationKey
}
}
protected inline fun <reified T : Enum<T>> option(): PropertyDelegateProvider<Any?, ReadOnlyProperty<Any?, CompilerConfigurationKey<T>>> =
PropertyDelegateProvider { _, property ->
val option = BinaryOption(property.name, EnumValueParser(enumValues<T>().toList()))
@@ -83,6 +96,12 @@ private object BooleanValueParser : BinaryOption.ValueParser<Boolean> {
get() = "true|false"
}
private object StringValueParser : BinaryOption.ValueParser<String> {
override fun parse(value: String) = value
override val validValuesHint: String?
get() = null
}
@PublishedApi
internal class EnumValueParser<T : Enum<T>>(val values: List<T>) : BinaryOption.ValueParser<T> {
// TODO: should we really ignore case here?
@@ -14,10 +14,6 @@ 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,8 +8,6 @@ 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
@@ -166,8 +164,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 bundleShortVersionString = context.configuration[BinaryOptions.bundleShortVersionString] ?: "1.0"
val bundleVersion = context.configuration[BinaryOptions.bundleVersion] ?: "1"
val platform = properties.platformName()
val minimumOsVersion = properties.osVersionMin
@@ -320,9 +318,17 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
private fun guessBundleID(bundleName: String): String {
val configuration = context.configuration
configuration[BUNDLE_ID]?.let {
return it
val deprecatedBundleIdOption = configuration[BUNDLE_ID]
val bundleIdOption = configuration[BinaryOptions.bundleId]
if (deprecatedBundleIdOption != null && bundleIdOption != null && deprecatedBundleIdOption != bundleIdOption) {
configuration.report(
CompilerMessageSeverity.ERROR,
"Both the deprecated -Xbundle-id=<id> and the new -Xbinary=bundleId=<id> options supplied with different values: " +
"'$deprecatedBundleIdOption' and '$bundleIdOption'. " +
"Please use only one of the options or make sure they have the same value."
)
}
deprecatedBundleIdOption?.let { return it } ?: bundleIdOption?.let { return it }
// Consider exported libraries only if we cannot infer the package from sources or included libs.
val mainPackage = guessMainPackage(context.getIncludedLibraryDescriptors() + context.moduleDescriptor)
@@ -336,7 +342,7 @@ internal class ObjCExport(val context: Context, symbolTable: SymbolTable) {
CompilerMessageSeverity.STRONG_WARNING,
"Cannot infer a bundle ID from packages of source files and exported dependencies, " +
"use the bundle name instead: $bundleName. " +
"Please specify the bundle ID explicitly using the -Xbundle-id compiler flag."
"Please specify the bundle ID explicitly using the -Xbinary=bundleId=<id> compiler flag."
)
}
return bundleID
@@ -5417,7 +5417,7 @@ if (isAppleTarget(project)) {
framework(frameworkName) {
sources = ['objcexport']
library = libraryName
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbundle-id=foo.bar"]
opts = ["-Xemit-lazy-objc-header=$lazyHeader", "-Xexport-kdoc", "-Xbinary=bundleId=foo.bar"]
}
swiftSources = ['objcexport']
if (isNoopGC) {
@@ -5684,7 +5684,7 @@ 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"]
opts = ["-Xbinary=bundleVersion=FooBundleVersion", "-Xbinary=bundleShortVersionString=FooBundleShortVersionString"]
}
swiftSources = []