All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlatform.kt Maven / Gradle / Ivy

There is a newer version: 2.0.20-RC
Show newest version
package org.jetbrains.kotlin.gradle.targets.js.nodejs

/**
 * Provides platform and architecture names that is used to download NodeJs.
 * See [NodeJsEnv.ivyDependency] that is filled in [NodeJsRootExtension.environment].
 */
internal object NodeJsPlatform {
    private val props = System.getProperties()
    private fun property(name: String) = props.getProperty(name) ?: System.getProperty(name)

    const val WIN = "win"
    const val DARWIN = "darwin"
    const val LINUX = "linux"
    const val SUNOS = "sunos"

    val name: String = run {
        val name = property("os.name").toLowerCase()
        when {
            name.contains("windows") -> WIN
            name.contains("mac") -> DARWIN
            name.contains("linux") -> LINUX
            name.contains("freebsd") -> LINUX
            name.contains("sunos") -> SUNOS
            else -> throw IllegalArgumentException("Unsupported OS: $name")
        }
    }

    const val X64 = "x64"
    const val X86 = "x86"
    const val ARM64 = "arm64"

    val architecture: String = run {
        val arch = property("os.arch").toLowerCase()
        when {
            arch.contains("64") -> X64
            arch == "arm" -> {
                // as Java just returns "arm" on all ARM variants, we need a system call to determine the exact arch
                // the node binaries for 'armv8l' are called 'arm64', so we need to distinguish here
                val process = Runtime.getRuntime().exec("uname -m")
                val systemArch = process.inputStream.bufferedReader().use { it.readText() }
                when (systemArch.trim()) {
                    "armv8l" -> ARM64
                    else -> systemArch
                }
            }
            else -> X86
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy