From 479e7a5169324d144fc7613cd3478b76093f4bd9 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Fri, 3 Sep 2021 12:55:58 +0700 Subject: [PATCH] [K/N] Fix KT-48566 by falling back to the old behavior In 1.5.20 HostManager.host started to check host architecture and it leads to regressing in case of os+arch combination that is not supported by HostManager. Before 1.5.20 HostManager.host was determined only by OS. It is not correct, but Gradle plugin uses HostManager even if there are no Native targets. We fallback to this behavior to workaround this regression. --- .../kotlin/konan/target/HostManager.kt | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt b/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt index 94a8e53632f..eef00f89a63 100644 --- a/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt +++ b/native/utils/src/org/jetbrains/kotlin/konan/target/HostManager.kt @@ -201,15 +201,18 @@ open class HostManager( fun host_arch(): String = hostArch() - fun hostArch(): String { - return when (val javaArch = System.getProperty("os.arch")) { + fun hostArch(): String = + hostArchOrNull() + ?: throw TargetSupportException("Unknown hardware platform: ${System.getProperty("os.arch")}") + + fun hostArchOrNull(): String? = + when (System.getProperty("os.arch")) { "x86_64" -> "x86_64" "amd64" -> "x86_64" "arm64" -> "aarch64" "aarch64" -> "aarch64" - else -> throw TargetSupportException("Unknown hardware platform: $javaArch") + else -> null } - } private val hostMapping: Map, KonanTarget> = mapOf( Pair("osx", "x86_64") to MACOS_X64, @@ -218,8 +221,20 @@ open class HostManager( Pair("windows", "x86_64") to MINGW_X64 ) - val host: KonanTarget = hostMapping[hostOs() to hostArch()] - ?: throw TargetSupportException("Unknown host target: ${hostOs()} ${hostArch()}") + val host: KonanTarget = determineHost(hostOs(), hostArchOrNull()) + + private fun determineHost(os: String, arch: String?): KonanTarget { + hostMapping[os to arch]?.let { + return it + } + // https://youtrack.jetbrains.com/issue/KT-48566. + // Workaround for unsupported host architectures. + // It is obviously incorrect, but makes Gradle plugin work. + hostMapping.entries.firstOrNull { (host, _) -> host.first == os }?.let { + return it.value + } + throw TargetSupportException("Unknown host target: $os $arch") + } // Note Hotspot-specific VM option enforcing C1-only, critical for decent compilation speed. val defaultJvmArgs = listOf("-XX:TieredStopAtLevel=1", "-ea", "-Dfile.encoding=UTF-8")