Use build-results file for root project dirs

Instead of using a separate mechanism and init script, reuse the information
captured in the build-results file.
This commit is contained in:
Daz DeBoer 2022-06-05 08:34:07 -06:00
parent e234151ec9
commit e644288a42
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
6 changed files with 8 additions and 145 deletions

View file

@ -1,10 +0,0 @@
import org.gradle.util.GradleVersion
// Only run against root build. Do not run against included builds.
def isTopLevelBuild = gradle.getParent() == null
// Only record configuration-cache entries for Gradle 7+
def isAtLeastGradle7 = GradleVersion.current() >= GradleVersion.version('7.0')
if (isTopLevelBuild && isAtLeastGradle7) {
apply from: 'project-root-capture.plugin.groovy'
}

View file

@ -1,40 +0,0 @@
/*
* Capture the build root directory for each executed Gradle build.
* This is used to save/restore configuration-cache files, so:
* - The implementation only makes sense if it's config-cache compatible
* - We only need to support Gradle 7+
*/
import org.gradle.tooling.events.*
settingsEvaluated { settings ->
def rootDir = settings.rootDir.absolutePath
def rootListLocation = new File(System.getenv("RUNNER_TEMP"), "project-roots.txt").absolutePath
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-projectRootTracker", ProjectTracker, { spec ->
spec.getParameters().getRootDir().set(rootDir);
spec.getParameters().getRootListLocation().set(rootListLocation);
})
gradle.services.get(BuildEventsListenerRegistry).onTaskCompletion(projectTracker)
}
abstract class ProjectTracker implements BuildService<ProjectTracker.Params>, OperationCompletionListener, AutoCloseable {
interface Params extends BuildServiceParameters {
Property<String> getRootDir();
Property<String> getRootListLocation();
}
public void onFinish(FinishEvent finishEvent) {}
@Override
public void close() {
def rootDir = getParameters().getRootDir().get()
def rootDirEntry = rootDir + '\n'
def rootListFile = new File(getParameters().getRootListLocation().get())
if (!rootListFile.exists() || !rootListFile.text.contains(rootDirEntry)) {
rootListFile << rootDirEntry
}
}
}