C#: Add support to the extractor for getting the compression extractor option.

This commit is contained in:
Michael Nebel
2022-02-22 13:46:20 +01:00
parent bca479c2f3
commit 6176b64907
3 changed files with 34 additions and 1 deletions

View File

@@ -46,7 +46,9 @@ namespace Semmle.Extraction.CSharp
var argsList = new List<string>(arguments);
if (!string.IsNullOrEmpty(extractionOptions))
{
argsList.AddRange(extractionOptions.Split(' '));
}
options.ParseArguments(argsList);
return options;

View File

@@ -1,3 +1,4 @@
using System;
using Semmle.Util.Logging;
using Semmle.Util;
@@ -49,6 +50,7 @@ namespace Semmle.Extraction
/// </summary>
public bool QlTest { get; private set; } = false;
/// <summary>
/// The compression algorithm used for trap files.
/// </summary>
@@ -64,6 +66,16 @@ namespace Semmle.Extraction
case "verbosity":
Verbosity = (Verbosity)int.Parse(value);
return true;
case "compression":
try
{
TrapCompression = (TrapWriter.CompressionMode)Enum.Parse(typeof(TrapWriter.CompressionMode), value, true);
return true;
}
catch (ArgumentException)
{
return false;
}
default:
return false;
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
namespace Semmle.Util
@@ -39,8 +40,26 @@ namespace Semmle.Util
public static class OptionsExtensions
{
public static void ParseArguments(this ICommandLineOptions options, IReadOnlyList<string> arguments)
private static string? GetExtractorOption(string name) =>
Environment.GetEnvironmentVariable($"CODEQL_EXTRACTOR_CSHARP_OPTION_{name.ToUpper()}");
private static List<string> GetExtractorOptions()
{
var extractorOptions = new List<string>();
var compressionMode = GetExtractorOption("compression");
if (!string.IsNullOrEmpty(compressionMode))
{
extractorOptions.Add($"--compression:{compressionMode}");
}
return extractorOptions;
}
public static void ParseArguments(this ICommandLineOptions options, IReadOnlyList<string> providedArguments)
{
var arguments = GetExtractorOptions();
arguments.AddRange(providedArguments);
for (var i = 0; i < arguments.Count; ++i)
{
var arg = arguments[i];