From 3b5ccdd35bbd844224c653d763b1d3487a448c29 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 3 Feb 2025 12:42:03 -0500 Subject: [PATCH 1/5] Check code 148 and 149 in shutdown task --- .../aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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..18498b8 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 @@ -27,7 +27,7 @@ public fun Project.configureIosSimulatorTasks() { 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() } } @@ -40,7 +40,8 @@ public fun Project.configureIosSimulatorTasks() { 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() } } @@ -57,4 +58,4 @@ public fun Project.configureIosSimulatorTasks() { standalone.set(false) device.set(simulatorDeviceName) } -} +} \ No newline at end of file From 9cc6f9f2568912c65e99439077e682e22df40679 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 3 Feb 2025 16:47:01 -0500 Subject: [PATCH 2/5] Create boot and shutdown tasks in root project, which all simulator tasks depend on --- .../gradle/kmp/ConfigureIosSimulator.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 18498b8..0b5ac72 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 @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.gradle.kmp +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.tasks.Exec import org.gradle.kotlin.dsl.withType @@ -16,11 +17,13 @@ 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 (this != rootProject) { throw GradleException("This function should only be called from the root project.") } + 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) @@ -33,9 +36,8 @@ public fun Project.configureIosSimulatorTasks() { } } - 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 { @@ -47,15 +49,13 @@ public fun Project.configureIosSimulatorTasks() { } } - 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) } } \ No newline at end of file From f7ab604bf929acc95204c1a69ff46843c73d0dde Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 3 Feb 2025 16:48:09 -0500 Subject: [PATCH 3/5] ktlint --- .../aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 0b5ac72..8072a23 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 @@ -17,7 +17,9 @@ import org.jetbrains.kotlin.konan.target.HostManager * https://youtrack.jetbrains.com/issue/KT-38317 */ public fun Project.configureIosSimulatorTasks() { - if (this != rootProject) { throw GradleException("This function should only be called from the root project.") } + if (this != rootProject) { + throw GradleException("This function should only be called from the root project.") + } if (!HostManager.hostIsMac) return val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15" @@ -58,4 +60,4 @@ public fun Project.configureIosSimulatorTasks() { } shutdownTask.mustRunAfter(simulatorTasks) } -} \ No newline at end of file +} From 209948445b2569a5c7bcf3c2be9646933c509d07 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 3 Feb 2025 20:36:59 -0500 Subject: [PATCH 4/5] Disable rootProject requirement --- .../kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt | 3 --- 1 file changed, 3 deletions(-) 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 8072a23..6bea931 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 @@ -17,9 +17,6 @@ import org.jetbrains.kotlin.konan.target.HostManager * https://youtrack.jetbrains.com/issue/KT-38317 */ public fun Project.configureIosSimulatorTasks() { - if (this != rootProject) { - throw GradleException("This function should only be called from the root project.") - } if (!HostManager.hostIsMac) return val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15" From d5ea46817222a09783f813c15d10737aa16e9055 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 3 Feb 2025 20:37:18 -0500 Subject: [PATCH 5/5] ktlint --- .../kotlin/aws/sdk/kotlin/gradle/kmp/ConfigureIosSimulator.kt | 1 - 1 file changed, 1 deletion(-) 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 6bea931..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 @@ -4,7 +4,6 @@ */ package aws.sdk.kotlin.gradle.kmp -import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.tasks.Exec import org.gradle.kotlin.dsl.withType