Skip to content

Commit ba52a22

Browse files
authored
[Build] Make checkPart4 configuration cache compatible (#117250)
This makes checkPart4 tasks in general configuration cache compliant. We do not enable it by default in our pipelines yet. That will eventually be done in separate PRs. To track any regressions we cover the checkPart4 task in the weekly gradle cache validation build job
1 parent ce2a7de commit ba52a22

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

.buildkite/scripts/gradle-configuration-cache-validation.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
set -euo pipefail
44

55
# This is a workaround for https://github.com/gradle/gradle/issues/28159
6-
.ci/scripts/run-gradle.sh --no-daemon precommit
6+
.ci/scripts/run-gradle.sh --no-daemon $@
77

8-
.ci/scripts/run-gradle.sh --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2
8+
.ci/scripts/run-gradle.sh --configuration-cache -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 $@
99

1010
# Create a temporary file
1111
tmpOutputFile=$(mktemp)
1212
trap "rm $tmpOutputFile" EXIT
1313

1414
echo "2nd run"
15-
.ci/scripts/run-gradle.sh --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 | tee $tmpOutputFile
15+
.ci/scripts/run-gradle.sh --configuration-cache -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 $@ | tee $tmpOutputFile
1616

1717
# Check if the command was successful
1818
if grep -q "Configuration cache entry reused." $tmpOutputFile; then

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcSetupExtension.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.gradle.api.Action;
1717
import org.gradle.api.GradleException;
1818
import org.gradle.api.Project;
19+
import org.gradle.api.Task;
1920
import org.gradle.api.logging.LogLevel;
2021
import org.gradle.api.model.ObjectFactory;
2122
import org.gradle.api.provider.Property;
@@ -103,10 +104,16 @@ private static TaskProvider<LoggedExec> createRunBwcGradleTask(
103104
loggedExec.dependsOn("checkoutBwcBranch");
104105
loggedExec.getWorkingDir().set(checkoutDir.get());
105106

106-
loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", providerFactory.of(JavaHomeValueSource.class, spec -> {
107-
spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version()));
108-
spec.getParameters().getCheckoutDir().set(checkoutDir);
109-
}).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s))));
107+
loggedExec.doFirst(new Action<Task>() {
108+
@Override
109+
public void execute(Task task) {
110+
Provider<String> minimumCompilerVersionValueSource = providerFactory.of(JavaHomeValueSource.class, spec -> {
111+
spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version()));
112+
spec.getParameters().getCheckoutDir().set(checkoutDir);
113+
}).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s)));
114+
loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", minimumCompilerVersionValueSource.get());
115+
}
116+
});
110117

111118
if (isCi && OS.current() != OS.WINDOWS) {
112119
// TODO: Disabled for now until we can figure out why files are getting corrupted
@@ -169,14 +176,6 @@ private static Provider<String> getJavaHome(ObjectFactory objectFactory, JavaToo
169176
.map(launcher -> launcher.getMetadata().getInstallationPath().getAsFile().getAbsolutePath());
170177
}
171178

172-
private static String readFromFile(File file) {
173-
try {
174-
return FileUtils.readFileToString(file).trim();
175-
} catch (IOException ioException) {
176-
throw new GradleException("Cannot read java properties file.", ioException);
177-
}
178-
}
179-
180179
public abstract static class JavaHomeValueSource implements ValueSource<String, JavaHomeValueSource.Params> {
181180

182181
private String minimumCompilerVersionPath(Version bwcVersion) {
@@ -185,6 +184,14 @@ private String minimumCompilerVersionPath(Version bwcVersion) {
185184
: "buildSrc/" + MINIMUM_COMPILER_VERSION_PATH;
186185
}
187186

187+
private static String readFromFile(File file) {
188+
try {
189+
return FileUtils.readFileToString(file).trim();
190+
} catch (IOException ioException) {
191+
throw new GradleException("Cannot read java properties file.", ioException);
192+
}
193+
}
194+
188195
@Override
189196
public String obtain() {
190197
return readFromFile(

x-pack/plugin/sql/qa/jdbc/security/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ subprojects {
5050

5151

5252
tasks.withType(RestIntegTestTask).configureEach {
53+
def taskName = name
5354
dependsOn copyTestClasses
5455
classpath += configurations.testArtifacts
5556
testClassesDirs = project.files(testArtifactsDir)
@@ -58,15 +59,15 @@ subprojects {
5859
project.gradle.sharedServices,
5960
TestClustersPlugin.REGISTRY_SERVICE_NAME
6061
)
61-
project.getProviders().of(TestClusterValueSource.class) {
62+
63+
def clusterInfo = project.getProviders().of(TestClusterValueSource.class) {
6264
it.parameters.path.set(clusterPath)
63-
it.parameters.clusterName.set("javaRestTest")
65+
it.parameters.clusterName.set(taskName)
6466
it.parameters.service = serviceProvider
6567
}
6668

67-
nonInputProperties.systemProperty 'tests.audit.logfile',
68-
"${-> testClusters.javaRestTest.singleNode().getAuditLog()}"
69+
nonInputProperties.systemProperty 'tests.audit.logfile', clusterInfo.map { it.auditLogs.get(0) }
6970
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
70-
"${-> testClusters.javaRestTest.singleNode().getAuditLog().getParentFile()}/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}.json"
71+
clusterInfo.map { it.auditLogs.get(0).getParentFile().toString() + "/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json" }
7172
}
7273
}

x-pack/plugin/sql/qa/server/security/build.gradle

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
2+
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
3+
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
4+
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
5+
import org.elasticsearch.gradle.util.GradleUtils
6+
17
apply plugin: 'elasticsearch.internal-test-artifact'
28

39
dependencies {
@@ -16,6 +22,8 @@ subprojects {
1622
// Use tests from the root security qa project in subprojects
1723
configurations.create('testArtifacts').transitive(false)
1824

25+
def clusterPath = getPath()
26+
1927
dependencies {
2028
javaRestTestImplementation project(":x-pack:plugin:core")
2129
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
@@ -50,12 +58,23 @@ subprojects {
5058

5159
tasks.named("javaRestTest").configure {
5260
dependsOn copyTestClasses
61+
62+
Provider<TestClustersRegistry> serviceProvider = GradleUtils.getBuildService(
63+
project.gradle.sharedServices,
64+
TestClustersPlugin.REGISTRY_SERVICE_NAME
65+
)
66+
67+
def clusterInfo = project.getProviders().of(TestClusterValueSource.class) {
68+
it.parameters.path.set(clusterPath)
69+
it.parameters.clusterName.set("javaRestTest")
70+
it.parameters.service = serviceProvider
71+
}
72+
5373
testClassesDirs += project.files(testArtifactsDir)
5474
classpath += configurations.testArtifacts
55-
nonInputProperties.systemProperty 'tests.audit.logfile',
56-
"${-> testClusters.javaRestTest.singleNode().getAuditLog()}"
75+
nonInputProperties.systemProperty 'tests.audit.logfile', clusterInfo.map { it.auditLogs.get(0) }
5776
nonInputProperties.systemProperty 'tests.audit.yesterday.logfile',
58-
"${-> testClusters.javaRestTest.singleNode().getAuditLog().getParentFile()}/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json.gz"
77+
clusterInfo.map { it.auditLogs.get(0).getParentFile().toString() + "/javaRestTest_audit-${new Date().format('yyyy-MM-dd')}-1.json.gz"}
5978
}
6079

6180
}

0 commit comments

Comments
 (0)