allow use of compilationOptions.nowarn to suppress warnings.

fixes #576
This commit is contained in:
Andrew Stanton-Nurse 2016-01-13 15:56:02 -08:00
parent 1aacac6a72
commit e27c583443
6 changed files with 31 additions and 6 deletions

View file

@ -14,6 +14,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
{
internal static readonly OptionTemplate s_definesTemplate = new OptionTemplate("define");
internal static readonly OptionTemplate s_suppressWarningTemplate = new OptionTemplate("suppress-warning");
internal static readonly OptionTemplate s_languageVersionTemplate = new OptionTemplate("language-version");
internal static readonly OptionTemplate s_platformTemplate = new OptionTemplate("platform");
@ -37,6 +39,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
public static CommonCompilerOptions Parse(ArgumentSyntax syntax)
{
IReadOnlyList<string> defines = null;
IReadOnlyList<string> suppressWarnings = null;
string languageVersion = null;
string platform = null;
bool? allowUnsafe = null;
@ -52,6 +55,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
syntax.DefineOptionList(s_definesTemplate.LongName, ref defines, "Preprocessor definitions");
syntax.DefineOptionList(s_suppressWarningTemplate.LongName, ref suppressWarnings, "Suppresses the specified warning");
syntax.DefineOption(s_languageVersionTemplate.LongName, ref languageVersion,
"The version of the language used to compile");
@ -85,6 +90,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
return new CommonCompilerOptions
{
Defines = defines,
SuppressWarnings = suppressWarnings,
LanguageVersion = languageVersion,
Platform = platform,
AllowUnsafe = allowUnsafe,
@ -101,6 +107,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
public static IEnumerable<string> SerializeToArgs(this CommonCompilerOptions options)
{
var defines = options.Defines;
var suppressWarnings = options.SuppressWarnings;
var languageVersion = options.LanguageVersion;
var platform = options.Platform;
var allowUnsafe = options.AllowUnsafe;
@ -119,6 +126,11 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
args.AddRange(defines.Select(def => s_definesTemplate.ToLongArg(def)));
}
if (suppressWarnings != null)
{
args.AddRange(suppressWarnings.Select(def => s_suppressWarningTemplate.ToLongArg(def)));
}
if (languageVersion != null)
{
args.Add(s_languageVersionTemplate.ToLongArg(languageVersion));

View file

@ -33,6 +33,8 @@ namespace Microsoft.DotNet.ProjectModel
public bool? GenerateXmlDocumentation { get; set; }
public IEnumerable<string> SuppressWarnings { get; set; }
public override bool Equals(object obj)
{
var other = obj as CommonCompilerOptions;
@ -48,7 +50,8 @@ namespace Microsoft.DotNet.ProjectModel
EmitEntryPoint == other.EmitEntryPoint &&
GenerateXmlDocumentation == other.GenerateXmlDocumentation &&
PreserveCompilationContext == other.PreserveCompilationContext &&
Enumerable.SequenceEqual(Defines ?? Enumerable.Empty<string>(), other.Defines ?? Enumerable.Empty<string>());
Enumerable.SequenceEqual(Defines ?? Enumerable.Empty<string>(), other.Defines ?? Enumerable.Empty<string>()) &&
Enumerable.SequenceEqual(SuppressWarnings ?? Enumerable.Empty<string>(), other.SuppressWarnings ?? Enumerable.Empty<string>());
}
public override int GetHashCode()
@ -67,13 +70,19 @@ namespace Microsoft.DotNet.ProjectModel
continue;
}
// Defines are always combined
// Defines and suppressions are always combined
if (option.Defines != null)
{
var existing = result.Defines ?? Enumerable.Empty<string>();
result.Defines = existing.Concat(option.Defines).Distinct();
}
if (option.SuppressWarnings != null)
{
var existing = result.SuppressWarnings ?? Enumerable.Empty<string>();
result.SuppressWarnings = existing.Concat(option.SuppressWarnings).Distinct();
}
if (option.LanguageVersion != null)
{
result.LanguageVersion = option.LanguageVersion;

View file

@ -526,6 +526,7 @@ namespace Microsoft.DotNet.ProjectModel
return new CommonCompilerOptions
{
Defines = rawOptions.ValueAsStringArray("define"),
SuppressWarnings = rawOptions.ValueAsStringArray("nowarn"),
LanguageVersion = rawOptions.ValueAsString("languageVersion"),
AllowUnsafe = rawOptions.ValueAsNullableBoolean("allowUnsafe"),
Platform = rawOptions.ValueAsString("platform"),

View file

@ -140,6 +140,11 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
commonArgs.AddRange(options.Defines.Select(def => $"-d:{def}"));
}
if (options.SuppressWarnings != null)
{
commonArgs.AddRange(options.SuppressWarnings.Select(w => $"-nowarn:{w}"));
}
if (options.LanguageVersion != null)
{
commonArgs.Add($"-langversion:{GetLanguageVersion(options.LanguageVersion)}");

View file

@ -29,9 +29,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
var result = buildCommand.ExecuteWithCapturedOutput();
result.Should().Pass();
// Should have triggered some compiler warnings about missing XML doc comments
Assert.True(result.StdErr.Contains("warning CS1591"));
// verify the output xml file
var outputXml = Path.Combine(outputDir, "TestLibrary.xml");
Assert.True(File.Exists(outputXml));
@ -64,4 +61,4 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
restoreCommand.Execute($"--quiet {args}").Should().Pass();
}
}
}
}

View file

@ -1,6 +1,7 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"nowarn": [ "CS1591" ],
"xmlDoc": true
},
"dependencies": {