Skip to content

Commit fe62900

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

File tree

12 files changed

+132
-6
lines changed

12 files changed

+132
-6
lines changed

csharp/codeql-extractor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ options:
7070
description: >
7171
[EXPERIMENTAL] The value is a path to the MsBuild binary log file that should be extracted.
7272
This option only works when `--build-mode none` is also specified.
73-
type: string
73+
type: array

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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"markdownMessage": "C# analysis with build-mode 'none' completed.",
3+
"severity": "unknown",
4+
"source": {
5+
"extractorName": "csharp",
6+
"id": "csharp/autobuilder/buildless/complete",
7+
"name": "C# analysis with build-mode 'none' completed"
8+
},
9+
"visibility": {
10+
"cliSummaryTable": true,
11+
"statusPage": false,
12+
"telemetry": true
13+
}
14+
}
15+
{
16+
"markdownMessage": "C# was extracted with build-mode set to 'none'. This means that all C# source in the working directory will be scanned, with build tools, such as Nuget and Dotnet CLIs, only contributing information about external dependencies.",
17+
"severity": "note",
18+
"source": {
19+
"extractorName": "csharp",
20+
"id": "csharp/autobuilder/buildless/mode-active",
21+
"name": "C# was extracted with build-mode set to 'none'"
22+
},
23+
"visibility": {
24+
"cliSummaryTable": true,
25+
"statusPage": true,
26+
"telemetry": true
27+
}
28+
}
29+
{
30+
"markdownMessage": "C# was extracted with the experimental 'binlog' option.",
31+
"severity": "note",
32+
"source": {
33+
"extractorName": "csharp",
34+
"id": "csharp/autobuilder/buildless/binlog",
35+
"name": "C# was extracted with the experimental 'binlog' option"
36+
},
37+
"visibility": {
38+
"cliSummaryTable": true,
39+
"statusPage": true,
40+
"telemetry": true
41+
}
42+
}

0 commit comments

Comments
 (0)