From b487d677f9853db487adb5ab53f1b75f7490a8d7 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 2 Apr 2024 12:22:41 +0000 Subject: [PATCH] [K/N][tests] Don't attempt to download simulator after first failure Sometimes, e.g. due to a bug in Xcode, downloading a simulator runtime might fail. See e.g. 89589210 here: https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes In that case, it makes little sense to try downloading the same simulator runtime later again. Moreover, such attempts might lead to accumulating stale downloads in /Library/Developer/CoreSimulator/Images/Inbox/, wasting disk space. This commit caches the download result, so that if the first attempt fails, then the later attempts will just rethrow the same exception. ^KTI-1683 --- .../kotlin/native/executors/XcodeSimulatorExecutor.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/native/executors/src/main/kotlin/org/jetbrains/kotlin/native/executors/XcodeSimulatorExecutor.kt b/native/executors/src/main/kotlin/org/jetbrains/kotlin/native/executors/XcodeSimulatorExecutor.kt index 311f5c86dd552..8216698d74b92 100644 --- a/native/executors/src/main/kotlin/org/jetbrains/kotlin/native/executors/XcodeSimulatorExecutor.kt +++ b/native/executors/src/main/kotlin/org/jetbrains/kotlin/native/executors/XcodeSimulatorExecutor.kt @@ -135,7 +135,13 @@ class XcodeSimulatorExecutor( return checkNotNull(simulatorRuntimeOrNull()) { "Runtime is not available for the selected $deviceId. Check Xcode installation" } } - private fun downloadRuntimeFor(osName: String) { + private val downloadRuntimeResultByOsName = mutableMapOf>() + + private fun downloadRuntimeFor(osName: String) = downloadRuntimeResultByOsName.getOrPut(osName) { + runCatching { downloadRuntimeForImpl(osName) } + }.getOrThrow() + + private fun downloadRuntimeForImpl(osName: String) { val version = Xcode.findCurrent().version check(version.major >= 14) { "Was unable to get the required runtimes running on Xcode $version. Check the Xcode installation"