-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
BuildCheck does not run on restore #10018
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There still seem to be some merge leftovers
src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs
Outdated
Show resolved
Hide resolved
src/Build/BuildCheck/Logging/BuildAnalysisLoggingContextExtensions.cs
Outdated
Show resolved
Hide resolved
|
||
var buildCheckManager = (_componentHost.GetComponent(BuildComponentType.BuildCheckManagerProvider) as IBuildCheckManagerProvider)!.Instance; | ||
buildCheckManager.SetDataSource(BuildCheckDataSource.BuildExecution); | ||
var propertyEntry = _requestEntry.RequestConfiguration.GlobalProperties[MSBuildConstants.MSBuildIsRestoring]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I understand, since we have this, why we need the change to the evaluation-started event. Can you go over that again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two points in BuildCheck that actually run the analyzer. One of them is through the RequestBuilder
which works on the worker nodes. And through the BuildCheckConnectorLogger
which runs on the main node. The modification to the evaluation-started event is to get information about the restore phase to the connector logger.
{ | ||
if (isRestore) | ||
{ | ||
isRestore = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense to me, won't there be a bunch of ProjectFinished events that will fire one after the other, causing the first one to unset this and the others to do check stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I figured that out after I ran this for a bit. I had hoped the event was just fired once. Is there an event that is fired at the end of the restore phase that I can use to to control the flow on the connector logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are relying on the restore happen fully before the build - then the first ProjectEvaluationStartedEventArgs
that is not marked with IsRestore
denotes the start of the build after the restore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the isRestore
reset to happen when we receive another ProjectEvaluationStartedEventArgs
event.
{ | ||
if (!isRestore) | ||
{ | ||
_buildCheckManager.StartProjectRequest(BuildCheckDataSource.EventArgs, e.BuildEventContext!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super-nit: Indentation
/// <summary> | ||
/// Gets or sets is the project is currently on restore phase. | ||
/// </summary> | ||
public bool IsRestore { get; internal set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth considering keeping the property internal for now. It's needed only internally for the infra. For a public API I wonder if exposing all global build properties wouldn't be potentially more useful. But since it's generally hard to remove or update an API once shipped, I think I would vote for not exposing anything publicly for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually - assuming that we also want to use this flag when replaying a binlog, we need to make a public surface change anyway. In other words, the new flag should likely be serialized. cc @JanKrivanek to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct.
BuildEventArgsWritter (and BuildEventArgsReader) need to be adjusted accordingly, plus the BinLogger version needs to be incremented
internal const int FileFormatVersion = 20; |
Then we'll need to copy the identical change to the https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/main/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs (and preferrably BuildEventArgsWritter as well) - so that viewer is fine with the change (it'd grace handle skip the extra field, but would report it as unknown change).
The analogous change seem to have been forgotten for tracing: #10016 (comment), so alternatively we can have bothe of those changes be reflected in a single PR with single BinaryLogger version bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @KirillOsenkov (just a heads up that same small changes will be comming. We should handle them proactively ourselves)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps @JanKrivanek we should have a wiki page somewhere with a walkthrough of how to do BinaryLogger related changes? Including the viewer PR, version increments etc. Feel free to add to the wiki on the viewer repo or here, wherever it makes more sense for the team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - I'll find a time to do this
@@ -626,7 +626,7 @@ private void Evaluate() | |||
} | |||
} | |||
|
|||
_evaluationLoggingContext.LogProjectEvaluationStarted(); | |||
_evaluationLoggingContext.LogProjectEvaluationStarted(_data.GlobalPropertiesDictionary[MSBuildConstants.MSBuildIsRestoring] is not null); ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently set the property only to true
but it's not unconceivable that at some point someone would want to set it to false
to mean "we're not restoring". For future proofing, would you consider parsing the value instead of just checking that the prop is defined?
** UPDATE May/15 **
|
Fixes: #9747
Context
We currently run BuildCheck during the restore phase of the build, because of this we end up running BuildCheck twice per project. This PR disables BuildCheck during restore phase.
Changes Made
Added two check for the restore phase on the code.
The first one is on the
RequestBuilder
, it reads the global propertyIsRestore
and creates a BuildCheck instance as necessary.The second one is within the
BuildCheckConnectorLogger
so we do not start a new BuildCheck run because of received events. In this case I added abool
toProjectEvaluationStartedEventArgs
so we can have access to theIsRestore
variable within the logger. We skip all event messages until we get aProjectFinishedEventArgs
, which signals the end of a build / the restore phase.Tests
Added extra tests that only runs the restore target.
Reopened from #9907