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 acb3905ce26..262c3687f88 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,8 +382,6 @@ 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 55daec390c4..b57a07dd665 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 @@ -105,24 +105,10 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { @Argument( value = "-Xbundle-id", valueDescription = "", - 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=." ) 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/BinaryOptions.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt index 4f2e4c12992..ec25bd738da 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt @@ -31,6 +31,10 @@ object BinaryOptions : BinaryOptionRegistry() { val gcSchedulerType by option() val linkRuntime by option() + + val bundleId by stringOption() + val bundleShortVersionString by stringOption() + val bundleVersion by stringOption() } open class BinaryOption( @@ -66,6 +70,15 @@ open class BinaryOptionRegistry { } } + protected fun stringOption(): PropertyDelegateProvider>> = + PropertyDelegateProvider { _, property -> + val option = BinaryOption(property.name, StringValueParser) + register(option) + ReadOnlyProperty { _, _ -> + option.compilerConfigurationKey + } + } + protected inline fun > option(): PropertyDelegateProvider>> = PropertyDelegateProvider { _, property -> val option = BinaryOption(property.name, EnumValueParser(enumValues().toList())) @@ -83,6 +96,12 @@ private object BooleanValueParser : BinaryOption.ValueParser { get() = "true|false" } +private object StringValueParser : BinaryOption.ValueParser { + override fun parse(value: String) = value + override val validValuesHint: String? + get() = null +} + @PublishedApi internal class EnumValueParser>(val values: List) : BinaryOption.ValueParser { // TODO: should we really ignore case here? 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 3a74c7c4a28..0edfc8d9f0f 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,10 +14,6 @@ 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 593fee16480..103b1af2da5 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,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= and the new -Xbinary=bundleId= 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= compiler flag." ) } return bundleID diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index fe0cfca33a9..beea73672a6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -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 = []