Make checking Xcode version faster.

xcodebuild -version call may take enormous amount of time even after warmup. To alleviate this, first try to check Xcode version directly by reading application .plist file, but still use xcodebuild -version as a fallback.

Merge-request: KT-MR-7694
Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
This commit is contained in:
Gleb Lukianets
2022-12-06 15:52:13 +00:00
committed by Space Team
parent 4adb367a25
commit e9984ce38d
3 changed files with 63 additions and 3 deletions
+5
View File
@@ -48,6 +48,10 @@ tasks.jar {
archiveFileName.set("shared.jar")
}
projectTest(jUnitMode = JUnitMode.JUnit5) {
useJUnitPlatform()
}
dependencies {
kotlinCompilerClasspath("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
@@ -55,4 +59,5 @@ dependencies {
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
api("org.jetbrains.kotlin:kotlin-native-utils:$kotlinVersion")
api("org.jetbrains.kotlin:kotlin-util-klib:$kotlinVersion")
testApiJUnit5()
}
@@ -64,7 +64,7 @@ interface Xcode {
}
}
private class CurrentXcode : Xcode {
internal class CurrentXcode : Xcode {
override val toolchain by lazy {
val ldPath = xcrun("-f", "ld") // = $toolchain/usr/bin/ld
@@ -87,10 +87,19 @@ private class CurrentXcode : Xcode {
override val watchosSdk: String by lazy { getSdkPath("watchos") }
override val watchsimulatorSdk: String by lazy { getSdkPath("watchsimulator") }
internal val xcodebuildVersion: String
get() = xcrun("xcodebuild", "-version")
.removePrefix("Xcode ")
internal val bundleVersion: String
get() = bash("""/usr/libexec/PlistBuddy "$(xcode-select -print-path)/../Info.plist" -c "Print :CFBundleShortVersionString"""")
override val version by lazy {
xcrun("xcodebuild", "-version")
.removePrefix("Xcode ")
try {
bundleVersion
} catch (e: KonanExternalToolFailure) {
xcodebuildVersion
}
}
private fun xcrun(vararg args: String): String = try {
@@ -107,5 +116,7 @@ private class CurrentXcode : Xcode {
throw MissingXcodeException(message, e)
}
private fun bash(command: String): String = Command("/bin/bash", "-c", command).getOutputLines().joinToString("\n")
private fun getSdkPath(sdk: String) = xcrun("--sdk", sdk, "--show-sdk-path")
}
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.konan.target
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Assumptions.assumeTrue
internal class CurrentXcodeTest {
companion object {
@BeforeAll
@JvmStatic
fun assumeMacOS() {
assumeTrue(HostManager.hostIsMac)
}
}
@Test
fun `Should be able to access Xcode bundle version`() {
val version = CurrentXcode().bundleVersion
assertNotEquals("", version)
}
@Test
fun `Should be able to access xcodebuild version`() {
val version = CurrentXcode().xcodebuildVersion
assertNotEquals("", version)
}
@Test
fun `Xcode bundle version version should match xcodebuild version`() {
val xcode = CurrentXcode()
val xcodebuildVersion = xcode.xcodebuildVersion
val bundleVersion = xcode.bundleVersion
val version = xcode.version
assertEquals(xcodebuildVersion, bundleVersion)
assertEquals(xcodebuildVersion, version)
}
}