Skip to content

Commit 0c5ea97

Browse files
authored
Merge pull request github#16021 from tamasvajk/feature/add-buildless-telemetry
C#: Add high level diagnostic messages for buildless extraction (star…
2 parents a950de3 + 2f0b54c commit 0c5ea97

File tree

9 files changed

+135
-2
lines changed

9 files changed

+135
-2
lines changed

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public override BuildScript GetBuildScript()
5151
break;
5252
case CSharpBuildStrategy.Buildless:
5353
// No need to check that the extractor has been executed in buildless mode
54-
attempt = new StandaloneBuildRule().Analyse(this, false);
54+
attempt = BuildScript.Bind(
55+
AddBuildlessStartedDiagnostic() & new StandaloneBuildRule().Analyse(this, false),
56+
AddBuildlessEndedDiagnostic);
5557
break;
5658
case CSharpBuildStrategy.MSBuild:
5759
attempt = new MsBuildRule().Analyse(this, false) & CheckExtractorRun(true);
@@ -86,6 +88,52 @@ public BuildScript CheckExtractorRun(bool warnOnFailure) =>
8688
return 1;
8789
});
8890

91+
private BuildScript AddBuildlessStartedDiagnostic()
92+
{
93+
return BuildScript.Create(actions =>
94+
{
95+
AddDiagnostic(new DiagnosticMessage(
96+
Options.Language,
97+
"buildless/mode-active",
98+
"C# with build-mode set to 'none'",
99+
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
100+
markdownMessage: "C# 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.",
101+
severity: DiagnosticMessage.TspSeverity.Note
102+
));
103+
return 0;
104+
});
105+
}
106+
107+
private BuildScript AddBuildlessEndedDiagnostic(int buildResult)
108+
{
109+
return BuildScript.Create(actions =>
110+
{
111+
if (buildResult == 0)
112+
{
113+
AddDiagnostic(new DiagnosticMessage(
114+
Options.Language,
115+
"buildless/complete",
116+
"C# analysis with build-mode 'none' completed",
117+
visibility: new DiagnosticMessage.TspVisibility(statusPage: false, cliSummaryTable: true, telemetry: true),
118+
markdownMessage: "C# analysis with build-mode 'none' completed.",
119+
severity: DiagnosticMessage.TspSeverity.Unknown
120+
));
121+
}
122+
else
123+
{
124+
AddDiagnostic(new DiagnosticMessage(
125+
Options.Language,
126+
"buildless/failed",
127+
"C# analysis with build-mode 'none' failed",
128+
visibility: new DiagnosticMessage.TspVisibility(statusPage: true, cliSummaryTable: true, telemetry: true),
129+
markdownMessage: "C# analysis with build-mode 'none' failed.",
130+
severity: DiagnosticMessage.TspSeverity.Error
131+
));
132+
}
133+
return buildResult;
134+
});
135+
}
136+
89137
protected override void AutobuildFailureDiagnostic()
90138
{
91139
// if `ScriptPath` is not null here, the `BuildCommandAuto` rule was

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ private void ResolveConflicts(IEnumerable<string> frameworkPaths)
728728
/// </summary>
729729
public IEnumerable<string> GeneratedSourceFiles => generatedSources;
730730

731+
/// <summary>
732+
/// All of the non-generated source files in the source directory.
733+
/// </summary>
734+
public IEnumerable<string> NonGeneratedSourcesFiles => nonGeneratedSources;
735+
731736
/// <summary>
732737
/// All of the source files in the source directory.
733738
/// </summary>

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Extractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static ExitCode Run(Options options)
146146
logger.Log(Severity.Info, "Extracting C# in buildless mode");
147147
using var dependencyManager = new DependencyManager(options.SrcDir, logger);
148148

149-
if (!dependencyManager.AllSourceFiles.Any())
149+
if (!dependencyManager.NonGeneratedSourcesFiles.Any())
150150
{
151151
logger.Log(Severity.Error, "No source files found");
152152
return ExitCode.Errors;

csharp/extractor/Semmle.Util/ToolStatusPage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public TspSource(string id, string name, string? extractorName = null)
4646
[JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
4747
public enum TspSeverity
4848
{
49+
Unknown,
4950
Note,
5051
Warning,
5152
Error
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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# 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# with build-mode set to 'none'"
22+
},
23+
"visibility": {
24+
"cliSummaryTable": true,
25+
"statusPage": true,
26+
"telemetry": true
27+
}
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
from create_database_utils import *
3+
from diagnostics_test_utils import *
34

45
os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_COMPILER_DIAGNOSTIC_LIMIT'] = '2'
56
os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_MESSAGE_LIMIT'] = '5'
67
run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"])
8+
9+
check_diagnostics()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"markdownMessage": "C# analysis with build-mode 'none' failed.",
3+
"severity": "error",
4+
"source": {
5+
"extractorName": "csharp",
6+
"id": "csharp/autobuilder/buildless/failed",
7+
"name": "C# analysis with build-mode 'none' failed"
8+
},
9+
"visibility": {
10+
"cliSummaryTable": true,
11+
"statusPage": true,
12+
"telemetry": true
13+
}
14+
}
15+
{
16+
"markdownMessage": "C# 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# with build-mode set to 'none'"
22+
},
23+
"visibility": {
24+
"cliSummaryTable": true,
25+
"statusPage": true,
26+
"telemetry": true
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<Target Name="DeleteBinObjFolders" BeforeTargets="Clean">
11+
<RemoveDir Directories=".\bin" />
12+
<RemoveDir Directories=".\obj" />
13+
</Target>
14+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from create_database_utils import *
2+
from diagnostics_test_utils import *
3+
4+
run_codeql_database_create([], db=None, lang="csharp", extra_args=["--build-mode=none"], runFunction=runUnsuccessfully)
5+
6+
check_diagnostics()

0 commit comments

Comments
 (0)