C#: Change extractor to accept multiple binlog files

This commit is contained in:
Tamas Vajk
2024-11-11 12:08:37 +01:00
parent e3662fa97f
commit fe62900a15
12 changed files with 132 additions and 6 deletions

View File

@@ -106,10 +106,10 @@ namespace Semmle.Extraction.CSharp
var canonicalPathCache = CanonicalPathCache.Create(logger, 1000);
var pathTransformer = new PathTransformer(canonicalPathCache);
if (options.BinaryLogPath is string binlogPath)
if (options.BinaryLogPaths is string[] binlogPaths)
{
logger.LogInfo(" Running binary log analysis.");
return RunBinaryLogAnalysis(analyzerStopwatch, options, binlogPath, logger, canonicalPathCache, pathTransformer);
return RunBinaryLogAnalysis(analyzerStopwatch, options, binlogPaths, logger, canonicalPathCache, pathTransformer);
}
else
{
@@ -124,6 +124,25 @@ namespace Semmle.Extraction.CSharp
}
}
private static ExitCode RunBinaryLogAnalysis(Stopwatch stopwatch, Options options, string[] binlogPaths, ILogger logger, CanonicalPathCache canonicalPathCache, PathTransformer pathTransformer)
{
var allFailed = true;
foreach (var binlogPath in binlogPaths)
{
var exit = RunBinaryLogAnalysis(stopwatch, options, binlogPath, logger, canonicalPathCache, pathTransformer);
switch (exit)
{
case ExitCode.Ok:
case ExitCode.Errors:
allFailed &= false;
break;
case ExitCode.Failed:
break;
}
}
return allFailed ? ExitCode.Failed : ExitCode.Ok;
}
private static ExitCode RunBinaryLogAnalysis(Stopwatch stopwatch, Options options, string binlogPath, ILogger logger, CanonicalPathCache canonicalPathCache, PathTransformer pathTransformer)
{
logger.LogInfo($"Reading compiler calls from binary log {binlogPath}");

View File

@@ -33,9 +33,9 @@ namespace Semmle.Extraction.CSharp
public bool AssemblySensitiveTrap { get; private set; } = false;
/// <summary>
/// The path to the binary log file, or null if unspecified.
/// The paths to the binary log files, or null if unspecified.
/// </summary>
public string? BinaryLogPath { get; set; }
public string[]? BinaryLogPaths { get; set; }
public static Options CreateWithEnvironment(string[] arguments)
{
@@ -71,7 +71,7 @@ namespace Semmle.Extraction.CSharp
ProjectsToLoad.Add(value);
return true;
case "binlog":
BinaryLogPath = value;
BinaryLogPaths = value.Split(FileUtils.NewLineCharacters, StringSplitOptions.RemoveEmptyEntries);
return true;
default:
return base.HandleOption(key, value);