Skip to content

Commit 7a07412

Browse files
authored
kn: Create iOS simulator boot and shutdown tasks in root project (#64)
1 parent ab34ff6 commit 7a07412

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,44 @@ import org.jetbrains.kotlin.konan.target.HostManager
1616
* https://youtrack.jetbrains.com/issue/KT-38317
1717
*/
1818
public fun Project.configureIosSimulatorTasks() {
19-
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
19+
if (!HostManager.hostIsMac) return
2020

21+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
2122
val xcrun = "/usr/bin/xcrun"
2223

23-
tasks.register("bootIosSimulatorDevice", Exec::class.java) {
24+
val bootTask = rootProject.tasks.maybeCreate("bootIosSimulatorDevice", Exec::class.java).apply {
2425
isIgnoreExitValue = true
2526
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
2627

2728
doLast {
2829
val result = executionResult.get()
2930
val code = result.exitValue
30-
if (code != 148 && code != 149 && code != 405) { // ignore "simulator already running" errors
31+
if (code != 148 && code != 149) { // ignore "simulator already running" errors
3132
result.assertNormalExitValue()
3233
}
3334
}
3435
}
3536

36-
tasks.register("shutdownIosSimulatorDevice", Exec::class.java) {
37+
val shutdownTask = rootProject.tasks.maybeCreate("shutdownIosSimulatorDevice", Exec::class.java).apply {
3738
isIgnoreExitValue = true
38-
mustRunAfter(tasks.withType<KotlinNativeSimulatorTest>())
3939
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)
4040

4141
doLast {
4242
val result = executionResult.get()
43-
if (result.exitValue != 405) { // ignore "simulator already shutdown" errors
43+
val code = result.exitValue
44+
if (code != 148 && code != 149) { // ignore "simulator already shutdown" errors
4445
result.assertNormalExitValue()
4546
}
4647
}
4748
}
4849

49-
tasks.withType<KotlinNativeSimulatorTest>().configureEach {
50-
if (!HostManager.hostIsMac) {
51-
return@configureEach
50+
allprojects {
51+
val simulatorTasks = tasks.withType<KotlinNativeSimulatorTest>()
52+
simulatorTasks.configureEach {
53+
dependsOn(bootTask)
54+
standalone.set(false)
55+
device.set(simulatorDeviceName)
5256
}
53-
54-
dependsOn("bootIosSimulatorDevice")
55-
finalizedBy("shutdownIosSimulatorDevice")
56-
57-
standalone.set(false)
58-
device.set(simulatorDeviceName)
57+
shutdownTask.mustRunAfter(simulatorTasks)
5958
}
6059
}

0 commit comments

Comments
 (0)