44 */
55package aws.sdk.kotlin.gradle.kmp
66
7+ import org.gradle.api.GradleException
78import org.gradle.api.Project
89import org.gradle.api.tasks.Exec
910import 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 */
1819public 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