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

Add WarningsAsErrors and WarningsNotAsErrors #1388

Merged
merged 6 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ILLink.Tasks/LinkTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ public class ILLink : ToolTask
/// </summary>
public string Warn { get; set; }

/// <summary>
/// The list of warnings to report as errors.
/// Maps to '--warnaserror'.
/// </summary>
public string WarningsAsErrors { get; set; }

/// <summary>
/// The list of warnings to report as usual.
/// Maps to '--warnaserror-'.
/// </summary>
public string WarningsNotAsErrors { get; set; }

mateoatr marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// A list of XML root descriptor files specifying linker
/// roots at a granular level. See the mono/linker
Expand Down Expand Up @@ -315,6 +327,12 @@ protected override string GenerateResponseFileCommands ()
if (Warn != null)
args.Append ("--warn ").AppendLine (Quote (Warn));

if (WarningsAsErrors != null)
args.Append ("--warnaserror ").AppendLine (Quote (WarningsAsErrors));

if (WarningsNotAsErrors != null)
args.Append ("--warnaserror- ").AppendLine (Quote (WarningsNotAsErrors));

// Add global optimization arguments
if (_beforeFieldInit is bool beforeFieldInit)
SetOpt (args, "beforefieldinit", beforeFieldInit);
Expand Down
6 changes: 3 additions & 3 deletions src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -777,18 +777,18 @@ string Unquote (string arg)

value = Unquote (value);
string[] values = value.Split (new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
HashSet<uint> noWarnCodes = new HashSet<uint> ();
HashSet<uint> warningCodes = new HashSet<uint> ();
foreach (string id in values) {
if (!id.StartsWith ("IL", StringComparison.Ordinal))
continue;

var warningCode = id.Substring (2);
if (ushort.TryParse (warningCode, out ushort code)
&& code > 2000 && code <= 6000)
noWarnCodes.Add (code);
warningCodes.Add (code);
}

return noWarnCodes;
return warningCodes;
}

private static Assembly GetCustomAssembly (string arg)
Expand Down
38 changes: 34 additions & 4 deletions test/ILLink.Tasks.Tests/ILLink.Tasks.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
using System.Linq;
using System.Reflection;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using ILLink.Tasks;
using Mono.Linker;
using Mono.Linker.Steps;

namespace ILLink.Tasks.Tests
{
Expand Down Expand Up @@ -306,6 +302,40 @@ public void TestWarn (string warnArg, WarnVersion expectedVersion)
}
}

[Theory]
[InlineData ("", "blah", true, new uint[] { }, new uint[] { })]
mateoatr marked this conversation as resolved.
Show resolved Hide resolved
[InlineData ("IL1001,IL####,IL2000,IL2021,IL2022", "x", false,
new uint[] { 2021, 2022 }, new uint[] { })]
[InlineData ("IL2023,IL6000;IL5042 IL2040", "IL4000,IL4001;IL4002 IL4003", false,
new uint[] { 2023, 2040, 5042, 6000 }, new uint[] { 4000, 4001, 4002, 4003 })]
[InlineData ("IL3000;IL3000;ABCD", "IL2005 il3000 IL2005", false,
new uint[] { 3000 }, new uint[] { 2005 })]
[InlineData ("", "IL2006", true, new uint[] { }, new uint[] { 2006 })]
[InlineData ("IL2001", "IL2001", false, new uint[] { }, new uint[] { 2001 })]
public void TestWarningsAsErrors (string warningsAsErrors, string warningsNotAsErrors, bool generalWarnAsErrorsIsSet, uint[] warnAsError, uint[] warnNotAsError)
{
var task = new MockTask () {
WarningsAsErrors = warningsAsErrors,
WarningsNotAsErrors = warningsNotAsErrors
};

using (var driver = task.CreateDriver ()) {
var actualWarnAsError = driver.Context.WarnAsError;
var actualGeneralWarnAsError = driver.Context.GeneralWarnAsError;
Assert.Equal (actualWarnAsError.Count, warnAsError.Distinct ().Count () + warnNotAsError.Distinct ().Count ());
Assert.Equal (actualGeneralWarnAsError, generalWarnAsErrorsIsSet);
if (warnAsError.Length > 0) {
foreach (var warningCode in warnAsError)
Assert.True (actualWarnAsError.ContainsKey (warningCode) && actualWarnAsError[warningCode] == true);
}

if (warnNotAsError.Length > 0) {
foreach (var warningCode in warnNotAsError)
Assert.True (actualWarnAsError.ContainsKey (warningCode) && actualWarnAsError[warningCode] == false);
}
}
}

public static IEnumerable<object[]> CustomDataCases => new List<object[]> {
new object [] {
new ITaskItem [] {
Expand Down