generated from actions/typescript-action
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from gradle/fix-config-cache
Fix save/restore of configuration-cache
- Loading branch information
Showing
9 changed files
with
70 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
// Capture the build root directory for each executed Gradle build. | ||
import org.gradle.util.GradleVersion | ||
|
||
// Only run against root build. Do not run against included builds. | ||
def isTopLevelBuild = gradle.getParent() == null | ||
if (isTopLevelBuild) { | ||
settingsEvaluated { settings -> | ||
def projectRootEntry = settings.rootDir.absolutePath + '\n' | ||
def projectRootList = new File(settings.gradle.gradleUserHomeDir, "project-roots.txt") | ||
if (!projectRootList.exists() || !projectRootList.text.contains(projectRootEntry)) { | ||
projectRootList << projectRootEntry | ||
} | ||
} | ||
} | ||
// 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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
/* | ||
* 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(settings.gradle.gradleUserHomeDir, "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 | ||
} | ||
} | ||
} |