-
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
Changes from all commits
5b33d8f
916d822
8363efc
7d223bc
f72913e
08b0cd1
288adff
e3ea5ba
f19e200
15c61c8
b047dd4
a014fdb
d0c84b0
8da2ae4
f0c8c19
5626302
39cadf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
using Microsoft.Build.BuildCheck.Acquisition; | ||
using Microsoft.Build.Experimental.BuildCheck; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Shared; | ||
using static Microsoft.Build.BuildCheck.Infrastructure.BuildCheckManagerProvider; | ||
|
||
namespace Microsoft.Build.BuildCheck.Infrastructure; | ||
|
@@ -31,6 +32,8 @@ internal BuildCheckConnectorLogger( | |
|
||
public string? Parameters { get; set; } | ||
|
||
private bool isRestore = false; | ||
|
||
public void Initialize(IEventSource eventSource) | ||
{ | ||
eventSource.AnyEventRaised += EventSource_AnyEventRaised; | ||
|
@@ -48,6 +51,11 @@ public void Shutdown() | |
|
||
private void HandleProjectEvaluationFinishedEvent(ProjectEvaluationFinishedEventArgs eventArgs) | ||
{ | ||
if (isRestore) | ||
{ | ||
return; | ||
} | ||
|
||
if (!IsMetaProjFile(eventArgs.ProjectFile)) | ||
{ | ||
_buildCheckManager.ProcessEvaluationFinishedEventArgs( | ||
|
@@ -60,6 +68,16 @@ private void HandleProjectEvaluationFinishedEvent(ProjectEvaluationFinishedEvent | |
|
||
private void HandleProjectEvaluationStartedEvent(ProjectEvaluationStartedEventArgs eventArgs) | ||
{ | ||
if (eventArgs.IsRestore) | ||
{ | ||
isRestore = true; | ||
return; | ||
} | ||
if (isRestore) | ||
{ | ||
isRestore = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the |
||
} | ||
|
||
if (!IsMetaProjFile(eventArgs.ProjectFile)) | ||
{ | ||
_buildCheckManager.StartProjectEvaluation(BuildCheckDataSource.EventArgs, eventArgs.BuildEventContext!, eventArgs.ProjectFile!); | ||
|
@@ -100,8 +118,22 @@ private void EventSource_BuildFinished(object sender, BuildFinishedEventArgs e) | |
{ | ||
{ typeof(ProjectEvaluationFinishedEventArgs), (BuildEventArgs e) => HandleProjectEvaluationFinishedEvent((ProjectEvaluationFinishedEventArgs) e) }, | ||
{ typeof(ProjectEvaluationStartedEventArgs), (BuildEventArgs e) => HandleProjectEvaluationStartedEvent((ProjectEvaluationStartedEventArgs) e) }, | ||
{ typeof(ProjectStartedEventArgs), (BuildEventArgs e) => _buildCheckManager.StartProjectRequest(BuildCheckDataSource.EventArgs, e.BuildEventContext!) }, | ||
{ typeof(ProjectFinishedEventArgs), (BuildEventArgs e) => _buildCheckManager.EndProjectRequest(BuildCheckDataSource.EventArgs, e.BuildEventContext!) }, | ||
{ typeof(ProjectStartedEventArgs), (BuildEventArgs e) => | ||
{ | ||
if (!isRestore) | ||
{ | ||
_buildCheckManager.StartProjectRequest(BuildCheckDataSource.EventArgs, e.BuildEventContext!); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super-nit: Indentation |
||
} | ||
} | ||
}, | ||
{ typeof(ProjectFinishedEventArgs), (BuildEventArgs e) => | ||
{ | ||
if (!isRestore) | ||
{ | ||
_buildCheckManager.EndProjectRequest(BuildCheckDataSource.EventArgs, e.BuildEventContext!); | ||
} | ||
} | ||
}, | ||
{ typeof(BuildCheckTracingEventArgs), (BuildEventArgs e) => _stats.Merge(((BuildCheckTracingEventArgs)e).TracingData, (span1, span2) => span1 + span2) }, | ||
{ typeof(BuildCheckAcquisitionEventArgs), (BuildEventArgs e) => _buildCheckManager.ProcessAnalyzerAcquisition(((BuildCheckAcquisitionEventArgs)e).ToAnalyzerAcquisitionData(), e.BuildEventContext!) }, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We currently set the property only to |
||
|
||
ErrorUtilities.VerifyThrow(_data.EvaluationId != BuildEventContext.InvalidEvaluationId, "Evaluation should produce an evaluation ID"); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -30,5 +30,10 @@ public ProjectEvaluationStartedEventArgs(string? message, params object[]? messa | |||
/// Gets or sets the full path of the project that started evaluation. | ||||
/// </summary> | ||||
public string? ProjectFile { get; set; } | ||||
|
||||
/// <summary> | ||||
/// Gets or sets is the project is currently on restore phase. | ||||
/// </summary> | ||||
public bool IsRestore { get; internal set; } | ||||
maridematte marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. That's correct.
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Good idea - I'll find a time to do this |
||||
} | ||||
} |
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 theBuildCheckConnectorLogger
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.