Skip to content

Commit d4ec4a0

Browse files
committed
Add nowarn compiler option
1 parent 8a8d0eb commit d4ec4a0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/IncrementalCompiler/CompileOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class CompileOptions
2929
[DataMember] public List<string> Defines = new List<string>();
3030
[DataMember] public List<string> References = new List<string>();
3131
[DataMember] public List<string> Files = new List<string>();
32+
[DataMember] public List<string> NoWarnings = new List<string>();
3233
[DataMember] public DebugSymbolFileType DebugSymbolFile;
3334
[DataMember] public PrebuiltOutputReuseType PrebuiltOutputReuse;
3435

@@ -68,6 +69,17 @@ public void ParseArgument(string[] args)
6869
Output = value.Trim('"');
6970
AssemblyName = Path.GetFileNameWithoutExtension(value);
7071
break;
72+
73+
case "nowarn":
74+
foreach (var id in value.Split(new char[] {',', ';', ' '},
75+
StringSplitOptions.RemoveEmptyEntries))
76+
{
77+
int num;
78+
NoWarnings.Add(int.TryParse(id, out num)
79+
? string.Format("CS{0:0000}", num)
80+
: id);
81+
}
82+
break;
7183
}
7284
}
7385
else if (arg.StartsWith("@"))

core/IncrementalCompiler/Compiler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public CompileResult Build(CompileOptions options)
3030
_options.WorkDirectory != options.WorkDirectory ||
3131
_options.AssemblyName != options.AssemblyName ||
3232
_options.Output != options.Output ||
33+
_options.NoWarnings.SequenceEqual(options.NoWarnings) == false ||
3334
_options.Defines.SequenceEqual(options.Defines) == false)
3435
{
3536
return BuildFull(options);
@@ -62,11 +63,13 @@ private CompileResult BuildFull(CompileOptions options)
6263
file => file,
6364
file => ParseSource(file, parseOption));
6465

66+
var specificDiagnosticOptions = options.NoWarnings.ToDictionary(x => x, _ => ReportDiagnostic.Suppress);
6567
_compilation = CSharpCompilation.Create(
6668
options.AssemblyName,
6769
_sourceMap.Values,
6870
_referenceMap.Values,
69-
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
71+
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
72+
.WithSpecificDiagnosticOptions(specificDiagnosticOptions));
7073

7174
Emit(result);
7275

0 commit comments

Comments
 (0)