C#: Change extractor to accept multiple `binlog` files · szsam/codeql@fe62900 · GitHub
Skip to content

Commit fe62900

Browse files
committed
C#: Change extractor to accept multiple binlog files
1 parent e3662fa commit fe62900

12 files changed

Lines changed: 132 additions & 6 deletions

File tree

csharp/codeql-extractor.yml

Lines changed: 1 addition & 1 deletion

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public static ExitCode Run(string[] args)
106106
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
107107
var pathTransformer = new PathTransformer(canonicalPathCache);
108108

109-
if (options.BinaryLogPath is string binlogPath)
109+
if (options.BinaryLogPaths is string[] binlogPaths)
110110
{
111111
logger.LogInfo(" Running binary log analysis.");
112-
return RunBinaryLogAnalysis(analyzerStopwatch, options, binlogPath, logger, canonicalPathCache, pathTransformer);
112+
return RunBinaryLogAnalysis(analyzerStopwatch, options, binlogPaths, logger, canonicalPathCache, pathTransformer);
113113
}
114114
else
115115
{
@@ -124,6 +124,25 @@ public static ExitCode Run(string[] args)
124124
}
125125
}
126126

127+
private static ExitCode RunBinaryLogAnalysis(Stopwatch stopwatch, Options options, string[] binlogPaths, ILogger logger, CanonicalPathCache canonicalPathCache, PathTransformer pathTransformer)
128+
{
129+
var allFailed = true;
130+
foreach (var binlogPath in binlogPaths)
131+
{
132+
var exit = RunBinaryLogAnalysis(stopwatch, options, binlogPath, logger, canonicalPathCache, pathTransformer);
133+
switch (exit)
134+
{
135+
case ExitCode.Ok:
136+
case ExitCode.Errors:
137+
allFailed &= false;
138+
break;
139+
case ExitCode.Failed:
140+
break;
141+
}
142+
}
143+
return allFailed ? ExitCode.Failed : ExitCode.Ok;
144+
}
145+
127146
private static ExitCode RunBinaryLogAnalysis(Stopwatch stopwatch, Options options, string binlogPath, ILogger logger, CanonicalPathCache canonicalPathCache, PathTransformer pathTransformer)
128147
{
129148
logger.LogInfo($"Reading compiler calls from binary log {binlogPath}");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public sealed class Options : CommonOptions
3333
public bool AssemblySensitiveTrap { get; private set; } = false;
3434

3535
/// <summary>
36-
/// The path to the binary log file, or null if unspecified.
36+
/// The paths to the binary log files, or null if unspecified.
3737
/// </summary>
38-
public string? BinaryLogPath { get; set; }
38+
public string[]? BinaryLogPaths { get; set; }
3939

4040
public static Options CreateWithEnvironment(string[] arguments)
4141
{
@@ -71,7 +71,7 @@ public override bool HandleOption(string key, string value)
7171
ProjectsToLoad.Add(value);
7272
return true;
7373
case "binlog":
74-
BinaryLogPath = value;
74+
BinaryLogPaths = value.Split(FileUtils.NewLineCharacters, StringSplitOptions.RemoveEmptyEntries);
7575
return true;
7676
default:
7777
return base.HandleOption(key, value);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| a/A.cs:0:0:0:0 | a/A.cs |
2+
| a/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs:0:0:0:0 | a/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs |
3+
| a/obj/Debug/net8.0/test.AssemblyInfo.cs:0:0:0:0 | a/obj/Debug/net8.0/test.AssemblyInfo.cs |
4+
| a/obj/Debug/net8.0/test.GlobalUsings.g.cs:0:0:0:0 | a/obj/Debug/net8.0/test.GlobalUsings.g.cs |
5+
| b/B.cs:0:0:0:0 | b/B.cs |
6+
| b/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs:0:0:0:0 | b/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs |
7+
| b/obj/Debug/net8.0/test.AssemblyInfo.cs:0:0:0:0 | b/obj/Debug/net8.0/test.AssemblyInfo.cs |
8+
| b/obj/Debug/net8.0/test.GlobalUsings.g.cs:0:0:0:0 | b/obj/Debug/net8.0/test.GlobalUsings.g.cs |
9+
| generated/a/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | generated/a/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs |
10+
| generated/b/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs:0:0:0:0 | generated/b/test.csproj (net8.0)/System.Text.RegularExpressions.Generator/System.Text.RegularExpressions.Generator.RegexGenerator/RegexGenerator.g.cs |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from File f
4+
where f.fromSource()
5+
select f
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Text.RegularExpressions;
2+
3+
var dummy = "dummy";
4+
5+
partial class Test
6+
{
7+
[GeneratedRegex("abc|def", RegexOptions.IgnoreCase, "en-US")]
8+
private static partial Regex AbcOrDefGeneratedRegex();
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Text.RegularExpressions;
2+
3+
var dummy = "dummy";
4+
5+
partial class Test
6+
{
7+
[GeneratedRegex("abc|def", RegexOptions.IgnoreCase, "en-US")]
8+
private static partial Regex AbcOrDefGeneratedRegex();
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 42 additions & 0 deletions

0 commit comments

Comments
 (0)