From 6b9844705e60ce78d4a3ae98104b235688cd2a01 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Tue, 13 Feb 2024 11:14:24 +0000 Subject: [PATCH] [K/N] Make InfoPlistBuilder add DT* properties The Firebase TestLab requires those properties to be present, otherwise fails with verification errors. These properties are specific to the Xcode installation or toolchain used, and should be retrieved from it, not hardcoded. See also KT-65601. Part of the ^KT-58928 Merge-request: KT-MR-13964 Merged-by: Pavel Punegov --- .../konan/objcexport/InfoPListBuilder.kt | 54 ++++++++++++++++--- .../backend/konan/objcexport/ObjCExport.kt | 7 ++- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/InfoPListBuilder.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/InfoPListBuilder.kt index 215826dfc5d..021e7511dff 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/InfoPListBuilder.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/objcexport/InfoPListBuilder.kt @@ -8,12 +8,13 @@ package org.jetbrains.kotlin.backend.konan.objcexport import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.konan.target.AppleConfigurables -import org.jetbrains.kotlin.konan.target.Family -import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.konan.target.platformName +import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.name.Name +internal enum class BundleType { + FRAMEWORK, XCTEST +} + /** * Creates an Info.plist file for an Apple framework. * @@ -22,6 +23,7 @@ import org.jetbrains.kotlin.name.Name */ internal class InfoPListBuilder( private val config: KonanConfig, + private val bundleType: BundleType = BundleType.FRAMEWORK ) { private val configuration = config.configuration @@ -37,6 +39,10 @@ internal class InfoPListBuilder( val properties = config.platform.configurables as AppleConfigurables val platform = properties.platformName() val minimumOsVersion = properties.osVersionMin + val bundlePackageType = when (bundleType) { + BundleType.FRAMEWORK -> "FMWK" + BundleType.XCTEST -> "BNDL" + } val contents = StringBuilder() contents.append(""" @@ -53,7 +59,7 @@ internal class InfoPListBuilder( CFBundleName $name CFBundlePackageType - FMWK + $bundlePackageType CFBundleShortVersionString $bundleShortVersionString CFBundleSupportedPlatforms @@ -79,6 +85,7 @@ internal class InfoPListBuilder( """.trimMargin()) } + val target = config.target // UIDeviceFamily mapping: // 1 - iPhone @@ -114,12 +121,47 @@ internal class InfoPListBuilder( ) } + if (bundleType == BundleType.XCTEST) { + val platformName = properties.platformName().lowercase() + val platformVersion = properties.sdkVersion + + contents.append(""" + | DTPlatformName + | ${platformName} + | DTPlatformVersion + | ${platformVersion} + | DTSDKName + | ${platformName}${platformVersion} + + """.trimMargin()) + + // FIXME with KT-65601: These are hardcoded for the version of Xcode used in our toolchain (15.0) + // They could be retrieved from `/usr/bin/xcrun --show-sdk-*-version --sdk SDK` for the installed Xcode + val sdkBuild = when (target.family) { + Family.OSX -> "23A334" + Family.IOS -> "21A325" + Family.TVOS -> "21J351" + Family.WATCHOS -> "21R354" + else -> error("Unknown Apple family: ${target.family}") + } + contents.append(""" + | DTXcode + | 1500 + | DTXcodeBuild + | 15A240d + | DTSDKBuild + | $sdkBuild + | DTPlatformBuild + | $sdkBuild + + """.trimMargin()) + } + contents.append(""" """.trimIndent()) - // TODO: Xcode also add some number of DT* keys. return contents.toString() } 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 381b720b8be..3721857af66 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 @@ -129,8 +129,11 @@ internal fun createTestBundle( bundleDirectory: File ) { val name = bundleDirectory.name.removeSuffix(CompilerOutputKind.TEST_BUNDLE.suffix()) - BundleBuilder(config, infoPListBuilder = InfoPListBuilder(config), mainPackageGuesser = MainPackageGuesser()) - .build(moduleDescriptor, bundleDirectory, name) + BundleBuilder( + config = config, + infoPListBuilder = InfoPListBuilder(config, BundleType.XCTEST), + mainPackageGuesser = MainPackageGuesser() + ).build(moduleDescriptor, bundleDirectory, name) } // TODO: No need for such class in dynamic driver.