mirror of
https://github.com/apple/pkl.git
synced 2026-05-22 06:47:04 +02:00
Update Gradle to 8.11 (#800)
Changes: - Update wrapper by running the following command: ./gradlew wrapper --gradle-version 8.11 --gradle-distribution-sha256-sum 57dafb5c2622c6cc08b993c85b7c06956a2f53536432a30ead46166dbca0f1e9 - Verify wrapper JAR integrity according to: https://docs.gradle.org/current/userguide/gradle_wrapper.html# manually_verifying_the_gradle_wrapper_jar - Replace usages of deprecated method `Project.exec` with `ExecOperations.exec` - Convert extension function `Task.configureInstallGraalVm` to task class `InstallGraalVm` - a task class is the cleanest way to get hold of `ExecOperations` - Move extension property `BuildInfo.GraalVm.downloadFile` into class `GraalVm` - Don't apply plugin `pklGraalVm` in project `bench` (unnecessary, now causes error)
This commit is contained in:
@@ -15,20 +15,11 @@
|
||||
*/
|
||||
import de.undercouch.gradle.tasks.download.Download
|
||||
import de.undercouch.gradle.tasks.download.Verify
|
||||
import java.nio.file.*
|
||||
import java.util.UUID
|
||||
import kotlin.io.path.createDirectories
|
||||
|
||||
plugins { id("de.undercouch.download") }
|
||||
|
||||
val buildInfo = project.extensions.getByType<BuildInfo>()
|
||||
|
||||
val BuildInfo.GraalVm.downloadFile
|
||||
get(): File {
|
||||
val extension = if (buildInfo.os.isWindows) "zip" else "tar.gz"
|
||||
return file(homeDir).resolve("${baseName}.$extension")
|
||||
}
|
||||
|
||||
// tries to minimize chance of corruption by download-to-temp-file-and-move
|
||||
val downloadGraalVmAarch64 by
|
||||
tasks.registering(Download::class) { configureDownloadGraalVm(buildInfo.graalVmAarch64) }
|
||||
@@ -68,63 +59,16 @@ fun Verify.configureVerifyGraalVm(graalvm: BuildInfo.GraalVm) {
|
||||
algorithm("SHA-256")
|
||||
}
|
||||
|
||||
// minimize chance of corruption by extract-to-random-dir-and-flip-symlink
|
||||
@Suppress("unused")
|
||||
val installGraalVmAarch64 by
|
||||
tasks.registering {
|
||||
tasks.registering(InstallGraalVm::class) {
|
||||
dependsOn(verifyGraalVmAarch64)
|
||||
configureInstallGraalVm(buildInfo.graalVmAarch64)
|
||||
graalVm = buildInfo.graalVmAarch64
|
||||
}
|
||||
|
||||
// minimize chance of corruption by extract-to-random-dir-and-flip-symlink
|
||||
@Suppress("unused")
|
||||
val installGraalVmAmd64 by
|
||||
tasks.registering {
|
||||
tasks.registering(InstallGraalVm::class) {
|
||||
dependsOn(verifyGraalVmAmd64)
|
||||
configureInstallGraalVm(buildInfo.graalVmAmd64)
|
||||
graalVm = buildInfo.graalVmAmd64
|
||||
}
|
||||
|
||||
fun Task.configureInstallGraalVm(graalVm: BuildInfo.GraalVm) {
|
||||
onlyIf { !graalVm.installDir.exists() }
|
||||
|
||||
doLast {
|
||||
val distroDir = Paths.get(graalVm.homeDir, UUID.randomUUID().toString())
|
||||
|
||||
try {
|
||||
distroDir.createDirectories()
|
||||
println("Extracting ${graalVm.downloadFile} into $distroDir")
|
||||
// faster and more reliable than Gradle's `copy { from tarTree() }`
|
||||
exec {
|
||||
workingDir = file(distroDir)
|
||||
executable = "tar"
|
||||
args("--strip-components=1", "-xzf", graalVm.downloadFile)
|
||||
}
|
||||
|
||||
val distroBinDir =
|
||||
if (buildInfo.os.isMacOsX) distroDir.resolve("Contents/Home/bin")
|
||||
else distroDir.resolve("bin")
|
||||
|
||||
println("Installing native-image into $distroDir")
|
||||
exec {
|
||||
val executableName = if (buildInfo.os.isWindows) "gu.cmd" else "gu"
|
||||
executable = distroBinDir.resolve(executableName).toString()
|
||||
args("install", "--no-progress", "native-image")
|
||||
}
|
||||
|
||||
println("Creating symlink ${graalVm.installDir} for $distroDir")
|
||||
val tempLink = Paths.get(graalVm.homeDir, UUID.randomUUID().toString())
|
||||
Files.createSymbolicLink(tempLink, distroDir)
|
||||
try {
|
||||
Files.move(tempLink, graalVm.installDir.toPath(), StandardCopyOption.ATOMIC_MOVE)
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
delete(tempLink.toFile())
|
||||
} catch (ignored: Exception) {}
|
||||
throw e
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
delete(distroDir)
|
||||
} catch (ignored: Exception) {}
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user