mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #20849 from michaelnebel/csharp/addcompilationerrorstodebuglogbmn
C#: Add compilation errors to the debug log in BMN.
This commit is contained in:
@@ -360,5 +360,22 @@ namespace Semmle.Extraction.CSharp
|
||||
return versionString.InformationalVersion;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> errorsToIgnore = new HashSet<string>
|
||||
{
|
||||
"CS7027", // Code signing failure
|
||||
"CS1589", // XML referencing not supported
|
||||
"CS1569" // Error writing XML documentation
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the diagnostics from the compilation, filtering out those that should be ignored.
|
||||
/// </summary>
|
||||
protected List<Diagnostic> GetFilteredDiagnostics() =>
|
||||
compilation is not null
|
||||
? compilation.GetDiagnostics()
|
||||
.Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id))
|
||||
.ToList()
|
||||
: [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,14 @@ namespace Semmle.Extraction.CSharp
|
||||
{
|
||||
}
|
||||
|
||||
private void LogDiagnostics()
|
||||
{
|
||||
foreach (var error in GetFilteredDiagnostics())
|
||||
{
|
||||
Logger.LogDebug($" Compilation error: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(string outputPath, IEnumerable<(string, string)> compilationInfos, CSharpCompilation compilationIn, CommonOptions options)
|
||||
{
|
||||
compilation = compilationIn;
|
||||
@@ -20,6 +28,7 @@ namespace Semmle.Extraction.CSharp
|
||||
this.options = options;
|
||||
LogExtractorInfo();
|
||||
SetReferencePaths();
|
||||
LogDiagnostics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,11 +136,7 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
private int LogDiagnostics()
|
||||
{
|
||||
var filteredDiagnostics = compilation!
|
||||
.GetDiagnostics()
|
||||
.Where(e => e.Severity >= DiagnosticSeverity.Error && !errorsToIgnore.Contains(e.Id))
|
||||
.ToList();
|
||||
|
||||
var filteredDiagnostics = GetFilteredDiagnostics();
|
||||
foreach (var error in filteredDiagnostics)
|
||||
{
|
||||
Logger.LogError($" Compilation error: {error}");
|
||||
@@ -148,7 +144,7 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
if (filteredDiagnostics.Count != 0)
|
||||
{
|
||||
foreach (var reference in compilation.References)
|
||||
foreach (var reference in compilation!.References)
|
||||
{
|
||||
Logger.LogInfo($" Resolved reference {reference.Display}");
|
||||
}
|
||||
@@ -156,12 +152,5 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
return filteredDiagnostics.Count;
|
||||
}
|
||||
|
||||
private static readonly HashSet<string> errorsToIgnore = new HashSet<string>
|
||||
{
|
||||
"CS7027", // Code signing failure
|
||||
"CS1589", // XML referencing not supported
|
||||
"CS1569" // Error writing XML documentation
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Compilation errors are now included in the debug log when using build-mode none.
|
||||
Reference in New Issue
Block a user