Add default suppress to compiler options message

This commit is contained in:
Troy Dai 2016-01-20 14:56:29 -08:00
parent 7555793363
commit 1b8f3a0025
10 changed files with 55 additions and 36 deletions

View file

@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
namespace Microsoft.DotNet.Cli.Compiler.Common
{
public class DefaultCompilerWarningSuppresses
{
public static IReadOnlyDictionary<string, IReadOnlyList<string>> Suppresses { get; } = new Dictionary<string, IReadOnlyList<string>>
{
{ "csc", new string[] {"CS1701", "CS1702", "CS1705" } }
};
}
}

View file

@ -71,7 +71,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
return rootOutputPath;
}
public static void MakeCompilationOutputRunnable(this ProjectContext context, string outputPath, string configuration)
{
context
@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
targetDirectory = EnsureTrailingSlash(targetDirectory);
var pathMap = sourceFiles
.ToDictionary(s => s,
.ToDictionary(s => s,
s => Path.Combine(targetDirectory,
PathUtility.GetRelativePath(sourceDirectory, s)));
@ -199,5 +199,19 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
appConfig.Save(stream);
}
}
public static CommonCompilerOptions GetLanguageSpecificCompilerOptions(this ProjectContext context, NuGetFramework framework, string configurationName)
{
var baseOption = context.ProjectFile.GetCompilerOptions(framework, configurationName);
IReadOnlyList<string> defaultSuppresses;
var compilerName = context.ProjectFile.CompilerName ?? "csc";
if (DefaultCompilerWarningSuppresses.Suppresses.TryGetValue(compilerName, out defaultSuppresses))
{
baseOption.SuppressWarnings = (baseOption.SuppressWarnings ?? Enumerable.Empty<string>()).Concat(defaultSuppresses).Distinct();
}
return baseOption;
}
}
}

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.ProjectModel.Server.Helpers;
using Microsoft.DotNet.ProjectModel.Server.Models;
using Microsoft.DotNet.Cli.Compiler.Common;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Server
@ -62,7 +63,7 @@ namespace Microsoft.DotNet.ProjectModel.Server
snapshot.RootDependency = context.ProjectFile.Name;
snapshot.TargetFramework = context.TargetFramework;
snapshot.SourceFiles = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
snapshot.CompilerOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
snapshot.CompilerOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
snapshot.ProjectReferences = allProjectReferences.OrderBy(reference => reference.Name).ToList();
snapshot.FileReferences = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
snapshot.DependencyDiagnostics = allDependencyDiagnostics;

View file

@ -9,6 +9,7 @@
"System.Threading.ThreadPool": "4.0.10-beta-23704",
"System.Runtime.Serialization.Primitives": "4.1.0-rc2-23704",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Compiler.Common": "1.0.0-*",
"Microsoft.Extensions.CommandLineUtils.Sources": {
"type": "build",
"version": "1.0.0-*"

View file

@ -12,7 +12,7 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Cli.Compiler.Common;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel.Workspaces
@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
// TODO: ctor argument?
var configuration = "Debug";
var compilationOptions = project.ProjectFile.GetCompilerOptions(project.TargetFramework, configuration);
var compilationOptions = project.GetLanguageSpecificCompilerOptions(project.TargetFramework, configuration);
var compilationSettings = ToCompilationSettings(compilationOptions, project.TargetFramework, project.ProjectFile.ProjectDirectory);
@ -136,7 +136,7 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
_cache[path] = assemblyMetadata;
}
}
return assemblyMetadata.GetReference();
}
@ -146,13 +146,8 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
{
var options = GetCompilationOptions(compilerOptions, projectDirectory);
// Disable 1702 until roslyn turns this off by default
options = options.WithSpecificDiagnosticOptions(new Dictionary<string, ReportDiagnostic>
{
{ "CS1701", ReportDiagnostic.Suppress }, // Binding redirects
{ "CS1702", ReportDiagnostic.Suppress },
{ "CS1705", ReportDiagnostic.Suppress }
});
options = options.WithSpecificDiagnosticOptions(compilerOptions.SuppressWarnings.ToDictionary(
suppress => suppress, _ => ReportDiagnostic.Suppress));
AssemblyIdentityComparer assemblyIdentityComparer =
targetFramework.IsDesktop() ?
@ -235,4 +230,4 @@ namespace Microsoft.DotNet.ProjectModel.Workspaces
public CSharpCompilationOptions CompilationOptions { get; set; }
}
}
}
}

View file

@ -1,16 +1,17 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23704",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.CodeAnalysis.CSharp.Workspaces": "1.2.0-beta1-20160108-01"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
"version": "1.0.0-*",
"compilationOptions": {
"keyFile": "../../tools/Key.snk"
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23704",
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.DotNet.Compiler.Common": "1.0.0-*",
"Microsoft.CodeAnalysis.CSharp.Workspaces": "1.2.0-beta1-20160108-01"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
}
}

View file

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;

View file

@ -124,10 +124,6 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
? "-debug:full"
: "-debug:portable");
args.Add("-nowarn:CS1701");
args.Add("-nowarn:CS1702");
args.Add("-nowarn:CS1705");
return args;
}

View file

@ -134,7 +134,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// used in incremental compilation for the key file
public static CommonCompilerOptions ResolveCompilationOptions(ProjectContext context, string configuration)
{
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var compilationOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
// Path to strong naming key in environment variable overrides path in project.json
var environmentKeyFile = Environment.GetEnvironmentVariable(EnvironmentNames.StrongNameKeyFile);

View file

@ -374,9 +374,6 @@ namespace Microsoft.DotNet.Tools.Compiler
.Execute();
}
}
private static void CopyExport(string outputPath, LibraryExport export)
{