mirror of
https://github.com/apple/pkl.git
synced 2026-04-17 22:19:46 +02:00
Run spotless apply
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
plugins {
|
||||
pklAllProjects
|
||||
pklKotlinLibrary
|
||||
@@ -7,11 +22,9 @@ plugins {
|
||||
|
||||
// already on build script class path (see buildSrc/build.gradle.kts),
|
||||
// hence must only specify plugin ID here
|
||||
@Suppress("DSL_SCOPE_VIOLATION")
|
||||
id(libs.plugins.shadow.get().pluginId)
|
||||
@Suppress("DSL_SCOPE_VIOLATION") id(libs.plugins.shadow.get().pluginId)
|
||||
|
||||
@Suppress("DSL_SCOPE_VIOLATION")
|
||||
alias(libs.plugins.checksum)
|
||||
@Suppress("DSL_SCOPE_VIOLATION") alias(libs.plugins.checksum)
|
||||
}
|
||||
|
||||
// make Java executable available to other subprojects
|
||||
@@ -54,7 +67,7 @@ dependencies {
|
||||
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
|
||||
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common")
|
||||
}
|
||||
|
||||
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
testImplementation(libs.wiremock)
|
||||
|
||||
@@ -69,17 +82,13 @@ dependencies {
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
manifest {
|
||||
attributes += mapOf("Main-Class" to "org.pkl.cli.Main")
|
||||
}
|
||||
manifest { attributes += mapOf("Main-Class" to "org.pkl.cli.Main") }
|
||||
|
||||
// not required at runtime
|
||||
exclude("org/pkl/cli/svm/**")
|
||||
}
|
||||
|
||||
tasks.javadoc {
|
||||
enabled = false
|
||||
}
|
||||
tasks.javadoc { enabled = false }
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveFileName.set("jpkl")
|
||||
@@ -93,72 +102,74 @@ tasks.shadowJar {
|
||||
exclude("module-info.*")
|
||||
}
|
||||
|
||||
val javaExecutable by tasks.registering(ExecutableJar::class) {
|
||||
inJar.set(tasks.shadowJar.flatMap { it.archiveFile })
|
||||
outJar.set(layout.buildDirectory.file("executable/jpkl"))
|
||||
val javaExecutable by
|
||||
tasks.registering(ExecutableJar::class) {
|
||||
inJar.set(tasks.shadowJar.flatMap { it.archiveFile })
|
||||
outJar.set(layout.buildDirectory.file("executable/jpkl"))
|
||||
|
||||
// uncomment for debugging
|
||||
//jvmArgs.addAll("-ea", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
|
||||
}
|
||||
// uncomment for debugging
|
||||
// jvmArgs.addAll("-ea", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
|
||||
}
|
||||
|
||||
val testJavaExecutable by tasks.registering(Test::class) {
|
||||
testClassesDirs = tasks.test.get().testClassesDirs
|
||||
classpath =
|
||||
// compiled test classes
|
||||
sourceSets.test.get().output +
|
||||
// java executable
|
||||
javaExecutable.get().outputs.files +
|
||||
// test-only dependencies
|
||||
// (test dependencies that are also main dependencies must already be contained in java executable;
|
||||
// to verify that, we don't want to include them here)
|
||||
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
|
||||
}
|
||||
val testJavaExecutable by
|
||||
tasks.registering(Test::class) {
|
||||
testClassesDirs = tasks.test.get().testClassesDirs
|
||||
classpath =
|
||||
// compiled test classes
|
||||
sourceSets.test.get().output +
|
||||
// java executable
|
||||
javaExecutable.get().outputs.files +
|
||||
// test-only dependencies
|
||||
// (test dependencies that are also main dependencies must already be contained in java
|
||||
// executable;
|
||||
// to verify that, we don't want to include them here)
|
||||
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(testJavaExecutable)
|
||||
}
|
||||
tasks.check { dependsOn(testJavaExecutable) }
|
||||
|
||||
// 0.14 Java executable was broken because javaExecutable.jvmArgs wasn't commented out.
|
||||
// To catch this and similar problems, test that Java executable starts successfully.
|
||||
val testStartJavaExecutable by tasks.registering(Exec::class) {
|
||||
dependsOn(javaExecutable)
|
||||
val outputFile =
|
||||
layout.buildDirectory.file("testStartJavaExecutable") // dummy output to satisfy up-to-date check
|
||||
outputs.file(outputFile)
|
||||
val testStartJavaExecutable by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(javaExecutable)
|
||||
val outputFile =
|
||||
layout.buildDirectory.file(
|
||||
"testStartJavaExecutable"
|
||||
) // dummy output to satisfy up-to-date check
|
||||
outputs.file(outputFile)
|
||||
|
||||
if (buildInfo.os.isWindows) {
|
||||
executable = "java"
|
||||
args("-jar", javaExecutable.get().outputs.files.singleFile.toString(), "--version")
|
||||
} else {
|
||||
executable = javaExecutable.get().outputs.files.singleFile.toString()
|
||||
args("--version")
|
||||
if (buildInfo.os.isWindows) {
|
||||
executable = "java"
|
||||
args("-jar", javaExecutable.get().outputs.files.singleFile.toString(), "--version")
|
||||
} else {
|
||||
executable = javaExecutable.get().outputs.files.singleFile.toString()
|
||||
args("--version")
|
||||
}
|
||||
|
||||
doFirst { outputFile.get().asFile.delete() }
|
||||
|
||||
doLast { outputFile.get().asFile.writeText("OK") }
|
||||
}
|
||||
|
||||
doFirst { outputFile.get().asFile.delete() }
|
||||
|
||||
doLast { outputFile.get().asFile.writeText("OK") }
|
||||
}
|
||||
|
||||
tasks.check {
|
||||
dependsOn(testStartJavaExecutable)
|
||||
}
|
||||
tasks.check { dependsOn(testStartJavaExecutable) }
|
||||
|
||||
fun Exec.configureExecutable(
|
||||
graalVm: BuildInfo.GraalVm,
|
||||
outputFile: Provider<RegularFile>,
|
||||
extraArgs: List<String> = listOf()
|
||||
) {
|
||||
inputs.files(sourceSets.main.map { it.output })
|
||||
inputs
|
||||
.files(sourceSets.main.map { it.output })
|
||||
.withPropertyName("mainSourceSets")
|
||||
.withPathSensitivity(PathSensitivity.RELATIVE)
|
||||
inputs.files(configurations.runtimeClasspath)
|
||||
inputs
|
||||
.files(configurations.runtimeClasspath)
|
||||
.withPropertyName("runtimeClasspath")
|
||||
.withNormalizer(ClasspathNormalizer::class)
|
||||
val nativeImageCommandName = if (buildInfo.os.isWindows) "native-image.cmd" else "native-image"
|
||||
inputs.files(
|
||||
file(graalVm.baseDir)
|
||||
.resolve("bin/$nativeImageCommandName")
|
||||
)
|
||||
inputs
|
||||
.files(file(graalVm.baseDir).resolve("bin/$nativeImageCommandName"))
|
||||
.withPropertyName("graalVmNativeImage")
|
||||
.withPathSensitivity(PathSensitivity.ABSOLUTE)
|
||||
outputs.file(outputFile)
|
||||
@@ -170,99 +181,108 @@ fun Exec.configureExecutable(
|
||||
// JARs to exclude from the class path for the native-image build.
|
||||
val exclusions = listOf(libs.truffleApi, libs.graalSdk).map { it.get().module.name }
|
||||
// https://www.graalvm.org/22.0/reference-manual/native-image/Options/
|
||||
argumentProviders.add(CommandLineArgumentProvider {
|
||||
buildList {
|
||||
// currently gives a deprecation warning, but we've been told
|
||||
// that the "initialize everything at build time" *CLI* option is likely here to stay
|
||||
add("--initialize-at-build-time=")
|
||||
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
|
||||
// needed for jansi (see https://github.com/fusesource/jansi/issues/199#issuecomment-1252268229)
|
||||
add("--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess,org.fusesource.jansi.internal")
|
||||
add("--no-fallback")
|
||||
add("-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl")
|
||||
add("-H:IncludeResources=org/jline/utils/.*")
|
||||
add("-H:IncludeResourceBundles=org.pkl.core.errorMessages")
|
||||
add("-H:IncludeResources=org/pkl/commons/cli/PklCARoots.pem")
|
||||
add("--macro:truffle")
|
||||
add("-H:Class=org.pkl.cli.Main")
|
||||
add("-H:Name=${outputFile.get().asFile.name}")
|
||||
// the actual limit (currently) used by native-image is this number + 1400 (idea is to compensate for Truffle's own nodes)
|
||||
add("-H:MaxRuntimeCompileMethods=1800")
|
||||
add("-H:+EnforceMaxRuntimeCompileMethods")
|
||||
add("--enable-url-protocols=http,https")
|
||||
add("-H:+ReportExceptionStackTraces")
|
||||
// disable automatic support for JVM CLI options (puts our main class in full control of argument parsing)
|
||||
add("-H:-ParseRuntimeOptions")
|
||||
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower) executable
|
||||
if (!buildInfo.isReleaseBuild) {
|
||||
add("-Ob")
|
||||
argumentProviders.add(
|
||||
CommandLineArgumentProvider {
|
||||
buildList {
|
||||
// currently gives a deprecation warning, but we've been told
|
||||
// that the "initialize everything at build time" *CLI* option is likely here to stay
|
||||
add("--initialize-at-build-time=")
|
||||
// needed for messagepack-java (see https://github.com/msgpack/msgpack-java/issues/600)
|
||||
// needed for jansi (see
|
||||
// https://github.com/fusesource/jansi/issues/199#issuecomment-1252268229)
|
||||
add(
|
||||
"--initialize-at-run-time=org.msgpack.core.buffer.DirectBufferAccess,org.fusesource.jansi.internal"
|
||||
)
|
||||
add("--no-fallback")
|
||||
add("-H:IncludeResources=org/pkl/core/stdlib/.*\\.pkl")
|
||||
add("-H:IncludeResources=org/jline/utils/.*")
|
||||
add("-H:IncludeResourceBundles=org.pkl.core.errorMessages")
|
||||
add("-H:IncludeResources=org/pkl/commons/cli/PklCARoots.pem")
|
||||
add("--macro:truffle")
|
||||
add("-H:Class=org.pkl.cli.Main")
|
||||
add("-H:Name=${outputFile.get().asFile.name}")
|
||||
// the actual limit (currently) used by native-image is this number + 1400 (idea is to
|
||||
// compensate for Truffle's own nodes)
|
||||
add("-H:MaxRuntimeCompileMethods=1800")
|
||||
add("-H:+EnforceMaxRuntimeCompileMethods")
|
||||
add("--enable-url-protocols=http,https")
|
||||
add("-H:+ReportExceptionStackTraces")
|
||||
// disable automatic support for JVM CLI options (puts our main class in full control of
|
||||
// argument parsing)
|
||||
add("-H:-ParseRuntimeOptions")
|
||||
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower)
|
||||
// executable
|
||||
if (!buildInfo.isReleaseBuild) {
|
||||
add("-Ob")
|
||||
}
|
||||
add("-march=compatibility")
|
||||
// native-image rejects non-existing class path entries -> filter
|
||||
add("--class-path")
|
||||
val pathInput =
|
||||
sourceSets.main.get().output +
|
||||
configurations.runtimeClasspath.get().filter {
|
||||
it.exists() && !exclusions.any { exclude -> it.name.contains(exclude) }
|
||||
}
|
||||
add(pathInput.asPath)
|
||||
// make sure dev machine stays responsive (15% slowdown on my laptop)
|
||||
val processors =
|
||||
Runtime.getRuntime().availableProcessors() /
|
||||
if (buildInfo.os.isMacOsX && !buildInfo.isCiBuild) 4 else 1
|
||||
add("-J-XX:ActiveProcessorCount=${processors}")
|
||||
// Pass through all `HOMEBREW_` prefixed environment variables to allow build with shimmed
|
||||
// tools.
|
||||
addAll(environment.keys.filter { it.startsWith("HOMEBREW_") }.map { "-E$it" })
|
||||
addAll(extraArgs)
|
||||
}
|
||||
add("-march=compatibility")
|
||||
// native-image rejects non-existing class path entries -> filter
|
||||
add("--class-path")
|
||||
val pathInput = sourceSets.main.get().output + configurations.runtimeClasspath.get()
|
||||
.filter { it.exists() && !exclusions.any { exclude -> it.name.contains(exclude) } }
|
||||
add(pathInput.asPath)
|
||||
// make sure dev machine stays responsive (15% slowdown on my laptop)
|
||||
val processors = Runtime.getRuntime().availableProcessors() /
|
||||
if (buildInfo.os.isMacOsX && !buildInfo.isCiBuild) 4 else 1
|
||||
add("-J-XX:ActiveProcessorCount=${processors}")
|
||||
// Pass through all `HOMEBREW_` prefixed environment variables to allow build with shimmed tools.
|
||||
addAll(environment.keys.filter { it.startsWith("HOMEBREW_") }.map { "-E$it" })
|
||||
addAll(extraArgs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the pkl CLI for macOS/amd64.
|
||||
*/
|
||||
val macExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-macos-amd64")
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the pkl CLI for macOS/aarch64.
|
||||
*/
|
||||
val macExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAarch64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAarch64,
|
||||
layout.buildDirectory.file("executable/pkl-macos-aarch64"),
|
||||
listOf(
|
||||
"-H:+AllowDeprecatedBuilderClassesOnImageClasspath"
|
||||
/** Builds the pkl CLI for macOS/amd64. */
|
||||
val macExecutableAmd64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-macos-amd64")
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the pkl CLI for linux/amd64.
|
||||
*/
|
||||
val linuxExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-linux-amd64")
|
||||
)
|
||||
}
|
||||
/** Builds the pkl CLI for macOS/aarch64. */
|
||||
val macExecutableAarch64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAarch64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAarch64,
|
||||
layout.buildDirectory.file("executable/pkl-macos-aarch64"),
|
||||
listOf("-H:+AllowDeprecatedBuilderClassesOnImageClasspath")
|
||||
)
|
||||
}
|
||||
|
||||
/** Builds the pkl CLI for linux/amd64. */
|
||||
val linuxExecutableAmd64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-linux-amd64")
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the pkl CLI for linux/aarch64.
|
||||
*
|
||||
* Right now, this is built within a container on Mac using emulation because CI does not have
|
||||
* ARM instances.
|
||||
* Right now, this is built within a container on Mac using emulation because CI does not have ARM
|
||||
* instances.
|
||||
*/
|
||||
val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAarch64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAarch64,
|
||||
layout.buildDirectory.file("executable/pkl-linux-aarch64")
|
||||
)
|
||||
}
|
||||
val linuxExecutableAarch64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAarch64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAarch64,
|
||||
layout.buildDirectory.file("executable/pkl-linux-aarch64")
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a statically linked CLI for linux/amd64.
|
||||
@@ -270,23 +290,25 @@ val linuxExecutableAarch64: TaskProvider<Exec> by tasks.registering(Exec::class)
|
||||
* Note: we don't publish the same for linux/aarch64 because native-image doesn't support this.
|
||||
* Details: https://www.graalvm.org/22.0/reference-manual/native-image/ARM64/
|
||||
*/
|
||||
val alpineExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
|
||||
listOf("--static", "--libc=musl")
|
||||
)
|
||||
}
|
||||
val alpineExecutableAmd64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-alpine-linux-amd64"),
|
||||
listOf("--static", "--libc=musl")
|
||||
)
|
||||
}
|
||||
|
||||
val windowsExecutableAmd64: TaskProvider<Exec> by tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-windows-amd64"),
|
||||
listOf("-Dfile.encoding=UTF-8")
|
||||
)
|
||||
}
|
||||
val windowsExecutableAmd64: TaskProvider<Exec> by
|
||||
tasks.registering(Exec::class) {
|
||||
dependsOn(":installGraalVmAmd64")
|
||||
configureExecutable(
|
||||
buildInfo.graalVmAmd64,
|
||||
layout.buildDirectory.file("executable/pkl-windows-amd64"),
|
||||
listOf("-Dfile.encoding=UTF-8")
|
||||
)
|
||||
}
|
||||
|
||||
tasks.assembleNative {
|
||||
when {
|
||||
@@ -296,15 +318,12 @@ tasks.assembleNative {
|
||||
dependsOn(macExecutableAarch64)
|
||||
}
|
||||
}
|
||||
|
||||
buildInfo.os.isWindows -> {
|
||||
dependsOn(windowsExecutableAmd64)
|
||||
}
|
||||
|
||||
buildInfo.os.isLinux && buildInfo.arch == "aarch64" -> {
|
||||
dependsOn(linuxExecutableAarch64)
|
||||
}
|
||||
|
||||
buildInfo.os.isLinux && buildInfo.arch == "amd64" -> {
|
||||
dependsOn(linuxExecutableAmd64)
|
||||
if (buildInfo.hasMuslToolchain) {
|
||||
@@ -315,7 +334,8 @@ tasks.assembleNative {
|
||||
}
|
||||
|
||||
// make Java executable available to other subprojects
|
||||
// (we don't do the same for native executables because we don't want tasks assemble/build to build them)
|
||||
// (we don't do the same for native executables because we don't want tasks assemble/build to build
|
||||
// them)
|
||||
artifacts {
|
||||
add("javaExecutable", javaExecutable.map { it.outputs.files.singleFile }) {
|
||||
name = "pkl-cli-java"
|
||||
@@ -325,7 +345,7 @@ artifacts {
|
||||
}
|
||||
}
|
||||
|
||||
//region Maven Publishing
|
||||
// region Maven Publishing
|
||||
publishing {
|
||||
publications {
|
||||
register<MavenPublication>("javaExecutable") {
|
||||
@@ -344,7 +364,8 @@ publishing {
|
||||
Pkl CLI executable for Java.
|
||||
Can be executed directly on *nix (if the `java` command is found on the PATH) and with `java -jar` otherwise.
|
||||
Requires Java 17 or higher.
|
||||
""".trimIndent()
|
||||
"""
|
||||
.trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -438,5 +459,4 @@ signing {
|
||||
sign(publishing.publications["macExecutableAmd64"])
|
||||
sign(publishing.publications["alpineLinuxExecutableAmd64"])
|
||||
sign(publishing.publications["windowsExecutableAmd64"])
|
||||
}
|
||||
//endregion
|
||||
} // endregion
|
||||
|
||||
Reference in New Issue
Block a user