Skip to content

Commit f712e53

Browse files
authored
kn: commonize iOS simulator configuration (#63)
1 parent 4395e9d commit f712e53

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.gradle.kmp
6+
7+
import org.gradle.api.Project
8+
import org.gradle.api.tasks.Exec
9+
import org.gradle.kotlin.dsl.withType
10+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
11+
import org.jetbrains.kotlin.konan.target.HostManager
12+
13+
/**
14+
* Disables standalone mode in simulator tests since it causes issues with TLS.
15+
* This means we need to manage the simulator state ourselves (booting, shutting down).
16+
* https://youtrack.jetbrains.com/issue/KT-38317
17+
*/
18+
public fun Project.configureIosSimulatorTasks() {
19+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
20+
21+
val xcrun = "/usr/bin/xcrun"
22+
23+
tasks.register("bootIosSimulatorDevice", Exec::class.java) {
24+
isIgnoreExitValue = true
25+
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
26+
27+
doLast {
28+
val result = executionResult.get()
29+
val code = result.exitValue
30+
if (code != 148 && code != 149) { // ignore "simulator already running" errors
31+
result.assertNormalExitValue()
32+
}
33+
}
34+
}
35+
36+
tasks.register("shutdownIosSimulatorDevice", Exec::class.java) {
37+
isIgnoreExitValue = true
38+
mustRunAfter(tasks.withType<KotlinNativeSimulatorTest>())
39+
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)
40+
41+
doLast {
42+
val result = executionResult.get()
43+
if (result.exitValue != 405) { // ignore "simulator already shutdown" errors
44+
result.assertNormalExitValue()
45+
}
46+
}
47+
}
48+
49+
tasks.withType<KotlinNativeSimulatorTest>().configureEach {
50+
if (!HostManager.hostIsMac) {
51+
return@configureEach
52+
}
53+
54+
dependsOn("bootIosSimulatorDevice")
55+
finalizedBy("shutdownIosSimulatorDevice")
56+
57+
standalone.set(false)
58+
device.set(simulatorDeviceName)
59+
}
60+
}

build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureTargets.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ private val KotlinNativeTarget.isApple: Boolean
246246
private val KotlinNativeTarget.isWindows: Boolean
247247
get() = konanTarget.family == Family.MINGW
248248

249-
250249
internal fun Project.disable(knTarget: KotlinNativeTarget) {
251250
logger.warn("disabling Kotlin/Native target: ${knTarget.name}")
252251
knTarget.apply {

0 commit comments

Comments
 (0)