From 5afbbecea4ed78c55f0329fb94964fcfa92d3bca Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 11 Feb 2022 16:30:25 +0300 Subject: [PATCH] Native: rename Xcode.current to .findCurrent() To reflect that it is a non-trivial operation with possible performance overhead. --- .../src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt | 4 ++-- .../src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt | 6 ++++-- .../src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt | 2 +- .../main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt | 2 +- .../main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt | 5 ++++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt index ab984d0c3ef..46f4795fa3b 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt @@ -259,7 +259,7 @@ private fun simulator(project: Project): ExecutorService = object : ExecutorServ } private val simctl by lazy { - val sdk = Xcode.current.pathToPlatformSdk(configurables.platformName()) + val sdk = Xcode.findCurrent().pathToPlatformSdk(configurables.platformName()) val out = ByteArrayOutputStream() val result = project.exec { commandLine("/usr/bin/xcrun", "--find", "simctl", "--sdk", sdk) @@ -638,7 +638,7 @@ fun KonanTestExecutable.configureXcodeBuild() { } val sdk = when (project.testTarget) { - KonanTarget.IOS_ARM32, KonanTarget.IOS_ARM64 -> Xcode.current.iphoneosSdk + KonanTarget.IOS_ARM32, KonanTarget.IOS_ARM64 -> Xcode.findCurrent().iphoneosSdk else -> error("Unsupported target: ${project.testTarget}") } diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt index cb64e7f80a4..08feb8730b9 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt @@ -200,7 +200,7 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable { val configs = project.testTargetConfigurables as AppleConfigurables val swiftPlatform = configs.platformName().toLowerCase() val simulatorPath = when (configs.targetTriple.isSimulator) { - true -> Xcode.current.getLatestSimulatorRuntimeFor(configs.target.family, configs.osVersionMin) + true -> xcode.getLatestSimulatorRuntimeFor(configs.target.family, configs.osVersionMin) ?.bundlePath ?.let { "$it/Contents/Resources/RuntimeRoot/usr/lib/swift" } else -> null @@ -255,7 +255,7 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable { if (configurables.targetTriple.isSimulator) { return // bitcode-build-tool doesn't support simulators. } - val sdk = Xcode.current.pathToPlatformSdk(configurables.platformName()) + val sdk = xcode.pathToPlatformSdk(configurables.platformName()) val python3 = listOf("/usr/bin/python3", "/usr/local/bin/python3") .map { Paths.get(it) }.firstOrNull { Files.exists(it) } @@ -264,4 +264,6 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable { runTest(executorService = localExecutorService(project), testExecutable = python3, args = listOf("-B", bitcodeBuildTool, "--sdk", sdk, "-v", "-t", toolPath, frameworkBinary)) } + + private val xcode by lazy { Xcode.findCurrent() } } \ No newline at end of file diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt index 7d8a43decba..96809fba532 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/PlatformInfo.kt @@ -56,7 +56,7 @@ object PlatformInfo { && properties.checkXcodeVersion && requiredMajorVersion != null ) { - val currentXcodeVersion = Xcode.current.version + val currentXcodeVersion = Xcode.findCurrent().version val currentMajorVersion = currentXcodeVersion.splitToSequence('.').first() if (currentMajorVersion != requiredMajorVersion) { throw IllegalStateException( diff --git a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt index 5ff6f838ad1..b4e883dfe58 100644 --- a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt +++ b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt @@ -55,7 +55,7 @@ class AppleConfigurablesImpl( if (InternalServer.isAvailable) { XcodePartsProvider.InternalServer } else { - val xcode = Xcode.current + val xcode = Xcode.findCurrent() if (properties.getProperty("ignoreXcodeVersionCheck") != "true") { properties.getProperty("minimalXcodeVersion")?.let { minimalXcodeVersion -> diff --git a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt index 320ba1909d9..fd834c90279 100644 --- a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt +++ b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt @@ -56,8 +56,11 @@ interface Xcode { companion object { // Don't cache the instance: the compiler might be executed in a Gradle daemon process, // so current Xcode might actually change between different invocations. + @Deprecated("", ReplaceWith("this.findCurrent()"), DeprecationLevel.WARNING) val current: Xcode - get() = CurrentXcode() + get() = findCurrent() + + fun findCurrent(): Xcode = CurrentXcode() } }