-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
72 additions
and
32 deletions.
There are no files selected for viewing
70 changes: 41 additions & 29 deletions
70
...gin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/binaryen/BinaryenPlatform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,55 @@ | ||
package org.jetbrains.kotlin.gradle.targets.js.binaryen | ||
|
||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly | ||
import org.gradle.api.provider.Provider | ||
|
||
/** | ||
* Provides platform and architecture names that is used to download Binaryen. | ||
*/ | ||
internal object BinaryenPlatform { | ||
private val props = System.getProperties() | ||
private fun property(name: String) = props.getProperty(name) ?: System.getProperty(name) | ||
|
||
const val WIN = "windows" | ||
const val LINUX = "linux" | ||
const val DARWIN = "macos" | ||
|
||
val name: String = run { | ||
val name = property("os.name").toLowerCaseAsciiOnly() | ||
when { | ||
name.contains("windows") -> WIN | ||
name.contains("mac") -> DARWIN | ||
name.contains("linux") -> LINUX | ||
name.contains("freebsd") -> LINUX | ||
else -> throw IllegalArgumentException("Unsupported OS: $name") | ||
} | ||
internal data class BinaryenPlatform( | ||
val name: String, | ||
val arch: String, | ||
) { | ||
val platform: String | ||
get() = "$arch-$name" | ||
|
||
fun isWindows(): Boolean { | ||
return name == WIN | ||
} | ||
|
||
const val ARM64 = "arm64" | ||
const val X64 = "x86_64" | ||
const val X86 = "x86_86" | ||
companion object { | ||
const val WIN = "windows" | ||
const val LINUX = "linux" | ||
const val DARWIN = "macos" | ||
|
||
const val X64 = "x86_64" | ||
const val X86 = "x86_86" | ||
|
||
val architecture: String | ||
get() { | ||
val arch = property("os.arch") | ||
internal fun parseBinaryenPlatform(name: String, arch: String, uname: Provider<String>): BinaryenPlatform { | ||
return BinaryenPlatform( | ||
parseOsName(name.toLowerCase()), | ||
parseOsArch( | ||
arch.toLowerCase(), | ||
uname | ||
) | ||
) | ||
} | ||
|
||
private fun parseOsName(name: String): String { | ||
return when { | ||
arch == "aarch64" -> ARM64 | ||
name.contains("windows") -> WIN | ||
name.contains("mac") -> DARWIN | ||
name.contains("linux") -> LINUX | ||
name.contains("freebsd") -> LINUX | ||
else -> throw IllegalArgumentException("Unsupported OS: $name") | ||
} | ||
} | ||
|
||
private fun parseOsArch(arch: String, uname: Provider<String>): String { | ||
return when { | ||
arch == "arm" || arch.startsWith("aarch") -> uname.get() | ||
arch.contains("64") -> X64 | ||
else -> X86 | ||
} | ||
} | ||
|
||
val platform: String | ||
get() = "$architecture-$name" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters