Skip to content

Commit 9cc6f9f

Browse files
committed
Create boot and shutdown tasks in root project, which all simulator tasks depend on
1 parent 3b5ccdd commit 9cc6f9f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package aws.sdk.kotlin.gradle.kmp
66

7+
import org.gradle.api.GradleException
78
import org.gradle.api.Project
89
import org.gradle.api.tasks.Exec
910
import org.gradle.kotlin.dsl.withType
@@ -16,11 +17,13 @@ import org.jetbrains.kotlin.konan.target.HostManager
1617
* https://youtrack.jetbrains.com/issue/KT-38317
1718
*/
1819
public fun Project.configureIosSimulatorTasks() {
19-
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
20+
if (this != rootProject) { throw GradleException("This function should only be called from the root project.") }
21+
if (!HostManager.hostIsMac) return
2022

23+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
2124
val xcrun = "/usr/bin/xcrun"
2225

23-
tasks.register("bootIosSimulatorDevice", Exec::class.java) {
26+
val bootTask = rootProject.tasks.maybeCreate("bootIosSimulatorDevice", Exec::class.java).apply {
2427
isIgnoreExitValue = true
2528
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
2629

@@ -33,9 +36,8 @@ public fun Project.configureIosSimulatorTasks() {
3336
}
3437
}
3538

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

4143
doLast {
@@ -47,15 +49,13 @@ public fun Project.configureIosSimulatorTasks() {
4749
}
4850
}
4951

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

0 commit comments

Comments
 (0)