mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Merge pull request #16700 from tamasvajk/buildless/tsp-warning-config
C#: Add TSP warning if `buildless` option is used instead of `build-mode`
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
public class CSharpAutobuildOptions : AutobuildOptionsShared
|
||||
{
|
||||
private const string buildModeEnvironmentVariable = "CODEQL_EXTRACTOR_CSHARP_BUILD_MODE";
|
||||
private const string extractorOptionPrefix = "CODEQL_EXTRACTOR_CSHARP_OPTION_";
|
||||
internal const string ExtractorOptionBuildless = "CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS";
|
||||
|
||||
public bool Buildless { get; }
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
public CSharpAutobuildOptions(IBuildActions actions) : base(actions)
|
||||
{
|
||||
Buildless =
|
||||
actions.GetEnvironmentVariable(extractorOptionPrefix + "BUILDLESS").AsBool("buildless", false) ||
|
||||
actions.GetEnvironmentVariable(ExtractorOptionBuildless).AsBool("buildless", false) ||
|
||||
actions.GetEnvironmentVariable(buildModeEnvironmentVariable)?.ToLower() == "none";
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Semmle.Autobuild.CSharp
|
||||
case CSharpBuildStrategy.Buildless:
|
||||
// No need to check that the extractor has been executed in buildless mode
|
||||
attempt = BuildScript.Bind(
|
||||
AddBuildlessStartedDiagnostic() & new StandaloneBuildRule().Analyse(this, false),
|
||||
AddBuildlessWronglyConfiguredWarning() & AddBuildlessStartedDiagnostic() & new StandaloneBuildRule().Analyse(this, false),
|
||||
AddBuildlessEndedDiagnostic);
|
||||
break;
|
||||
case CSharpBuildStrategy.Auto:
|
||||
@@ -81,6 +81,27 @@ namespace Semmle.Autobuild.CSharp
|
||||
return 1;
|
||||
});
|
||||
|
||||
private BuildScript AddBuildlessWronglyConfiguredWarning()
|
||||
{
|
||||
return BuildScript.Create(actions =>
|
||||
{
|
||||
if (actions.GetEnvironmentVariable(CSharpAutobuildOptions.ExtractorOptionBuildless) is null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
AddDiagnostic(new DiagnosticMessage(
|
||||
Options.Language,
|
||||
"buildless/use-build-mode",
|
||||
"C# was extracted with the deprecated 'buildless' option, use build-mode instead",
|
||||
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
|
||||
markdownMessage: "C# was extracted with the deprecated 'buildless' option, use build-mode instead.",
|
||||
severity: DiagnosticMessage.TspSeverity.Warning
|
||||
));
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
private BuildScript AddBuildlessStartedDiagnostic()
|
||||
{
|
||||
return BuildScript.Create(actions =>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
var dummy = "dummy";
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"markdownMessage": "C# analysis with build-mode 'none' completed.",
|
||||
"severity": "unknown",
|
||||
"source": {
|
||||
"extractorName": "csharp",
|
||||
"id": "csharp/autobuilder/buildless/complete",
|
||||
"name": "C# analysis with build-mode 'none' completed"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": true,
|
||||
"statusPage": false,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
{
|
||||
"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.",
|
||||
"severity": "note",
|
||||
"source": {
|
||||
"extractorName": "csharp",
|
||||
"id": "csharp/autobuilder/buildless/mode-active",
|
||||
"name": "C# was extracted with build-mode set to 'none'"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": true,
|
||||
"statusPage": true,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
{
|
||||
"markdownMessage": "C# was extracted with the deprecated 'buildless' option, use build-mode instead.",
|
||||
"severity": "warning",
|
||||
"source": {
|
||||
"extractorName": "csharp",
|
||||
"id": "csharp/autobuilder/buildless/use-build-mode",
|
||||
"name": "C# was extracted with the deprecated 'buildless' option, use build-mode instead"
|
||||
},
|
||||
"visibility": {
|
||||
"cliSummaryTable": true,
|
||||
"statusPage": true,
|
||||
"telemetry": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "8.0.101"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
from create_database_utils import *
|
||||
from diagnostics_test_utils import *
|
||||
|
||||
os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS'] = 'true'
|
||||
run_codeql_database_create([], lang="csharp")
|
||||
|
||||
check_diagnostics()
|
||||
Reference in New Issue
Block a user