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

Fix some IP problems in the build #28929

Merged
merged 6 commits into from
May 21, 2024
Merged

Fix some IP problems in the build #28929

merged 6 commits into from
May 21, 2024

Conversation

asodja
Copy link
Member

@asodja asodja commented Apr 23, 2024

  • usage of allproject in mirrors.settings.gradle.kts script -> replaced with gradle.lifecycle.beforeProject
  • accessing a BuildEnvironmentExtension on a root project -> we register now this extension to every project and wire values via gradle.lifecycle.beforeProject and a build service

@asodja asodja added the a:investigation Issues requiring decision or investigation label Apr 23, 2024
buildEnvironmentExtension.gitBranch = git("rev-parse", "--abbrev-ref", "HEAD")
buildEnvironmentExtension.repoRoot = layout.projectDirectory.parentOrRoot()
val buildLayout = layout
gradle.lifecycle.beforeProject {
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Before git would be executed only twice per build, right? And now it's once per project?

Copy link
Member Author

@asodja asodja Apr 23, 2024

Choose a reason for hiding this comment

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

Interestingly it seems it's called 3-times in both cases during sync, at least when trying to do some println in the zip part I get for both:

> Configure project :
Executed 'git rev-parse --abbrev-ref HEAD' for ':'
Executed 'git rev-parse --abbrev-ref HEAD' for ':'
Executed 'git rev-parse --abbrev-ref HEAD' for ':'

So it looks like provider is evaulated anytime git() is called anyway, or that should not be the case?

If you have any ideas how to improve that, let me know.
We can also just merge improvement for gradle/shared-with-buildSrc/mirrors.settings.gradle.kts that is trivial and we leave this one for some other time when we'll have more tools.

Copy link
Member Author

@asodja asodja Apr 26, 2024

Choose a reason for hiding this comment

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

Any thoughts if that solution could be a problem or not @gradle/bt-developer-productivity?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So it looks like provider is evaulated anytime git() is called anyway, or that should not be the case?

This seems to be expected behavior. BiProvider's implementation did run the combiner function every time:

R combinedUnpackedValue = combiner.apply(leftValue.getWithoutSideEffect(), rightValue.getWithoutSideEffect());

That being said, it's still a bit inefficient to have the provider instance in every Project, even though it may not be a problem right now. Suppose somebody start using gitCommitId in every Project in the future, that would be executed hundreds of times.

Right now I don't have a very good idea for this, is it possible to store the information in the similar way as DevelocityConfiguration? I think there's only one instance stored in the build right?

Copy link
Member

Choose a reason for hiding this comment

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

It would be possible to always execute git once in the settings plugin and then simply propagate the data to every project as a Kotlin data class or similar construct (until we have a proper solution via the Shared Data API):

captureBuildEnvironment().let { buildEnvironment ->
  gradle.lifecycle.beforeProject {
     extensions.add("buildEnvironment", buildEnvironment)
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

How will that affect configuration cache? E.g. will that git read be an input to configuration cache?

Copy link
Member

Choose a reason for hiding this comment

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

In my example, yes. Is the git result currently directly wired as a task input or is it ever used at configuration time?

Copy link
Member Author

@asodja asodja May 16, 2024

Choose a reason for hiding this comment

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

I think in some cases it's still used at a configuration time, but there was a PR that improved that #27954.

I was thinking that maybe a solution with a Build service could be ok in this case. So in root we would register a build service that would then cache the result of a git command, so it could be reused in other projects.

Copy link
Member Author

@asodja asodja May 17, 2024

Choose a reason for hiding this comment

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

I think solution with BuildService works. I tested and cc is reused if commit id changes, at least for integration tests.

And if

* The external process is executed only once and only when the value is requested for the first
* time.
is true, then git process should be executed just once

@asodja asodja marked this pull request as ready for review May 17, 2024 18:48
@asodja asodja requested a review from a team as a code owner May 17, 2024 18:48
@asodja asodja requested review from bamboo and blindpirate May 17, 2024 18:48
Copy link
Collaborator

@blindpirate blindpirate left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Member

@bamboo bamboo left a comment

Choose a reason for hiding this comment

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

🎉

import org.gradle.api.provider.Property


abstract class BuildEnvironmentExtension {
Copy link
Member

Choose a reason for hiding this comment

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

💅 Why not an interface?

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 guess because I just copy/pasted the class. :)
Changed it to interface.

@asodja asodja added this pull request to the merge queue May 21, 2024
@bot-gradle bot-gradle added this to the 8.9 RC1 milestone May 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 21, 2024
@asodja
Copy link
Member Author

asodja commented May 21, 2024

@bot-gradle test AST

@gradle gradle deleted a comment from asodja May 21, 2024
@gradle gradle deleted a comment from asodja May 21, 2024
@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you. Click here to see all build failures.

@asodja
Copy link
Member Author

asodja commented May 21, 2024

@bot-gradle test AST

@bot-gradle
Copy link
Collaborator

I've triggered the following builds for you. Click here to see all build failures.

@asodja asodja added this pull request to the merge queue May 21, 2024
Merged via the queue into master with commit 7821e18 May 21, 2024
33 checks passed
@asodja asodja deleted the asodja/buildenv-problems branch May 21, 2024 15:08
@alllex alllex added a:chore Minor issue without significant impact in:building-gradle gradle/gradle build and removed a:investigation Issues requiring decision or investigation labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:chore Minor issue without significant impact in:building-gradle gradle/gradle build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants