[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 <Pavel.Punegov@jetbrains.com>
This commit is contained in:
Pavel Punegov
2024-02-13 11:14:24 +00:00
committed by Space Team
parent 3d0c9f9edd
commit 6b9844705e
2 changed files with 53 additions and 8 deletions
@@ -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(
<key>CFBundleName</key>
<string>$name</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<string>$bundlePackageType</string>
<key>CFBundleShortVersionString</key>
<string>$bundleShortVersionString</string>
<key>CFBundleSupportedPlatforms</key>
@@ -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("""
| <key>DTPlatformName</key>
| <string>${platformName}</string>
| <key>DTPlatformVersion</key>
| <string>${platformVersion}</string>
| <key>DTSDKName</key>
| <string>${platformName}${platformVersion}</string>
""".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("""
| <key>DTXcode</key>
| <string>1500</string>
| <key>DTXcodeBuild</key>
| <string>15A240d</string>
| <key>DTSDKBuild</key>
| <string>$sdkBuild</string>
| <key>DTPlatformBuild</key>
| <string>$sdkBuild</string>
""".trimMargin())
}
contents.append("""
</dict>
</plist>
""".trimIndent())
// TODO: Xcode also add some number of DT* keys.
return contents.toString()
}
@@ -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.