Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<KotlinNativeSimulatorTest>())
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<KotlinNativeSimulatorTest>().configureEach {
if (!HostManager.hostIsMac) {
return@configureEach
allprojects {
val simulatorTasks = tasks.withType<KotlinNativeSimulatorTest>()
simulatorTasks.configureEach {
dependsOn(bootTask)
standalone.set(false)
device.set(simulatorDeviceName)
}

dependsOn("bootIosSimulatorDevice")
finalizedBy("shutdownIosSimulatorDevice")

standalone.set(false)
device.set(simulatorDeviceName)
shutdownTask.mustRunAfter(simulatorTasks)
}
}