Skip to content

Commit

Permalink
make download task not rely on an outdated gradle plugin.
Browse files Browse the repository at this point in the history
update kotlin version definition to be compatible with Godot kotlin/jvm for godot 4.
make the kotlin module rely on the jvm from the project's toolchain.
  • Loading branch information
Frontrider committed Oct 30, 2023
1 parent 4ccd10a commit af85e3c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "io.github.frontrider.godle"
version = "0.21.13"
version = "0.21.15"

repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/Godle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class Godle : Plugin<Project> {

project.initBaseGodot()
project.ignores()

}
}
1 change: 1 addition & 0 deletions src/main/kotlin/dsl/versioning/GodotVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data class GodotVersion(

val downloadTask: (GodotDownload) -> Unit = {},
val execTask: (ExecSpec) -> Unit = {},
val isJava:Boolean = false,
val majorVersion: MajorVersion = versionAsGodot3(),
val bindingName:String = "extension_api.json",
val headerName:String = "gdextension_interface.h",
Expand Down
37 changes: 37 additions & 0 deletions src/main/kotlin/dsl/versioning/jvm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.frontrider.godle.dsl.versioning

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.process.ExecSpec

fun setupJVM(detectJVM: Boolean = true, exec:ExecSpec) {
//the exec task detects the current JVM
if (detectJVM) {
if (jvmPath != null) {
exec.environment("JAVA_HOME", jvmPath!!)
return
}
println("attempting to detect jvm!")

//attempt to determine the current JVM's path and use it.
val command = ProcessHandle.current()
.info()
.command()

if (command.isPresent) {
val javaHome = command.get().removeSuffix("/bin/java")
println("jvm found at $javaHome")
//determine from the process itself, this is the most secure variant
exec.environment("JAVA_HOME", javaHome)
jvmPath = javaHome
} else {
//determine from an environment variable, will most likely be set, but it may not be the correct one.
val javaHome = System.getProperty("java.home")
if (javaHome != null) {
println("jvm found at $javaHome")
exec.environment("JAVA_HOME", javaHome)
jvmPath = javaHome
}
}
}
}
32 changes: 1 addition & 31 deletions src/main/kotlin/dsl/versioning/kotlin3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,7 @@ fun GodleExtension.`kotlin-jvm3`(version: String, detectJVM: Boolean = true): Go
linuxBinary = "godot.x11.opt.tools.%bit%",
windowsBinary = "godot.windows.opt.tools.%bit%.exe",
macBinary = "godot.osx.opt.tools.%bit%",
execTask = { exec ->
//the exec task detects the current JVM
if (detectJVM) {
if(jvmPath != null){
exec.environment("JAVA_HOME", jvmPath!!)
return@GodotVersion
}
println("attempting to detect jvm!")

//attempt to determine the current JVM's path and use it.
val command = ProcessHandle.current()
.info()
.command()

if (command.isPresent) {
val javaHome = command.get().removeSuffix("/bin/java")
println("jvm found at $javaHome")
//determine from the process itself, this is the most secure variant
exec.environment("JAVA_HOME", javaHome)
jvmPath= javaHome
} else {
//determine from an environment variable, will most likely be set, but it may not be the correct one.
val javaHome = System.getProperty("java.home")
if (javaHome != null) {
println("jvm found at $javaHome")
exec.environment("JAVA_HOME", javaHome)
jvmPath= javaHome
}
}
}
}
isJava = true
)
}

Expand Down
32 changes: 1 addition & 31 deletions src/main/kotlin/dsl/versioning/kotlin4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,7 @@ fun GodleExtension.`kotlin-jvm4`(version: String, detectJVM: Boolean = true): Go
linuxBinary = "godot.linuxbsd.editor.x86_%bit%",
windowsBinary = "godot.windows.editor.x86_%bit%.exe",
macBinary = "Godot",
execTask = { exec ->
//the exec task detects the current JVM
if (detectJVM) {
if(jvmPath != null){
exec.environment("JAVA_HOME", jvmPath!!)
return@GodotVersion
}
println("attempting to detect jvm!")

//attempt to determine the current JVM's path and use it.
val command = ProcessHandle.current()
.info()
.command()

if (command.isPresent) {
val javaHome = command.get().removeSuffix("/bin/java")
println("jvm found at $javaHome")
//determine from the process itself, this is the most secure variant
exec.environment("JAVA_HOME", javaHome)
jvmPath= javaHome
} else {
//determine from an environment variable, will most likely be set, but it may not be the correct one.
val javaHome = System.getProperty("java.home")
if (javaHome != null) {
println("jvm found at $javaHome")
exec.environment("JAVA_HOME", javaHome)
jvmPath= javaHome
}
}
}
}
isJava = true
)
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/tasks/exec/GodotExec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package io.github.frontrider.godle.tasks.exec

import io.github.frontrider.godle.dsl.GodleExtension
import io.github.frontrider.godle.initGodotExec
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Input
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.jvm.toolchain.internal.JavaToolchain

/**
* Executes the current godot binary, with given arguments.
Expand All @@ -18,10 +21,17 @@ open class GodotExec : Exec() {
initGodotExec(project, this)

val extension = project.extensions.getByType(GodleExtension::class.java)
val version = extension.version.get().majorVersion
val version = extension.version.get()

if (version.isJava) {
val javaPluginExtension = project.extensions.getByType(JavaPluginExtension::class.java)
val toolchain = project.extensions.getByType(JavaToolchainService::class.java).compilerFor(javaPluginExtension.toolchain).get()
val jvmPath = toolchain.metadata.installationPath
environment("JAVA_HOME",jvmPath.asFile.absolutePath)
}

if (debug) {
args(version.debugFlag)
args(version.majorVersion.debugFlag)
}
}
}

0 comments on commit af85e3c

Please sign in to comment.