Revert configuration cache (#1659)

This reverts the commits that enabled Gradle's configuration cache
feature.

IMO: this feature is too hard to use. We don't know if a task is valid
for the configuration cache until it runs, and it's very hard to tell if
something is safe when authoring Gradle code.
For example, our publish tasks are currently failing; I don't know how I
would fix this without running the publish task again on my dev machine.

Also, some of our build scripts become more brittle because of this; for
example, see
https://github.com/apple/pkl/blob/bb07589eae0b3195a589559a3245cbc12c29b394/build-logic/src/main/kotlin/BuildInfo.kt#L291-L296
This commit is contained in:
Daniel Chao
2026-06-05 16:31:40 -07:00
committed by GitHub
parent bb07589eae
commit 1cc20b611f
21 changed files with 180 additions and 307 deletions
+33 -24
View File
@@ -16,18 +16,18 @@
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.api.services.ServiceReference
import org.gradle.api.tasks.ClasspathNormalizer
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.registerIfAbsent
import org.gradle.kotlin.dsl.withNormalizer
import org.gradle.process.ExecOperations
@@ -49,31 +49,25 @@ abstract class NativeImageBuild : DefaultTask() {
@get:InputFiles abstract val classpath: ConfigurableFileCollection
/** Path to the `native-image` binary (e.g. `<graalVmBaseDir>/bin/native-image`). */
@get:Input abstract val nativeImageExecutable: Property<String>
private val outputDir = project.layout.buildDirectory.dir("executable")
@get:Input abstract val graalSdkLibraryName: Property<String>
@get:Input abstract val releaseBuild: Property<Boolean>
@get:Input abstract val nativeArch: Property<Boolean>
/** Divisor applied to `availableProcessors` to throttle native-image CPU usage. */
@get:Input abstract val processorDivisor: Property<Int>
@get:OutputFile val outputFile = outputDir.flatMap { it.file(imageName) }
@get:Inject protected abstract val execOperations: ExecOperations
@get:Inject protected abstract val layout: ProjectLayout
private val graalVm: Provider<BuildInfo.GraalVm> = arch.map { a ->
when (a) {
Architecture.AMD64 -> buildInfo.graalVmAmd64
Architecture.AARCH64 -> buildInfo.graalVmAarch64
}
}
private val outputDir
get() = layout.buildDirectory.dir("executable")
private val buildInfo: BuildInfo = project.extensions.getByType(BuildInfo::class.java)
@get:OutputFile
val outputFile
get() = outputDir.flatMap { it.file(imageName) }
private val nativeImageCommandName =
if (buildInfo.os.isWindows) "native-image.cmd" else "native-image"
@get:ServiceReference("nativeImageBuildService")
abstract val buildService: Property<NativeImageBuildService>
private val nativeImageExecutable = graalVm.map { "${it.baseDir}/bin/$nativeImageCommandName" }
private val extraArgsFromProperties by lazy {
System.getProperties()
@@ -81,7 +75,19 @@ abstract class NativeImageBuild : DefaultTask() {
.map { "${it.key}=${it.value}".substring("pkl.native".length) }
}
private val buildService =
project.gradle.sharedServices.registerIfAbsent(
"nativeImageBuildService",
NativeImageBuildService::class,
) {
maxParallelUsages.set(1)
}
init {
// ensure native-image builds run in serial (prevent `gw buildNative` from consuming all host
// CPU resources).
usesService(buildService)
group = "build"
inputs
@@ -98,7 +104,8 @@ abstract class NativeImageBuild : DefaultTask() {
@Suppress("unused")
protected fun run() {
execOperations.exec {
val exclusions = listOf(graalSdkLibraryName.get())
val exclusions =
listOf(buildInfo.libs.findLibrary("graalSdk").get()).map { it.get().module.name }
executable = nativeImageExecutable.get()
workingDir(outputDir)
@@ -133,10 +140,10 @@ abstract class NativeImageBuild : DefaultTask() {
add("-H:-ParseRuntimeOptions")
// quick build mode: 40% faster compilation, 20% smaller (but presumably also slower)
// executable
if (!releaseBuild.get()) {
if (!buildInfo.isReleaseBuild) {
add("-Ob")
}
if (nativeArch.get()) {
if (buildInfo.isNativeArch) {
add("-march=native")
} else {
add("-march=compatibility")
@@ -148,7 +155,9 @@ abstract class NativeImageBuild : DefaultTask() {
}
add(pathInput.asPath)
// make sure dev machine stays responsive (15% slowdown on my laptop)
val processors = Runtime.getRuntime().availableProcessors() / processorDivisor.get()
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.