Skip to content

Commit ededd46

Browse files
authored
Merge pull request github#13030 from hvitved/csharp/warn-as-error
C#: Never treat warnings as error in the extractor
2 parents 7323d4e + ba5025d commit ededd46

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Extractor/CompilerVersion.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,14 @@ public bool SkipExtraction
130130
/// <returns>Modified list of arguments.</returns>
131131
private static IEnumerable<string> AddDefaultResponse(string responseFile, IEnumerable<string> args)
132132
{
133-
return SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
133+
var ret = SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
134134
args :
135135
new[] { "@" + responseFile }.Concat(args);
136+
137+
// make sure to never treat warnings as errors in the extractor:
138+
// our version of Roslyn may report warnings that the actual build
139+
// doesn't
140+
return ret.Concat(new[] { "/warnaserror-" });
136141
}
137142

138143
private static bool SuppressDefaultResponseFile(IEnumerable<string> args)

csharp/ql/integration-tests/posix-only/warn_as_error/Errors.expected

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import csharp
2+
import semmle.code.csharp.commons.Diagnostics
3+
4+
from Diagnostic d
5+
where d.getSeverity() >= 3
6+
select d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// See https://aka.ms/new-console-template for more information
2+
Console.WriteLine("Hello, World!");
3+
4+
var x = "unused";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Will fail because of a warning
4+
dotnet build
5+
6+
# Pretend it didn't fail, so extraction succeeds (which doesn't treat warnings as errors)
7+
exit 0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
from create_database_utils import *
3+
from diagnostics_test_utils import *
4+
5+
run_codeql_database_create(["./build.sh"], lang="csharp", extra_args=["--extractor-option=cil=false"])
6+
7+
check_diagnostics()

0 commit comments

Comments
 (0)