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

Warnings-as-errors fail BuildSubmission results #6006

Merged
merged 5 commits into from
Jan 7, 2021

Conversation

rainersigwald
Copy link
Member

@rainersigwald rainersigwald commented Jan 4, 2021

Fix #5837 by moving the promotion of warnings to build failures to the BuildSubmission level instead of doing it in BuildManager (where the result change happened at EndBuild() time and thus wasn't visible when checking the result after the submission completed:

msbuild/src/MSBuild/XMake.cs

Lines 1256 to 1268 in c70d520

(result, exception) = ExecuteBuild(buildManager, buildRequest);
}
}
if (result != null && exception == null)
{
success = result == BuildResultCode.Success;
}
}
finally
{
buildManager.EndBuild();
}

Fixes dotnet#5837 by using the approach used in BuildManager to check whether
warnings-as-errors were emitted to convert the result to a failure at
the submission level, because MSBuild was promoting it to failure too
late (in time to log it but not to fail the msbuild invocation.
It's handled at the submission level now.
@rainersigwald rainersigwald marked this pull request as ready for review January 5, 2021 17:55
Copy link
Member

@ladipro ladipro left a comment

Choose a reason for hiding this comment

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

Looks good!

src/MSBuild.UnitTests/XMake_Tests.cs Outdated Show resolved Hide resolved
@@ -198,6 +198,13 @@ private void CheckForCompletion()
bool hasCompleted = (Interlocked.Exchange(ref _completionInvoked, 1) == 1);
if (!hasCompleted)
{
// Did this submission have warnings elevated to errors? If so, mark it as
// failed even though it succeeded (with warnings--but they're errors).
if (((IBuildComponentHost)BuildManager).LoggingService.HasBuildSubmissionLoggedErrors(BuildResult.SubmissionId))
Copy link
Member

Choose a reason for hiding this comment

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

Check for understanding:
The build is "completed" only after _completionEvent is set, so this is called before any build displays whether it has been completed. _completionInvoked is initially set to 0, so if the build has completed, checked via line 196, then it checks if we already knew the build was completed with the Interlocked.Exchange check, and if we hadn't already done completion-related things, we trigger them by setting _completionEvent. This check to see if we had logged errors without failing comes immediately before that, so before any BuildSubmission can be marked complete, it has to check whether it has logged any errors (or warnings converted to errors), hence fixing the bug. Is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be a bit pedantic, you say "build" several times when it would be more correct to say "BuildSubmission". You can have multiple submissions in a single Begin/EndBuild pair, and that's done in practice in, e.g., the VS solution build--so that all of the different projects share project state across a VS build operation, but have their own Submissions (and so the project system can know when each project individually finishes and schedule the ones that depend on it).

Co-authored-by: Forgind <Forgind@users.noreply.github.com>
@rajeemm
Copy link

rajeemm commented Aug 31, 2021

Hi, which dotnet cli version this should be taken into effect?
Thanks!

@rainersigwald
Copy link
Member Author

@roaladje .NET SDK 5.0.200 and higher should have it.

@rajeemm
Copy link

rajeemm commented Aug 31, 2021

@roaladje .NET SDK 5.0.200 and higher should have it.

Thanks! works!

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.

dotnet build fails, but exit code is still 0
5 participants