@@ -6,7 +6,12 @@ import aws.sdk.kotlin.gradle.dsl.configurePublishing
66import aws.sdk.kotlin.gradle.kmp.*
77import aws.sdk.kotlin.gradle.util.typedProp
88import org.gradle.kotlin.dsl.withType
9+ import org.gradle.api.Project
10+ import org.gradle.api.tasks.Exec
11+ import org.gradle.kotlin.dsl.withType
12+ import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
913import org.jetbrains.kotlin.gradle.dsl.JvmTarget
14+ import org.jetbrains.kotlin.konan.target.HostManager
1015
1116plugins {
1217 alias(libs.plugins.dokka)
@@ -113,5 +118,56 @@ subprojects {
113118 }
114119 }
115120
116- configureIosSimulatorTasks()
121+ smithyConfigureIosSimulatorTasks()
122+ }
123+
124+
125+ /* *
126+ * Disables standalone mode in simulator tests since it causes issues with TLS.
127+ * This means we need to manage the simulator state ourselves (booting, shutting down).
128+ * https://youtrack.jetbrains.com/issue/KT-38317
129+ */
130+ public fun Project.smithyConfigureIosSimulatorTasks () {
131+ val simulatorDeviceName = project.findProperty(" iosSimulatorDevice" ) as ? String ? : " iPhone 15"
132+
133+ val xcrun = " /usr/bin/xcrun"
134+
135+ tasks.register(" bootIosSimulatorDevice" , Exec ::class .java) {
136+ isIgnoreExitValue = true
137+ commandLine(xcrun, " simctl" , " boot" , simulatorDeviceName)
138+
139+ doLast {
140+ val result = executionResult.get()
141+ val code = result.exitValue
142+ if (code != 148 && code != 149 ) { // ignore "simulator already running" errors
143+ result.assertNormalExitValue()
144+ }
145+ }
146+ }
147+
148+ tasks.register(" shutdownIosSimulatorDevice" , Exec ::class .java) {
149+ isIgnoreExitValue = true
150+ mustRunAfter(tasks.withType<KotlinNativeSimulatorTest >())
151+ commandLine(xcrun, " simctl" , " shutdown" , simulatorDeviceName)
152+
153+ doLast {
154+ val result = executionResult.get()
155+ val code = result.exitValue
156+ if (code != 148 && code != 149 ) { // ignore "simulator already shutdown" errors
157+ result.assertNormalExitValue()
158+ }
159+ }
160+ }
161+
162+ tasks.withType<KotlinNativeSimulatorTest >().configureEach {
163+ if (! HostManager .hostIsMac) {
164+ return @configureEach
165+ }
166+
167+ dependsOn(" bootIosSimulatorDevice" )
168+ finalizedBy(" shutdownIosSimulatorDevice" )
169+
170+ standalone.set(false )
171+ device.set(simulatorDeviceName)
172+ }
117173}
0 commit comments