diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt index 6cb341d10fa..7beab5d3998 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt @@ -102,14 +102,17 @@ open class FrameworkTest : DefaultTask() { KonanTarget.MACOS_X64 -> "macosx" else -> throw IllegalStateException("Test target $target is not supported") } - return when (target) { + val simulatorPath = when (target) { KonanTarget.TVOS_X64, KonanTarget.IOS_X64, - KonanTarget.WATCHOS_X64 -> Xcode.current.getLatestSimulatorRuntimeFor(target, configs.osVersionMin)?.let { - "${it.bundlePath}/Contents/Resources/RuntimeRoot/usr/lib/swift" - } ?: error("Simulator runtime for $target ${configs.osVersionMin} is not available") - else -> configs.absoluteTargetToolchain + "/usr/lib/swift/$swiftPlatform" + KonanTarget.WATCHOS_X64 -> Xcode.current.getLatestSimulatorRuntimeFor(target, configs.osVersionMin)?.bundlePath?.let { + "$it/Contents/Resources/RuntimeRoot/usr/lib/swift" + } + else -> null } + // Use default path from toolchain if we cannot get `bundlePath` for target. + // It may be the case for simulators if Xcode/macOS is old. + return simulatorPath ?: configs.absoluteTargetToolchain + "/usr/lib/swift/$swiftPlatform" } private fun buildEnvironment(): Map { diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/XcRunRuntimeUtils.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/XcRunRuntimeUtils.kt index e565735d156..2a18710b695 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/XcRunRuntimeUtils.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/XcRunRuntimeUtils.kt @@ -38,7 +38,7 @@ fun Xcode.getLatestSimulatorRuntimeFor(target: KonanTarget, osMinVersion: String else -> error("Unexpected simulator target: $target") } return getSimulatorRuntimeDescriptors().firstOrNull { - it.isAvailable && it.name.startsWith(osName) && compareStringsAsVersions(it.version, osMinVersion) >= 0 + it.checkAvailability() && it.name.startsWith(osName) && compareStringsAsVersions(it.version, osMinVersion) >= 0 } } @@ -51,9 +51,21 @@ data class ListRuntimesReport( @Serializable data class SimulatorRuntimeDescriptor( val version: String, - val bundlePath: String, - val isAvailable: Boolean, + // bundlePath field may not exist in the old Xcode (prior to 10.3). + val bundlePath: String? = null, + val isAvailable: Boolean? = null, + val availability: String? = null, val name: String, val identifier: String, val buildversion: String -) +) { + /** + * Different Xcode/macOS combinations give different fields that checks + * runtime availability. This method is an umbrella for these fields. + */ + fun checkAvailability(): Boolean { + if (isAvailable == true) return true + if (availability?.contains("unavailable") == true) return false + return false + } +}