Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,60 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.gradle.kmp

import org.gradle.api.Project
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
import org.jetbrains.kotlin.konan.target.HostManager

/**
* Disables standalone mode in simulator tests since it causes issues with TLS.
* This means we need to manage the simulator state ourselves (booting, shutting down).
* https://youtrack.jetbrains.com/issue/KT-38317
*/
public fun Project.configureIosSimulatorTasks() {
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"

val xcrun = "/usr/bin/xcrun"

tasks.register("bootIosSimulatorDevice", Exec::class.java) {
isIgnoreExitValue = true
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)

doLast {
val result = executionResult.get()
val code = result.exitValue
if (code != 148 && code != 149) { // ignore "simulator already running" errors
result.assertNormalExitValue()
}
}
}

tasks.register("shutdownIosSimulatorDevice", Exec::class.java) {
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
result.assertNormalExitValue()
}
}
}

tasks.withType<KotlinNativeSimulatorTest>().configureEach {
if (!HostManager.hostIsMac) {
return@configureEach
}

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

standalone.set(false)
device.set(simulatorDeviceName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ private val KotlinNativeTarget.isApple: Boolean
private val KotlinNativeTarget.isWindows: Boolean
get() = konanTarget.family == Family.MINGW


internal fun Project.disable(knTarget: KotlinNativeTarget) {
logger.warn("disabling Kotlin/Native target: ${knTarget.name}")
knTarget.apply {
Expand Down