diff --git a/build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt b/build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt index e72fa1b..d8f444a 100644 --- a/build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt +++ b/build-plugins/kmp-conventions/src/main/kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt @@ -16,45 +16,44 @@ import org.jetbrains.kotlin.konan.target.HostManager * https://youtrack.jetbrains.com/issue/KT-38317 */ public fun Project.configureIosSimulatorTasks() { - val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15" + if (!HostManager.hostIsMac) return + val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15" val xcrun = "/usr/bin/xcrun" - tasks.register("bootIosSimulatorDevice", Exec::class.java) { + val bootTask = rootProject.tasks.maybeCreate("bootIosSimulatorDevice", Exec::class.java).apply { isIgnoreExitValue = true commandLine(xcrun, "simctl", "boot", simulatorDeviceName) doLast { val result = executionResult.get() val code = result.exitValue - if (code != 148 && code != 149 && code != 405) { // ignore "simulator already running" errors + if (code != 148 && code != 149) { // ignore "simulator already running" errors result.assertNormalExitValue() } } } - tasks.register("shutdownIosSimulatorDevice", Exec::class.java) { + val shutdownTask = rootProject.tasks.maybeCreate("shutdownIosSimulatorDevice", Exec::class.java).apply { isIgnoreExitValue = true - mustRunAfter(tasks.withType()) commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName) doLast { val result = executionResult.get() - if (result.exitValue != 405) { // ignore "simulator already shutdown" errors + val code = result.exitValue + if (code != 148 && code != 149) { // ignore "simulator already shutdown" errors result.assertNormalExitValue() } } } - tasks.withType().configureEach { - if (!HostManager.hostIsMac) { - return@configureEach + allprojects { + val simulatorTasks = tasks.withType() + simulatorTasks.configureEach { + dependsOn(bootTask) + standalone.set(false) + device.set(simulatorDeviceName) } - - dependsOn("bootIosSimulatorDevice") - finalizedBy("shutdownIosSimulatorDevice") - - standalone.set(false) - device.set(simulatorDeviceName) + shutdownTask.mustRunAfter(simulatorTasks) } }