Skip to content

Commit b39f383

Browse files
authored
Merge pull request #8230 from michaelnebel/csharp/autobuilder-buildless
C#: Buildless extractor option.
2 parents fff4250 + 938902d commit b39f383

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ private CSharpAutobuilder CreateAutoBuilder(bool isWindows,
399399
actions.GetEnvironmentVariable["LGTM_INDEX_SOLUTION"] = solution;
400400
actions.GetEnvironmentVariable["LGTM_INDEX_IGNORE_ERRORS"] = ignoreErrors;
401401
actions.GetEnvironmentVariable["LGTM_INDEX_BUILDLESS"] = buildless;
402+
actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS"] = buildless;
402403
actions.GetEnvironmentVariable["LGTM_INDEX_ALL_SOLUTIONS"] = allSolutions;
403404
actions.GetEnvironmentVariable["LGTM_INDEX_NUGET_RESTORE"] = nugetRestore;
404405
actions.GetEnvironmentVariable["ProgramFiles(x86)"] = isWindows ? @"C:\Program Files (x86)" : null;

csharp/autobuilder/Semmle.Autobuild.Shared/AutobuildOptions.cs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace Semmle.Autobuild.Shared
1010
/// </summary>
1111
public class AutobuildOptions
1212
{
13-
private const string prefix = "LGTM_INDEX_";
13+
private const string lgtmPrefix = "LGTM_INDEX_";
14+
private const string extractorOptionPrefix = "CODEQL_EXTRACTOR_CSHARP_OPTION_";
1415

1516
public int SearchDepth { get; } = 3;
1617
public string RootDirectory { get; }
@@ -36,20 +37,21 @@ public class AutobuildOptions
3637
public AutobuildOptions(IBuildActions actions, Language language)
3738
{
3839
RootDirectory = actions.GetCurrentDirectory();
39-
VsToolsVersion = actions.GetEnvironmentVariable(prefix + "VSTOOLS_VERSION");
40-
MsBuildArguments = actions.GetEnvironmentVariable(prefix + "MSBUILD_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
41-
MsBuildPlatform = actions.GetEnvironmentVariable(prefix + "MSBUILD_PLATFORM");
42-
MsBuildConfiguration = actions.GetEnvironmentVariable(prefix + "MSBUILD_CONFIGURATION");
43-
MsBuildTarget = actions.GetEnvironmentVariable(prefix + "MSBUILD_TARGET");
44-
DotNetArguments = actions.GetEnvironmentVariable(prefix + "DOTNET_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
45-
DotNetVersion = actions.GetEnvironmentVariable(prefix + "DOTNET_VERSION");
46-
BuildCommand = actions.GetEnvironmentVariable(prefix + "BUILD_COMMAND");
47-
Solution = actions.GetEnvironmentVariable(prefix + "SOLUTION").AsListWithExpandedEnvVars(actions, Array.Empty<string>());
40+
VsToolsVersion = actions.GetEnvironmentVariable(lgtmPrefix + "VSTOOLS_VERSION");
41+
MsBuildArguments = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
42+
MsBuildPlatform = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_PLATFORM");
43+
MsBuildConfiguration = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_CONFIGURATION");
44+
MsBuildTarget = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_TARGET");
45+
DotNetArguments = actions.GetEnvironmentVariable(lgtmPrefix + "DOTNET_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
46+
DotNetVersion = actions.GetEnvironmentVariable(lgtmPrefix + "DOTNET_VERSION");
47+
BuildCommand = actions.GetEnvironmentVariable(lgtmPrefix + "BUILD_COMMAND");
48+
Solution = actions.GetEnvironmentVariable(lgtmPrefix + "SOLUTION").AsListWithExpandedEnvVars(actions, Array.Empty<string>());
4849

49-
IgnoreErrors = actions.GetEnvironmentVariable(prefix + "IGNORE_ERRORS").AsBool("ignore_errors", false);
50-
Buildless = actions.GetEnvironmentVariable(prefix + "BUILDLESS").AsBool("buildless", false);
51-
AllSolutions = actions.GetEnvironmentVariable(prefix + "ALL_SOLUTIONS").AsBool("all_solutions", false);
52-
NugetRestore = actions.GetEnvironmentVariable(prefix + "NUGET_RESTORE").AsBool("nuget_restore", true);
50+
IgnoreErrors = actions.GetEnvironmentVariable(lgtmPrefix + "IGNORE_ERRORS").AsBool("ignore_errors", false);
51+
Buildless = actions.GetEnvironmentVariable(lgtmPrefix + "BUILDLESS").AsBool("buildless", false) ||
52+
actions.GetEnvironmentVariable(extractorOptionPrefix + "BUILDLESS").AsBool("buildless", false);
53+
AllSolutions = actions.GetEnvironmentVariable(lgtmPrefix + "ALL_SOLUTIONS").AsBool("all_solutions", false);
54+
NugetRestore = actions.GetEnvironmentVariable(lgtmPrefix + "NUGET_RESTORE").AsBool("nuget_restore", true);
5355

5456
Language = language;
5557
}
@@ -62,21 +64,12 @@ public static bool AsBool(this string? value, string param, bool defaultValue)
6264
if (value is null)
6365
return defaultValue;
6466

65-
switch (value.ToLower())
67+
return value.ToLower() switch
6668
{
67-
case "on":
68-
case "yes":
69-
case "true":
70-
case "enabled":
71-
return true;
72-
case "off":
73-
case "no":
74-
case "false":
75-
case "disabled":
76-
return false;
77-
default:
78-
throw new ArgumentOutOfRangeException(param, value, "The Boolean value is invalid.");
79-
}
69+
"on" or "yes" or "true" or "enabled" => true,
70+
"off" or "no" or "false" or "disabled" => false,
71+
_ => throw new ArgumentOutOfRangeException(param, value, "The Boolean value is invalid."),
72+
};
8073
}
8174

8275
public static string[] AsListWithExpandedEnvVars(this string? value, IBuildActions actions, string[] defaultValue)

csharp/codeql-extractor.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ options:
2929
(to write uncompressed TRAP).
3030
type: string
3131
pattern: "^(none|gzip|brotli)$"
32+
buildless:
33+
title: Whether to use buildless (standalone) extraction.
34+
description: >
35+
A value indicating, which type of extraction the autobuilder should perform.
36+
If 'true', then the standalone extractor will be used, otherwise tracing extraction
37+
will be performed.
38+
The default is 'false'.
39+
Note that buildless extraction will generally yield less accurate analysis results,
40+
and should only be used in cases where it is not possible to build
41+
the code (for example if it uses inaccessible dependencies).
42+
type: string
43+
pattern: "^(false|true)$"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The C# extractor now accepts an extractor option `buildless`, which is used to decide what type of extraction that should be performed. If `true` then buildless (standalone) extraction will be performed. Otherwise tracing extraction will be performed (default).
5+
The option is added via `codeql database create --language=csharp -Obuildless=true ...`.

0 commit comments

Comments
 (0)