Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate Configuration Cache when buildSrc builds are added #31460

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

alllex
Copy link
Member

@alllex alllex commented Nov 29, 2024

Fixes: #31097

@@ -24,9 +24,10 @@ import static org.junit.Assume.assumeFalse

class ConfigurationCacheBuildSrcChangesIntegrationTest extends AbstractConfigurationCacheIntegrationTest {

def configurationCache = newConfigurationCacheFixture()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it here is not typical, but fine by me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests use this fixture. I saw no need in creating it in every test

configurationCacheRun "help"
then:
configurationCache.assertStateStored()
buildOperations.none("Load build (:buildSrc)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Did you consider reusing the build ops fixture owned by the CC fixture (by adding corresponding assertions there?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that CC fixture comes with operation tracking as well. It's a good idea to reuse it.

It's as easy as

Suggested change
buildOperations.none("Load build (:buildSrc)")
configurationCache.operations.none("Load build (:buildSrc)")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed my mind about this - since the checks we are performing are not related to CC, it makes sense not to use the one from CC fixture

configurationCacheRun "help"
then:
configurationCache.assertStateStored()
outputContains("Calculating task graph as configuration cache cannot be reused because a buildSrc build at 'buildSrc' has been added.")
Copy link
Member

@abstratt abstratt Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳 nice!

"buildSrc" | "src/main/groovy/MyClass.groovy"
}

def "reuses cache upon changing invalid buildSrc by creating #description"() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -108,6 +114,7 @@ class ConfigurationCacheFingerprintWriter(
FeatureFlagListener,
FileCollectionObservationListener,
ScriptSourceListener,
BuildAddedListener,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@@ -204,6 +215,21 @@ class ConfigurationCacheFingerprintWriter(
CompositeStoppable.stoppable(buildScopedWriter, projectScopedWriter).stop()
}

override fun buildAdded(buildState: BuildState) {
captureBuildSrcPresence(buildState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 Maybe add a note for lines 200 and 219 on which cases each one covers? At first, I thought they may be redundant, but confirmed they aren't, not sure why though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two places we capture because we add the listener late. The first visitBuilds call goes over all builds that have been added early, which includes the root build, root/buildSrc, root/buildSrc/buildSrc, etc. The second place react to discovering any included builds, e.g. during the evaluation of settings of any build that is already in the tree.

I think having these two places is good enough solution for now. However, I'd try and find a solution that guarantees we have not skipped any builds this way. We'd need to either make sure our listener is registered unconditionally and early enough, or we should find/create a general Gradle callback that is called after all builds have been added to the registry (and no more builds can be added). I wasn't able to find such a callback if it exists today.

@@ -760,6 +760,10 @@ tmpdir is currently ${System.getProperty("java.io.tmpdir")}""")
recreateExecuter()
}

BuildOperationsFixture newBuildOperationsFixture() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 Possibly not needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not needed if we go with the CC fixture operations

Copy link
Member

@abstratt abstratt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, Alex. Provided some optional feedback/asked some questions.

is ConfigurationCacheFingerprint.BuildSrcCandidate -> input.run {
val currentValid = host.hasValidBuildSrc(buildSrcDir)
ifOrNull(currentValid != valid) {
text("a buildSrc build at ").reference(displayNameOf(buildSrcDir))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -291,6 +294,14 @@ class ConfigurationCacheFingerprintChecker(private val host: Host) {
text("the set of system properties prefixed by ").reference(prefix).text(" has changed: ").text(detailedMessageForChanges(snapshotWithoutIgnored, currentWithoutIgnored))
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ This blows up the 100 line limit. I would add:

@Suppress("CyclomaticComplexMethod", "LongMethod")

instead of somehow avoiding going over the limit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration cache is not invalidated when creating a buildSrc directory
2 participants