LUCENE-9179: don't invoke the same build recursively upon first run, just continue. Seems like gradle bug but let's not cry about it - it just happens once and CI defaults can be passed independently on command-line.

This commit is contained in:
Dawid Weiss 2020-01-27 17:34:13 +01:00
parent 8e357b167b
commit b420ef8f77
1 changed files with 29 additions and 49 deletions

View File

@ -4,28 +4,18 @@
def hasDefaults = rootProject.file("gradle.properties").exists()
// If we don't have the defaults yet, create them and re-run the build
// recursively with the same parameters as originally passed.
//
// Sadly, the recursive build doesn't seem to pick up the parallelism
// tweaks from gradle.properties file.
// If we don't have the defaults yet, create them.
if (!hasDefaults) {
configure(rootProject) {
task setupLocalDefaultsOnce(type: GradleBuild) {
task localSettings() {
doFirst {
// Approximate a common-sense default for running gradle/tests with parallel
// workers: half the count of available cpus but not more than 12.
def cpus = Runtime.runtime.availableProcessors()
def maxWorkers = (int) Math.max(1d, Math.min(cpus * 0.5d, 12))
def testsJvms = (int) Math.max(1d, Math.min(cpus * 0.5d, 12))
// Reuse the same set of parameters for the recursive invocation and apply
// some of these eagerly.
def startParams = gradle.startParameter.newInstance()
startParams.setParallelProjectExecutionEnabled(true)
startParams.setMaxWorkerCount(maxWorkers)
startParameter(startParams)
// Write the defaults for this machine.
rootProject.file("gradle.properties").write(
[
@ -45,7 +35,6 @@ if (!hasDefaults) {
"tests.jvms=${testsJvms}"
].join("\n"), "UTF-8")
doFirst {
logger.log(LogLevel.WARN, "\nIMPORTANT. This is the first time you ran the build. " +
"I wrote some sane defaults (for this machine) to 'gradle.properties', " +
"they will be picked up on consecutive gradle invocations (not this one).\n\n" +
@ -54,20 +43,11 @@ if (!hasDefaults) {
}
}
// Disable any tasks in this build, they were forked recursively.
gradle.taskGraph.whenReady { graph ->
graph.allTasks.each { task ->
if (task != rootProject.setupLocalDefaultsOnce) {
task.enabled = false
}
}
}
// Make all tasks depend on local setup to make sure it'll run.
allprojects {
tasks.all { task ->
if (task != rootProject.setupLocalDefaultsOnce) {
task.dependsOn rootProject.setupLocalDefaultsOnce
if (task != rootProject.localSettings) {
task.dependsOn rootProject.localSettings
}
}
}