mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Use layout.buildDirectory (#326)
This switches Gradle scripts to use `layout.buildDirectory` instead of hard-coded "build".
This commit is contained in:
@@ -41,7 +41,7 @@ idea {
|
||||
}
|
||||
|
||||
val clean by tasks.registering(Delete::class) {
|
||||
delete("build")
|
||||
delete(layout.buildDirectory)
|
||||
}
|
||||
|
||||
val printVersion by tasks.registering {
|
||||
|
||||
@@ -105,7 +105,7 @@ tasks.check {
|
||||
}
|
||||
|
||||
val validateFatJar by tasks.registering {
|
||||
val outputFile = file("build/validateFatJar/result.txt")
|
||||
val outputFile = layout.buildDirectory.file("validateFatJar/result.txt")
|
||||
inputs.files(tasks.shadowJar)
|
||||
inputs.property("nonRelocations", nonRelocations)
|
||||
outputs.file(outputFile)
|
||||
@@ -125,9 +125,9 @@ val validateFatJar by tasks.registering {
|
||||
}
|
||||
}
|
||||
if (unshadowedFiles.isEmpty()) {
|
||||
outputFile.writeText("SUCCESS")
|
||||
outputFile.get().asFile.writeText("SUCCESS")
|
||||
} else {
|
||||
outputFile.writeText("FAILURE")
|
||||
outputFile.get().asFile.writeText("FAILURE")
|
||||
throw GradleException("Found unshadowed files:\n" + unshadowedFiles.joinToString("\n"))
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ tasks.check {
|
||||
|
||||
val resolveSourcesJars by tasks.registering(ResolveSourcesJars::class) {
|
||||
configuration.set(configurations.runtimeClasspath)
|
||||
outputDir.set(project.file("build/resolveSourcesJars"))
|
||||
outputDir.set(layout.buildDirectory.dir("resolveSourcesJars"))
|
||||
}
|
||||
|
||||
val fatSourcesJar by tasks.registering(MergeSourcesJars::class) {
|
||||
|
||||
@@ -33,7 +33,7 @@ dependencies {
|
||||
}
|
||||
|
||||
val validateHtml by tasks.registering(JavaExec::class) {
|
||||
val resultFile = file("build/validateHtml/result.txt")
|
||||
val resultFile = layout.buildDirectory.file("validateHtml/result.txt")
|
||||
inputs.files(htmlValidator.sources)
|
||||
outputs.file(resultFile)
|
||||
|
||||
@@ -50,7 +50,7 @@ val validateHtml by tasks.registering(JavaExec::class) {
|
||||
// write a basic result file s.t. gradle can consider task up-to-date
|
||||
// writing a result file in case validation fails is not easily possible with JavaExec, but also not strictly necessary
|
||||
doFirst { project.delete(resultFile) }
|
||||
doLast { resultFile.writeText("Success.") }
|
||||
doLast { resultFile.get().asFile.writeText("Success.") }
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
|
||||
@@ -55,7 +55,7 @@ val workAroundKotlinGradlePluginBug by tasks.registering {
|
||||
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type 'JavaCompile').
|
||||
// > Directory '[...]/pkl/pkl-executor/build/classes/kotlin/main'
|
||||
// specified for property 'compileKotlinOutputClasses' does not exist.
|
||||
file("build/classes/kotlin/main").mkdirs()
|
||||
layout.buildDirectory.dir("classes/kotlin/main").get().asFile.mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,14 +54,14 @@ val validatePom by tasks.registering {
|
||||
return@registering
|
||||
}
|
||||
val generatePomFileForLibraryPublication by tasks.existing(GenerateMavenPom::class)
|
||||
val outputFile = file("build/validatePom") // dummy output to satisfy up-to-date check
|
||||
val outputFile = layout.buildDirectory.file("validatePom") // dummy output to satisfy up-to-date check
|
||||
|
||||
dependsOn(generatePomFileForLibraryPublication)
|
||||
inputs.file(generatePomFileForLibraryPublication.get().destination)
|
||||
outputs.file(outputFile)
|
||||
|
||||
doLast {
|
||||
outputFile.delete()
|
||||
outputFile.get().asFile.delete()
|
||||
|
||||
val pomFile = generatePomFileForLibraryPublication.get().destination
|
||||
assert(pomFile.exists())
|
||||
@@ -95,7 +95,7 @@ val validatePom by tasks.registering {
|
||||
}
|
||||
}
|
||||
|
||||
outputFile.writeText("OK")
|
||||
outputFile.get().asFile.writeText("OK")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,13 @@ dependencies {
|
||||
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
|
||||
stagedMacAmd64Executable(files("build/executable/pkl-macos-amd64"))
|
||||
stagedMacAarch64Executable(files("build/executable/pkl-macos-aarch64"))
|
||||
stagedLinuxAmd64Executable(files("build/executable/pkl-linux-amd64"))
|
||||
stagedLinuxAarch64Executable(files("build/executable/pkl-linux-aarch64"))
|
||||
stagedAlpineLinuxAmd64Executable(files("build/executable/pkl-alpine-linux-amd64"))
|
||||
fun executableDir(name: String) = files(layout.buildDirectory.dir("executable/$name"))
|
||||
stagedMacAmd64Executable(executableDir("pkl-macos-amd64"))
|
||||
stagedMacAmd64Executable(executableDir("pkl-macos-amd64"))
|
||||
stagedMacAarch64Executable(executableDir("pkl-macos-aarch64"))
|
||||
stagedLinuxAmd64Executable(executableDir("pkl-linux-amd64"))
|
||||
stagedLinuxAarch64Executable(executableDir("pkl-linux-aarch64"))
|
||||
stagedAlpineLinuxAmd64Executable(executableDir("pkl-alpine-linux-amd64"))
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
@@ -90,7 +92,7 @@ tasks.shadowJar {
|
||||
|
||||
val javaExecutable by tasks.registering(ExecutableJar::class) {
|
||||
inJar.set(tasks.shadowJar.flatMap { it.archiveFile })
|
||||
outJar.set(file("build/executable/jpkl"))
|
||||
outJar.set(layout.buildDirectory.file("executable/jpkl"))
|
||||
|
||||
// uncomment for debugging
|
||||
//jvmArgs.addAll("-ea", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
|
||||
@@ -117,22 +119,22 @@ tasks.check {
|
||||
// To catch this and similar problems, test that Java executable starts successfully.
|
||||
val testStartJavaExecutable by tasks.registering(Exec::class) {
|
||||
dependsOn(javaExecutable)
|
||||
val outputFile = file("build/testStartJavaExecutable") // dummy output to satisfy up-to-date check
|
||||
val outputFile = layout.buildDirectory.file("testStartJavaExecutable") // dummy output to satisfy up-to-date check
|
||||
outputs.file(outputFile)
|
||||
|
||||
executable = javaExecutable.get().outputs.files.singleFile.toString()
|
||||
args("--version")
|
||||
|
||||
doFirst { outputFile.delete() }
|
||||
doFirst { outputFile.get().asFile.delete() }
|
||||
|
||||
doLast { outputFile.writeText("OK") }
|
||||
doLast { outputFile.get().asFile.writeText("OK") }
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(testStartJavaExecutable)
|
||||
}
|
||||
|
||||
fun Exec.configureExecutable(isEnabled: Boolean, outputFile: File, extraArgs: List<String> = listOf()) {
|
||||
fun Exec.configureExecutable(isEnabled: Boolean, outputFile: Provider<RegularFile>, extraArgs: List<String> = listOf()) {
|
||||
enabled = isEnabled
|
||||
dependsOn(":installGraalVm")
|
||||
|
||||
@@ -140,7 +142,7 @@ fun Exec.configureExecutable(isEnabled: Boolean, outputFile: File, extraArgs: Li
|
||||
inputs.files(configurations.runtimeClasspath)
|
||||
outputs.file(outputFile)
|
||||
|
||||
workingDir = outputFile.parentFile
|
||||
workingDir(outputFile.map { it.asFile.parentFile })
|
||||
executable = "${buildInfo.graalVm.baseDir}/bin/native-image"
|
||||
|
||||
// JARs to exclude from the class path for the native-image build.
|
||||
@@ -161,7 +163,7 @@ fun Exec.configureExecutable(isEnabled: Boolean, outputFile: File, extraArgs: Li
|
||||
,"-H:IncludeResourceBundles=org.pkl.core.errorMessages"
|
||||
,"--macro:truffle"
|
||||
,"-H:Class=org.pkl.cli.Main"
|
||||
,"-H:Name=${outputFile.name}"
|
||||
,"-H:Name=${outputFile.get().asFile.name}"
|
||||
//,"--native-image-info"
|
||||
//,"-Dpolyglot.image-build-time.PreinitializeContexts=pkl"
|
||||
// the actual limit (currently) used by native-image is this number + 1400 (idea is to compensate for Truffle's own nodes)
|
||||
@@ -209,7 +211,7 @@ fun Exec.configureExecutable(isEnabled: Boolean, outputFile: File, extraArgs: Li
|
||||
* Builds the pkl CLI for macOS/amd64.
|
||||
*/
|
||||
val macExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
configureExecutable(buildInfo.os.isMacOsX && buildInfo.graalVm.isGraal22, file("build/executable/pkl-macos-amd64"))
|
||||
configureExecutable(buildInfo.os.isMacOsX && buildInfo.graalVm.isGraal22, layout.buildDirectory.file("executable/pkl-macos-amd64"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,7 +223,7 @@ val macExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
val macExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
configureExecutable(
|
||||
buildInfo.os.isMacOsX && !buildInfo.graalVm.isGraal22,
|
||||
file("build/executable/pkl-macos-aarch64"),
|
||||
layout.buildDirectory.file("executable/pkl-macos-aarch64"),
|
||||
listOf(
|
||||
"--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess",
|
||||
"-H:+AllowDeprecatedBuilderClassesOnImageClasspath"
|
||||
@@ -233,7 +235,7 @@ val macExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
* Builds the pkl CLI for linux/amd64.
|
||||
*/
|
||||
val linuxExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
configureExecutable(buildInfo.os.isLinux && buildInfo.arch == "amd64", file("build/executable/pkl-linux-amd64"))
|
||||
configureExecutable(buildInfo.os.isLinux && buildInfo.arch == "amd64", layout.buildDirectory.file("executable/pkl-linux-amd64"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +245,7 @@ val linuxExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
* ARM instances.
|
||||
*/
|
||||
val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
configureExecutable(buildInfo.os.isLinux && buildInfo.arch == "aarch64", file("build/executable/pkl-linux-aarch64"))
|
||||
configureExecutable(buildInfo.os.isLinux && buildInfo.arch == "aarch64", layout.buildDirectory.file("executable/pkl-linux-aarch64"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +257,7 @@ val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class)
|
||||
val alpineExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
configureExecutable(
|
||||
buildInfo.os.isLinux && buildInfo.arch == "amd64" && buildInfo.hasMuslToolchain,
|
||||
file("build/executable/pkl-alpine-linux-amd64"),
|
||||
layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
|
||||
listOf(
|
||||
"--static",
|
||||
"--libc=musl",
|
||||
|
||||
@@ -32,11 +32,11 @@ tasks.processResources {
|
||||
|
||||
for (packageDir in file("src/main/files/packages").listFiles()!!) {
|
||||
if (!packageDir.isDirectory) continue
|
||||
val destinationDir = file("build/test-packages/${packageDir.name}")
|
||||
val destinationDir = layout.buildDirectory.dir("test-packages/${packageDir.name}")
|
||||
val metadataJson = file("$packageDir/${packageDir.name}.json")
|
||||
val packageContents = packageDir.resolve("package")
|
||||
val zipFileName = "${packageDir.name}.zip"
|
||||
val archiveFile = destinationDir.resolve(zipFileName)
|
||||
val archiveFile = destinationDir.map { it.file(zipFileName) }
|
||||
|
||||
val zipTask = tasks.register("zip-${packageDir.name}", Zip::class) {
|
||||
destinationDirectory.set(destinationDir)
|
||||
@@ -51,14 +51,14 @@ for (packageDir in file("src/main/files/packages").listFiles()!!) {
|
||||
dependsOn(zipTask)
|
||||
from(metadataJson)
|
||||
into(destinationDir)
|
||||
val shasumFile = file("$destinationDir/${packageDir.name}.json.sha256")
|
||||
val shasumFile = destinationDir.map { it.file("${packageDir.name}.json.sha256") }
|
||||
outputs.file(shasumFile)
|
||||
filter { line ->
|
||||
line.replaceFirst("\$computedChecksum", archiveFile.computeChecksum())
|
||||
line.replaceFirst("\$computedChecksum", archiveFile.get().asFile.computeChecksum())
|
||||
}
|
||||
doLast {
|
||||
val outputFile = destinationDir.resolve("${packageDir.name}.json")
|
||||
shasumFile.writeText(outputFile.computeChecksum())
|
||||
val outputFile = destinationDir.get().asFile.resolve("${packageDir.name}.json")
|
||||
shasumFile.get().asFile.writeText(outputFile.computeChecksum())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ for (packageDir in file("src/main/files/packages").listFiles()!!) {
|
||||
}
|
||||
}
|
||||
|
||||
val keystoreDir = file("build/keystore")
|
||||
val keystoreDir = layout.buildDirectory.dir("keystore")
|
||||
val keystoreName = "localhost.p12"
|
||||
val keystoreFile = keystoreDir.map { it.file(keystoreName) }
|
||||
val certsFileName = "localhost.pem"
|
||||
|
||||
val generateKeys by tasks.registering(JavaExec::class) {
|
||||
val outputFile = file("$keystoreDir/$keystoreName")
|
||||
outputs.file(outputFile)
|
||||
outputs.file(keystoreFile)
|
||||
mainClass.set("sun.security.tools.keytool.Main")
|
||||
args = listOf(
|
||||
"-genkeypair",
|
||||
@@ -83,17 +83,17 @@ val generateKeys by tasks.registering(JavaExec::class) {
|
||||
"-storepass", "password",
|
||||
"-dname", "CN=localhost"
|
||||
)
|
||||
workingDir = keystoreDir
|
||||
workingDir(keystoreDir)
|
||||
doFirst {
|
||||
workingDir.mkdirs()
|
||||
outputFile.delete()
|
||||
keystoreFile.get().asFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
val exportCerts by tasks.registering(JavaExec::class) {
|
||||
val outputFile = file("$keystoreDir/$certsFileName")
|
||||
val outputFile = keystoreDir.map { it.file(certsFileName) }
|
||||
dependsOn(generateKeys)
|
||||
inputs.file("$keystoreDir/$keystoreName")
|
||||
inputs.file(keystoreFile)
|
||||
outputs.file(outputFile)
|
||||
mainClass.set("sun.security.tools.keytool.Main")
|
||||
args = listOf(
|
||||
@@ -104,10 +104,10 @@ val exportCerts by tasks.registering(JavaExec::class) {
|
||||
"-rfc",
|
||||
"-file", certsFileName
|
||||
)
|
||||
workingDir = keystoreDir
|
||||
workingDir(keystoreDir)
|
||||
doFirst {
|
||||
workingDir.mkdirs()
|
||||
outputFile.delete()
|
||||
outputFile.get().asFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,18 @@ val pklCodegenJava: Configuration by configurations.creating
|
||||
val firstPartySourcesJars by configurations.existing
|
||||
|
||||
val generateTestConfigClasses by tasks.registering(JavaExec::class) {
|
||||
outputs.dir("build/testConfigClasses")
|
||||
val outputDir = layout.buildDirectory.dir("testConfigClasses")
|
||||
outputs.dir(outputDir)
|
||||
inputs.dir("src/test/resources/codegenPkl")
|
||||
|
||||
classpath = pklCodegenJava
|
||||
mainClass.set("org.pkl.codegen.java.Main")
|
||||
args("--output-dir", "build/testConfigClasses")
|
||||
args("--generate-javadoc")
|
||||
args(fileTree("src/test/resources/codegenPkl"))
|
||||
argumentProviders.add(CommandLineArgumentProvider {
|
||||
listOf(
|
||||
"--output-dir", outputDir.get().asFile.path,
|
||||
"--generate-javadoc"
|
||||
) + fileTree("src/test/resources/codegenPkl").map { it.path }
|
||||
})
|
||||
}
|
||||
|
||||
tasks.processTestResources {
|
||||
@@ -56,8 +60,8 @@ val testFromJar by tasks.registering(Test::class) {
|
||||
//}
|
||||
|
||||
sourceSets.getByName("test") {
|
||||
java.srcDir("build/testConfigClasses/java")
|
||||
resources.srcDir("build/testConfigClasses/resources")
|
||||
java.srcDir(layout.buildDirectory.dir("testConfigClasses/java"))
|
||||
resources.srcDir(layout.buildDirectory.dir("testConfigClasses/resources"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -28,18 +28,21 @@ dependencies {
|
||||
}
|
||||
|
||||
val generateTestConfigClasses by tasks.registering(JavaExec::class) {
|
||||
outputs.dir("build/testConfigClasses")
|
||||
val outputDir = layout.buildDirectory.dir("testConfigClasses")
|
||||
outputs.dir(outputDir)
|
||||
inputs.dir("src/test/resources/codegenPkl")
|
||||
|
||||
classpath = pklCodegenKotlin
|
||||
mainClass.set("org.pkl.codegen.kotlin.Main")
|
||||
args("--output-dir", "build/testConfigClasses")
|
||||
args(fileTree("src/test/resources/codegenPkl"))
|
||||
argumentProviders.add(CommandLineArgumentProvider {
|
||||
listOf("--output-dir", outputDir.get().asFile.absolutePath) +
|
||||
fileTree("src/test/resources/codegenPkl").map { it.absolutePath }
|
||||
})
|
||||
}
|
||||
|
||||
sourceSets.getByName("test") {
|
||||
java.srcDir("build/testConfigClasses/kotlin")
|
||||
resources.srcDir("build/testConfigClasses/resources")
|
||||
java.srcDir(layout.buildDirectory.dir("testConfigClasses/kotlin"))
|
||||
resources.srcDir(layout.buildDirectory.dir("testConfigClasses/resources"))
|
||||
}
|
||||
|
||||
tasks.processTestResources {
|
||||
|
||||
@@ -282,7 +282,7 @@ tasks.testNative {
|
||||
|
||||
tasks.clean {
|
||||
delete("generated/")
|
||||
delete("build/test-packages")
|
||||
delete(layout.buildDirectory.dir("test-packages"))
|
||||
}
|
||||
|
||||
spotless {
|
||||
|
||||
@@ -10,7 +10,7 @@ plugins {
|
||||
// create and publish a self-contained stdlib archive
|
||||
// purpose is to provide non-jvm tools/projects with a versioned stdlib
|
||||
val stdlibZip by tasks.registering(Zip::class) {
|
||||
destinationDirectory.set(file("build/libs"))
|
||||
destinationDirectory.set(layout.buildDirectory.dir("libs"))
|
||||
archiveBaseName.set("pkl-stdlib")
|
||||
archiveVersion.set(project.version as String)
|
||||
into("org/pkl/stdlib") {
|
||||
|
||||
Reference in New Issue
Block a user