-
Notifications
You must be signed in to change notification settings - Fork 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
Report better warnings and errors if build hosts exit abnormally #71909
Merged
jasonmalinowski
merged 4 commits into
dotnet:main
from
jasonmalinowski:log-buildhost-process-exits
Feb 5, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
860d45a
Log the process log if the BuildHost exits with a non-zero code
jasonmalinowski 5db5647
Rewrite test to not use MSBuildProjectLoader
jasonmalinowski 19751d7
Report workspace messages for warnings/errors from the build hosts
jasonmalinowski de6f68a
Add a direct test to test MSBuildProjectLoader
jasonmalinowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporterLoggerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.CodeAnalysis.MSBuild; | ||
|
||
internal class DiagnosticReporterLoggerProvider : ILoggerProvider | ||
{ | ||
private readonly DiagnosticReporter _reporter; | ||
|
||
private DiagnosticReporterLoggerProvider(DiagnosticReporter reporter) | ||
{ | ||
_reporter = reporter; | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return new Logger(_reporter, categoryName); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public static ILoggerFactory CreateLoggerFactoryForDiagnosticReporter(DiagnosticReporter reporter) | ||
{ | ||
// Note: it's important we set MinLevel here, or otherwise we'll still get called in Log() for things below LogLevel.Warning. | ||
return new LoggerFactory( | ||
[new DiagnosticReporterLoggerProvider(reporter)], | ||
new LoggerFilterOptions() { MinLevel = LogLevel.Warning }); | ||
} | ||
|
||
private sealed class Logger(DiagnosticReporter reporter, string categoryName) : ILogger | ||
{ | ||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull | ||
{ | ||
return null; | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return logLevel >= LogLevel.Warning; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
var kind = logLevel == LogLevel.Warning ? WorkspaceDiagnosticKind.Warning : WorkspaceDiagnosticKind.Failure; | ||
var message = formatter(state, exception); | ||
if (!string.IsNullOrEmpty(categoryName)) | ||
message = $"[{categoryName}] {message}"; | ||
|
||
reporter.Report(new WorkspaceDiagnostic(kind, message)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Trying to keep both constructors working was a getting a bit convoluted -- the nullable parameters to the other constructor existed only to make it possible to even write this as a :this() chain, and adding more nullable parameters to keep it going was just getting sillier too. So I'm just splitting into two, which ensures that the mainline use of the internal constructor is never getting a null from the other parts of the system.