From 7c3e0bb8012c01823214340d8d52a9174a8e73c4 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 22 Oct 2019 19:00:41 +0300 Subject: [PATCH] Add Xcode version check --- konan/konan.properties | 4 +-- .../jetbrains/kotlin/konan/target/Apple.kt | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/konan/konan.properties b/konan/konan.properties index 8e015fb46d8..34882bf1972 100644 --- a/konan/konan.properties +++ b/konan/konan.properties @@ -25,8 +25,8 @@ dependencyProfiles = default alt airplaneMode = false # if true, ignores Xcode version check. ignoreXcodeVersionCheck = false -# Disabled until decided better mechanism. -# useFixedXcodeVersion = 11.0 + +minimalXcodeVersion=11.0 downloadingAttempts = 10 downloadingAttemptIntervalMs = 3000 diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt index ceb72c911e0..91635d8a740 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.konan.target import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader import org.jetbrains.kotlin.konan.properties.Properties import org.jetbrains.kotlin.konan.util.InternalServer +import kotlin.math.max class AppleConfigurablesImpl( target: KonanTarget, @@ -63,19 +64,36 @@ class AppleConfigurablesImpl( XcodePartsProvider.InternalServer } else { val xcode = Xcode.current - properties.getProperty("useFixedXcodeVersion")?.let { requiredXcodeVersion -> - val currentXcodeVersion = xcode.version - if (properties.getProperty("ignoreXcodeVersionCheck") != "true" && - currentXcodeVersion != requiredXcodeVersion) { - error("expected Xcode version $requiredXcodeVersion, got $currentXcodeVersion, consider updating " + - "Xcode or use \"ignoreXcodeVersionCheck\" variable in konan.properties") + if (properties.getProperty("ignoreXcodeVersionCheck") != "true") { + properties.getProperty("minimalXcodeVersion")?.let { minimalXcodeVersion -> + val currentXcodeVersion = xcode.version + checkXcodeVersion(minimalXcodeVersion, currentXcodeVersion) } } XcodePartsProvider.Local(xcode) } + private fun checkXcodeVersion(minimalVersion: String, currentVersion: String) { + // Xcode versions contain only numbers (even betas). + // But we still split by '-' and whitespaces to take into account versions like 11.2-beta. + val minimalVersionParts = minimalVersion.split("(\\s+|\\.|-)".toRegex()).map { it.toIntOrNull() ?: 0 } + val currentVersionParts = currentVersion.split("(\\s+|\\.|-)".toRegex()).map { it.toIntOrNull() ?: 0 } + val size = max(minimalVersionParts.size, currentVersionParts.size) + + for (i in 0 until size) { + val currentPart = currentVersionParts.getOrElse(i) { 0 } + val minimalPart = minimalVersionParts.getOrElse(i) { 0 } + + when { + currentPart > minimalPart -> return + currentPart < minimalPart -> + error("Unsupported Xcode version $currentVersion, minimal supported version is $minimalVersion.") + } + } + } + private sealed class XcodePartsProvider { class Local(val xcode: Xcode) : XcodePartsProvider() object InternalServer : XcodePartsProvider()