-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add nowarn option #1303
Add nowarn option #1303
Changes from all commits
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using Mono.Cecil; | ||
using Mono.Cecil.Cil; | ||
|
||
|
@@ -174,6 +175,8 @@ public ISymbolWriterProvider SymbolWriterProvider { | |
|
||
public WarningSuppressionWriter WarningSuppressionWriter { get; } | ||
|
||
public NoWarn DontWarn { get; set; } | ||
|
||
public bool OutputWarningSuppressions { get; set; } | ||
|
||
public UnconditionalSuppressMessageAttributeState Suppressions { get; set; } | ||
|
@@ -229,6 +232,7 @@ public LinkContext (Pipeline pipeline, AssemblyResolver resolver, ReaderParamete | |
PInvokes = new List<PInvokeInfo> (); | ||
Suppressions = new UnconditionalSuppressMessageAttributeState (this); | ||
WarningSuppressionWriter = new WarningSuppressionWriter (this); | ||
DontWarn = NoWarn.Analysis; | ||
|
||
// See https://github.com/mono/linker/issues/612 | ||
const CodeOptimizations defaultOptimizations = | ||
|
@@ -484,9 +488,22 @@ public bool IsOptimizationEnabled (CodeOptimizations optimization, AssemblyDefin | |
|
||
public void LogMessage (MessageContainer message) | ||
{ | ||
if (!LogMessages || message == MessageContainer.Empty) | ||
if (message == MessageContainer.Empty) | ||
return; | ||
|
||
if (!LogMessages && message.Category == MessageCategory.Warning) { | ||
switch (DontWarn) { | ||
case NoWarn.All: | ||
return; | ||
|
||
case NoWarn.Analysis: | ||
if (MessageSubCategory.Analysis.Contains (message.SubCategory)) | ||
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. Nit: Maybe use |
||
return; | ||
|
||
break; | ||
} | ||
} | ||
|
||
if (OutputWarningSuppressions && message.Category == MessageCategory.Warning && message.Origin?.MemberDefinition != null) | ||
WarningSuppressionWriter.AddWarning (message.Code.Value, message.Origin?.MemberDefinition); | ||
|
||
|
@@ -519,9 +536,6 @@ public void LogDiagnostic (string message) | |
/// <param name="subcategory">Optionally, further categorize this warning</param> | ||
public void LogWarning (string text, int code, MessageOrigin origin, string subcategory = MessageSubCategory.None) | ||
{ | ||
if (!LogMessages) | ||
return; | ||
|
||
var warning = MessageContainer.CreateWarningMessage (this, text, code, origin, subcategory); | ||
LogMessage (warning); | ||
} | ||
|
@@ -562,9 +576,6 @@ public void LogWarning (string text, int code, string origin, string subcategory | |
/// <returns>New MessageContainer of 'Error' category</returns> | ||
public void LogError (string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null) | ||
{ | ||
if (!LogMessages) | ||
return; | ||
|
||
var error = MessageContainer.CreateErrorMessage (text, code, subcategory, origin); | ||
LogMessage (error); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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. | ||
|
||
namespace Mono.Linker | ||
{ | ||
public enum NoWarn | ||
{ | ||
// Turn off all warnings. | ||
All, | ||
|
||
// Turn off warnings having the DynamicDependency, PreserveDependency, | ||
// UnrecognizedReflectionPattern, or UnreferencedCode subcategory. | ||
Analysis | ||
} | ||
} |
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.
Do we need to worry about localization?
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 don't localize any message outputted by the linker. I sincerely don't know how useful that would be, but might be a good next step after polishing the current messages that we have (#1275).
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.
Not for .NET 5 - linker is not localized (at all). If we think it's important it would be a relatively non-trivial feature on its own (mostly because there's nothing in that space in linker, so we would have to introduce everything from scratch). So .NET 6 (if we think it's important).
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.
Are other parts of the tool chain localized? What happens for Csc.exe?
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, csc.exe is fully localized. Visual Studio requires localization in all core languages as a shipping criteria, so it was a hard requirement for us. That doesn't sound like the case for the linker, so let's come back to that in the 6.0 timeframe as Vitek suggests.