Skip to content

Commit

Permalink
fixing m2 compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Murdock authored and Robert Murdock committed Jul 7, 2023
1 parent acc7361 commit 429d534
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 54 deletions.
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
import java.io.File
import java.io.FileOutputStream

Expand Down Expand Up @@ -63,61 +64,11 @@ open class NodeExec : AbstractExecTask<NodeExec>(NodeExec::class.java) {
}

fun NodeExec.setup(project: Project) {
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
nodeBinDir = nodeJs.requireConfigured().nodeBinDir
nodeExecPath = nodeJs.requireConfigured().nodeExecutable
projectNodeModulesDir = project.nodeModulesDir
nodeBinDir = project.nodeBinDir
nodeExecPath = project.nodeExecPath
}

private fun Project.goGetNodeBinDir(): File {
val props = System.getProperties()
fun property(name: String) = props.getProperty(name) ?: System.getProperty(name)
val win = "win"
val darwin = "darwin"
val linux = "linux"
val sunos = "sunos"

val platform: String = run {
val name = property("os.name").lowercase()
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")
}
}
val x64 = "x64"
val x86 = "x86"
val arm64 = "arm64"

val architecture: String = run {
val arch = property("os.arch").lowercase()
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
}
}
val nodeJs = NodeJsRootPlugin.apply(this)
val installationDir = nodeJs.installationDir
val nodeDir = installationDir.resolve("node-v${nodeJs.nodeVersion}-$platform-$architecture")

val isWindows = platform == win
return if (isWindows) nodeDir else nodeDir.resolve("bin")
}

val Project.nodeModulesDir get() = rootProject.buildDir.resolve("js/node_modules")

private val Project.nodeExecPath get() = "$nodeBinDir/node"

private val Project.nodeBinDir get() = project.rootProject.goGetNodeBinDir()

0 comments on commit 429d534

Please sign in to comment.