[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.
This commit is contained in:
Sergey Bogolepov
2021-09-03 12:55:58 +07:00
committed by Space
parent bf62e98a1a
commit 479e7a5169
@@ -201,15 +201,18 @@ open class HostManager(
fun host_arch(): String = fun host_arch(): String =
hostArch() hostArch()
fun hostArch(): String { fun hostArch(): String =
return when (val javaArch = System.getProperty("os.arch")) { hostArchOrNull()
?: throw TargetSupportException("Unknown hardware platform: ${System.getProperty("os.arch")}")
fun hostArchOrNull(): String? =
when (System.getProperty("os.arch")) {
"x86_64" -> "x86_64" "x86_64" -> "x86_64"
"amd64" -> "x86_64" "amd64" -> "x86_64"
"arm64" -> "aarch64" "arm64" -> "aarch64"
"aarch64" -> "aarch64" "aarch64" -> "aarch64"
else -> throw TargetSupportException("Unknown hardware platform: $javaArch") else -> null
} }
}
private val hostMapping: Map<Pair<String, String>, KonanTarget> = mapOf( private val hostMapping: Map<Pair<String, String>, KonanTarget> = mapOf(
Pair("osx", "x86_64") to MACOS_X64, Pair("osx", "x86_64") to MACOS_X64,
@@ -218,8 +221,20 @@ open class HostManager(
Pair("windows", "x86_64") to MINGW_X64 Pair("windows", "x86_64") to MINGW_X64
) )
val host: KonanTarget = hostMapping[hostOs() to hostArch()] val host: KonanTarget = determineHost(hostOs(), hostArchOrNull())
?: throw TargetSupportException("Unknown host target: ${hostOs()} ${hostArch()}")
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. // Note Hotspot-specific VM option enforcing C1-only, critical for decent compilation speed.
val defaultJvmArgs = listOf("-XX:TieredStopAtLevel=1", "-ea", "-Dfile.encoding=UTF-8") val defaultJvmArgs = listOf("-XX:TieredStopAtLevel=1", "-ea", "-Dfile.encoding=UTF-8")