Skip to content

Commit 68a78fa

Browse files
authored
Merge pull request #16700 from tamasvajk/buildless/tsp-warning-config
C#: Add TSP warning if `buildless` option is used instead of `build-mode`
2 parents d5af71a + 9366eb8 commit 68a78fa

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpAutobuilder.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Semmle.Autobuild.CSharp
1212
public class CSharpAutobuildOptions : AutobuildOptionsShared
1313
{
1414
private const string buildModeEnvironmentVariable = "CODEQL_EXTRACTOR_CSHARP_BUILD_MODE";
15-
private const string extractorOptionPrefix = "CODEQL_EXTRACTOR_CSHARP_OPTION_";
15+
internal const string ExtractorOptionBuildless = "CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS";
1616

1717
public bool Buildless { get; }
1818

@@ -26,7 +26,7 @@ public class CSharpAutobuildOptions : AutobuildOptionsShared
2626
public CSharpAutobuildOptions(IBuildActions actions) : base(actions)
2727
{
2828
Buildless =
29-
actions.GetEnvironmentVariable(extractorOptionPrefix + "BUILDLESS").AsBool("buildless", false) ||
29+
actions.GetEnvironmentVariable(ExtractorOptionBuildless).AsBool("buildless", false) ||
3030
actions.GetEnvironmentVariable(buildModeEnvironmentVariable)?.ToLower() == "none";
3131

3232

@@ -51,7 +51,7 @@ public override BuildScript GetBuildScript()
5151
case CSharpBuildStrategy.Buildless:
5252
// No need to check that the extractor has been executed in buildless mode
5353
attempt = BuildScript.Bind(
54-
AddBuildlessStartedDiagnostic() & new StandaloneBuildRule().Analyse(this, false),
54+
AddBuildlessWronglyConfiguredWarning() & AddBuildlessStartedDiagnostic() & new StandaloneBuildRule().Analyse(this, false),
5555
AddBuildlessEndedDiagnostic);
5656
break;
5757
case CSharpBuildStrategy.Auto:
@@ -81,6 +81,27 @@ public BuildScript CheckExtractorRun(bool warnOnFailure) =>
8181
return 1;
8282
});
8383

84+
private BuildScript AddBuildlessWronglyConfiguredWarning()
85+
{
86+
return BuildScript.Create(actions =>
87+
{
88+
if (actions.GetEnvironmentVariable(CSharpAutobuildOptions.ExtractorOptionBuildless) is null)
89+
{
90+
return 0;
91+
}
92+
93+
AddDiagnostic(new DiagnosticMessage(
94+
Options.Language,
95+
"buildless/use-build-mode",
96+
"C# was extracted with the deprecated 'buildless' option, use build-mode instead",
97+
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
98+
markdownMessage: "C# was extracted with the deprecated 'buildless' option, use build-mode instead.",
99+
severity: DiagnosticMessage.TspSeverity.Warning
100+
));
101+
return 0;
102+
});
103+
}
104+
84105
private BuildScript AddBuildlessStartedDiagnostic()
85106
{
86107
return BuildScript.Create(actions =>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var dummy = "dummy";
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 deprecated 'buildless' option, use build-mode instead.",
31+
"severity": "warning",
32+
"source": {
33+
"extractorName": "csharp",
34+
"id": "csharp/autobuilder/buildless/use-build-mode",
35+
"name": "C# was extracted with the deprecated 'buildless' option, use build-mode instead"
36+
},
37+
"visibility": {
38+
"cliSummaryTable": true,
39+
"statusPage": true,
40+
"telemetry": true
41+
}
42+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.101"
4+
}
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from create_database_utils import *
3+
from diagnostics_test_utils import *
4+
5+
os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS'] = 'true'
6+
run_codeql_database_create([], lang="csharp")
7+
8+
check_diagnostics()

0 commit comments

Comments
 (0)