Merge pull request #13030 from hvitved/csharp/warn-as-error

C#: Never treat warnings as error in the extractor
This commit is contained in:
Tom Hvitved
2023-05-08 10:46:20 +02:00
committed by GitHub
7 changed files with 41 additions and 1 deletions

View File

@@ -130,9 +130,14 @@ namespace Semmle.Extraction.CSharp
/// <returns>Modified list of arguments.</returns>
private static IEnumerable<string> AddDefaultResponse(string responseFile, IEnumerable<string> args)
{
return SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
var ret = SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
args :
new[] { "@" + responseFile }.Concat(args);
// make sure to never treat warnings as errors in the extractor:
// our version of Roslyn may report warnings that the actual build
// doesn't
return ret.Concat(new[] { "/warnaserror-" });
}
private static bool SuppressDefaultResponseFile(IEnumerable<string> args)

View File

@@ -0,0 +1,6 @@
import csharp
import semmle.code.csharp.commons.Diagnostics
from Diagnostic d
where d.getSeverity() >= 3
select d

View File

@@ -0,0 +1,4 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
var x = "unused";

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,7 @@
#!/bin/sh
# Will fail because of a warning
dotnet build
# Pretend it didn't fail, so extraction succeeds (which doesn't treat warnings as errors)
exit 0

View File

@@ -0,0 +1,7 @@
import os
from create_database_utils import *
from diagnostics_test_utils import *
run_codeql_database_create(["./build.sh"], lang="csharp", extra_args=["--extractor-option=cil=false"])
check_diagnostics()