Skip to content

Commit 43df639

Browse files
committed
Report projects incompatible with .NET Core
1 parent 802e231 commit 43df639

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public CSharpAutobuildOptions(IBuildActions actions) : base(actions)
3131

3232
public class CSharpAutobuilder : Autobuilder<CSharpAutobuildOptions>
3333
{
34+
private DotNetRule? dotNetRule;
35+
3436
private BuildCommandAutoRule? buildCommandAutoRule;
3537

3638
public CSharpAutobuilder(IBuildActions actions, CSharpAutobuildOptions options) : base(actions, options) { }
@@ -103,11 +105,12 @@ BuildScript IntermediateAttempt(BuildScript s) =>
103105
(s & CheckExtractorRun(false)) |
104106
(attemptExtractorCleanup & BuildScript.Failure);
105107

108+
this.dotNetRule = new DotNetRule();
106109
this.buildCommandAutoRule = new BuildCommandAutoRule(DotNetRule.WithDotNet);
107110

108111
attempt =
109112
// First try .NET Core
110-
IntermediateAttempt(new DotNetRule().Analyse(this, true)) |
113+
IntermediateAttempt(dotNetRule.Analyse(this, true)) |
111114
// Then MSBuild
112115
(() => IntermediateAttempt(new MsBuildRule().Analyse(this, true))) |
113116
// And finally look for a script that might be a build script
@@ -164,6 +167,13 @@ protected override void AutobuildFailureDiagnostic()
164167

165168
Diagnostic(message);
166169
}
170+
else if (dotNetRule is not null && dotNetRule.NotDotNetProjects.Any())
171+
{
172+
var message = MakeDiagnostic("dotnet-incompatible-projects", "Some projects are incompatible with .NET Core");
173+
message.MarkdownMessage =
174+
"CodeQL found some projects which cannot be built with .NET Core:\n" +
175+
string.Join('\n', dotNetRule.NotDotNetProjects.Select(p => $"- `{p.FullPath}`"));
176+
message.Severity = DiagnosticMessage.TspSeverity.Warning;
167177

168178
Diagnostic(message);
169179
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,34 @@ namespace Semmle.Autobuild.CSharp
1515
/// </summary>
1616
internal class DotNetRule : IBuildRule<CSharpAutobuildOptions>
1717
{
18+
private IEnumerable<Project<CSharpAutobuildOptions>> notDotNetProjects;
19+
20+
/// <summary>
21+
/// A list of projects which are incompatible with DotNet.
22+
/// </summary>
23+
public IEnumerable<Project<CSharpAutobuildOptions>> NotDotNetProjects
24+
{
25+
get { return this.notDotNetProjects; }
26+
}
27+
28+
public DotNetRule()
29+
{
30+
this.notDotNetProjects = new List<Project<CSharpAutobuildOptions>>();
31+
}
32+
1833
public BuildScript Analyse(IAutobuilder<CSharpAutobuildOptions> builder, bool auto)
1934
{
2035
if (!builder.ProjectsOrSolutionsToBuild.Any())
2136
return BuildScript.Failure;
2237

2338
if (auto)
2439
{
25-
var notDotNetProject = builder.ProjectsOrSolutionsToBuild
40+
notDotNetProjects = builder.ProjectsOrSolutionsToBuild
2641
.SelectMany(p => Enumerators.Singleton(p).Concat(p.IncludedProjects))
2742
.OfType<Project<CSharpAutobuildOptions>>()
28-
.FirstOrDefault(p => !p.DotNetProject);
43+
.Where(p => !p.DotNetProject);
44+
var notDotNetProject = notDotNetProjects.FirstOrDefault();
45+
2946
if (notDotNetProject is not null)
3047
{
3148
builder.Log(Severity.Info, "Not using .NET Core because of incompatible project {0}", notDotNetProject);

0 commit comments

Comments
 (0)