Skip to content

Commit

Permalink
Only log warnings with WarnNotAsError
Browse files Browse the repository at this point in the history
  • Loading branch information
Forgind committed Jan 20, 2022
1 parent fb700f9 commit 977e445
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 28 deletions.
9 changes: 9 additions & 0 deletions src/Build.UnitTests/BackEnd/MockLoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ public ISet<string> WarningsAsErrors
set;
}

/// <summary>
/// List of warnings to not treat as errors.
/// </summary>
public ISet<string> WarningsNotAsErrors
{
get;
set;
}

/// <summary>
/// List of warnings to treat as low importance messages.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ ILoggingService InitializeLoggingService()
AppendDebuggingLoggers(_buildParameters.Loggers),
_buildParameters.ForwardingLoggers,
_buildParameters.WarningsAsErrors,
_buildParameters.WarningsNotAsErrors,
_buildParameters.WarningsAsMessages);

_nodeManager.RegisterPacketHandler(NodePacketType.LogMessage, LogMessagePacket.FactoryForDeserialization, loggingService as INodePacketHandler);
Expand Down Expand Up @@ -2939,7 +2940,7 @@ void OnProjectStartedBody(ProjectStartedEventArgs e)
/// <summary>
/// Creates a logging service around the specified set of loggers.
/// </summary>
private ILoggingService CreateLoggingService(IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> forwardingLoggers, ISet<string> warningsAsErrors, ISet<string> warningsAsMessages)
private ILoggingService CreateLoggingService(IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> forwardingLoggers, ISet<string> warningsAsErrors, ISet<string> warningsNotAsErrors, ISet<string> warningsAsMessages)
{
Debug.Assert(Monitor.IsEntered(_syncLock));

Expand All @@ -2960,6 +2961,7 @@ private ILoggingService CreateLoggingService(IEnumerable<ILogger> loggers, IEnum
loggingService.OnProjectStarted += _projectStartedEventHandler;
loggingService.OnProjectFinished += _projectFinishedEventHandler;
loggingService.WarningsAsErrors = warningsAsErrors;
loggingService.WarningsNotAsErrors = warningsNotAsErrors;
loggingService.WarningsAsMessages = warningsAsMessages;

try
Expand Down
6 changes: 6 additions & 0 deletions src/Build/BackEnd/BuildManager/BuildParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ internal BuildParameters(BuildParameters other, bool resetEnvironment = false)
_logTaskInputs = other._logTaskInputs;
_logInitialPropertiesAndItems = other._logInitialPropertiesAndItems;
WarningsAsErrors = other.WarningsAsErrors == null ? null : new HashSet<string>(other.WarningsAsErrors, StringComparer.OrdinalIgnoreCase);
WarningsNotAsErrors = other.WarningsNotAsErrors == null ? null : new HashSet<string>(other.WarningsNotAsErrors, StringComparer.OrdinalIgnoreCase);
WarningsAsMessages = other.WarningsAsMessages == null ? null : new HashSet<string>(other.WarningsAsMessages, StringComparer.OrdinalIgnoreCase);
_projectLoadSettings = other._projectLoadSettings;
_interactive = other._interactive;
Expand Down Expand Up @@ -548,6 +549,11 @@ public bool OnlyLogCriticalEvents
/// </summary>
public ISet<string> WarningsAsErrors { get; set; }

/// <summary>
/// A list of warnings to not treat as errors. Only has any effect if WarningsAsErrors is empty.
/// </summary>
public ISet<string> WarningsNotAsErrors { get; set; }

/// <summary>
/// A list of warnings to treat as low importance messages.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Build/BackEnd/Components/Logging/ILoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ ISet<string> WarningsAsErrors
set;
}

/// <summary>
/// Set of warnings to not treat as errors. Only has any effect if WarningsAsErrors is non-null but empty.
/// </summary>
ISet<string> WarningsNotAsErrors
{
get;
set;
}

/// <summary>
/// A list of warnings to treat as low importance messages.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion src/Build/BackEnd/Components/Logging/LoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,15 @@ public ISet<string> WarningsAsErrors
set;
} = null;

/// <summary>
/// Get of warnings to not treat as errors. Only has any effect if WarningsAsErrors is empty but not null.
/// </summary>
public ISet<string> WarningsNotAsErrors
{
get;
set;
} = null;

/// <summary>
/// A list of warnings to treat as low importance messages.
/// </summary>
Expand Down Expand Up @@ -1744,7 +1753,7 @@ private bool ShouldTreatWarningAsError(BuildWarningEventArgs warningEvent)
{
// Global warnings as errors apply to all projects. If the list is empty or contains the code, the warning should be treated as an error
//
if (WarningsAsErrors.Count == 0 || WarningsAsErrors.Contains(warningEvent.Code))
if ((WarningsAsErrors.Count == 0 && (WarningsNotAsErrors is null || !WarningsNotAsErrors.Contains(warningEvent.Code))) || WarningsAsErrors.Contains(warningEvent.Code))
{
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Build/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Microsoft.Build.FileSystem.IDirectoryCache.FileExists(string path) -> bool
Microsoft.Build.FileSystem.IDirectoryCacheFactory
Microsoft.Build.FileSystem.IDirectoryCacheFactory.GetDirectoryCacheForEvaluation(int evaluationId) -> Microsoft.Build.FileSystem.IDirectoryCache
static Microsoft.Build.Globbing.CompositeGlob.Create(System.Collections.Generic.IEnumerable<Microsoft.Build.Globbing.IMSBuildGlob> globs) -> Microsoft.Build.Globbing.IMSBuildGlob
Microsoft.Build.Execution.BuildParameters.WarningsNotAsErrors.get -> System.Collections.Generic.ISet<string>
Microsoft.Build.Execution.BuildParameters.WarningsNotAsErrors.set -> void
4 changes: 3 additions & 1 deletion src/Build/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ Microsoft.Build.FileSystem.IDirectoryCache.EnumerateFiles<TResult>(string path,
Microsoft.Build.FileSystem.IDirectoryCache.FileExists(string path) -> bool
Microsoft.Build.FileSystem.IDirectoryCacheFactory
Microsoft.Build.FileSystem.IDirectoryCacheFactory.GetDirectoryCacheForEvaluation(int evaluationId) -> Microsoft.Build.FileSystem.IDirectoryCache
static Microsoft.Build.Globbing.CompositeGlob.Create(System.Collections.Generic.IEnumerable<Microsoft.Build.Globbing.IMSBuildGlob> globs) -> Microsoft.Build.Globbing.IMSBuildGlob
static Microsoft.Build.Globbing.CompositeGlob.Create(System.Collections.Generic.IEnumerable<Microsoft.Build.Globbing.IMSBuildGlob> globs) -> Microsoft.Build.Globbing.IMSBuildGlob
Microsoft.Build.Execution.BuildParameters.WarningsNotAsErrors.get -> System.Collections.Generic.ISet<string>
Microsoft.Build.Execution.BuildParameters.WarningsNotAsErrors.set -> void
1 change: 1 addition & 0 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ public void InvalidToolsVersionErrors()
new StringWriter(),
false,
warningsAsErrors: null,
warningsNotAsErrors: null,
warningsAsMessages: null,
enableRestore: false,
profilerLogger: null,
Expand Down
2 changes: 2 additions & 0 deletions src/MSBuild/CommandLineSwitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ internal enum ParameterizedSwitch
Preprocess,
Targets,
WarningsAsErrors,
WarningsNotAsErrors,
WarningsAsMessages,
BinaryLogger,
Restore,
Expand Down Expand Up @@ -263,6 +264,7 @@ bool emptyParametersAllowed
new ParameterizedSwitchInfo( new string[] { "preprocess", "pp" }, ParameterizedSwitch.Preprocess, null, false, null, true, false ),
new ParameterizedSwitchInfo( new string[] { "targets", "ts" }, ParameterizedSwitch.Targets, null, false, null, true, false ),
new ParameterizedSwitchInfo( new string[] { "warnaserror", "err" }, ParameterizedSwitch.WarningsAsErrors, null, true, null, true, true ),
new ParameterizedSwitchInfo( new string[] { "warnnotaserror", "err" }, ParameterizedSwitch.WarningsNotAsErrors, null, true, "MissingWarnNotAsErrorParameterError", true, true ),
new ParameterizedSwitchInfo( new string[] { "warnasmessage", "nowarn" }, ParameterizedSwitch.WarningsAsMessages, null, true, "MissingWarnAsMessageParameterError", true, false ),
new ParameterizedSwitchInfo( new string[] { "binarylogger", "bl" }, ParameterizedSwitch.BinaryLogger, null, false, null, true, false ),
new ParameterizedSwitchInfo( new string[] { "restore", "r" }, ParameterizedSwitch.Restore, null, false, null, true, false ),
Expand Down
10 changes: 9 additions & 1 deletion src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,14 @@ Copyright (C) Microsoft Corporation. All rights reserved.
LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized.
</comment>
</data>
<data name="MissingWarnNotAsErrorParameterError" UESanitized="true" Visibility="Public">
<value>MSBUILD : error MSB1060: Specify one or more warning codes to keep as warnings despite a global -warnaserror when using the -warnNotAsError switch.</value>
<comment>
{StrBegin="MSBUILD : error MSB1060: "}
UE: This happens if the user does something like "msbuild.exe -warnNotAsError:" without any codes.
LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized.
</comment>
</data>
<data name="InvalidProfilerValue" xml:space="preserve">
<value>MSBUILD : error MSB1053: Provided filename is not valid. {0}</value>
</data>
Expand Down Expand Up @@ -1294,7 +1302,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<!--
The command line message bucket is: MSB1001 - MSB1999
Next error code should be MSB1060.
Next error code should be MSB1061.
Don't forget to update this comment after using the new code.
-->
Expand Down
9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 977e445

Please sign in to comment.