Report projects incompatible with .NET Core

This commit is contained in:
Michael B. Gale
2023-02-15 12:14:42 +00:00
parent 61ff4c7896
commit f68c529f04
2 changed files with 30 additions and 3 deletions

View File

@@ -31,6 +31,8 @@ namespace Semmle.Autobuild.CSharp
public class CSharpAutobuilder : Autobuilder<CSharpAutobuildOptions>
{
private DotNetRule? dotNetRule;
private BuildCommandAutoRule? buildCommandAutoRule;
public CSharpAutobuilder(IBuildActions actions, CSharpAutobuildOptions options) : base(actions, options) { }
@@ -103,11 +105,12 @@ namespace Semmle.Autobuild.CSharp
(s & CheckExtractorRun(false)) |
(attemptExtractorCleanup & BuildScript.Failure);
this.dotNetRule = new DotNetRule();
this.buildCommandAutoRule = new BuildCommandAutoRule(DotNetRule.WithDotNet);
attempt =
// First try .NET Core
IntermediateAttempt(new DotNetRule().Analyse(this, true)) |
IntermediateAttempt(dotNetRule.Analyse(this, true)) |
// Then MSBuild
(() => IntermediateAttempt(new MsBuildRule().Analyse(this, true))) |
// And finally look for a script that might be a build script
@@ -164,6 +167,13 @@ namespace Semmle.Autobuild.CSharp
Diagnostic(message);
}
else if (dotNetRule is not null && dotNetRule.NotDotNetProjects.Any())
{
var message = MakeDiagnostic("dotnet-incompatible-projects", "Some projects are incompatible with .NET Core");
message.MarkdownMessage =
"CodeQL found some projects which cannot be built with .NET Core:\n" +
string.Join('\n', dotNetRule.NotDotNetProjects.Select(p => $"- `{p.FullPath}`"));
message.Severity = DiagnosticMessage.TspSeverity.Warning;
Diagnostic(message);
}

View File

@@ -15,6 +15,21 @@ namespace Semmle.Autobuild.CSharp
/// </summary>
internal class DotNetRule : IBuildRule<CSharpAutobuildOptions>
{
private IEnumerable<Project<CSharpAutobuildOptions>> notDotNetProjects;
/// <summary>
/// A list of projects which are incompatible with DotNet.
/// </summary>
public IEnumerable<Project<CSharpAutobuildOptions>> NotDotNetProjects
{
get { return this.notDotNetProjects; }
}
public DotNetRule()
{
this.notDotNetProjects = new List<Project<CSharpAutobuildOptions>>();
}
public BuildScript Analyse(IAutobuilder<CSharpAutobuildOptions> builder, bool auto)
{
if (!builder.ProjectsOrSolutionsToBuild.Any())
@@ -22,10 +37,12 @@ namespace Semmle.Autobuild.CSharp
if (auto)
{
var notDotNetProject = builder.ProjectsOrSolutionsToBuild
notDotNetProjects = builder.ProjectsOrSolutionsToBuild
.SelectMany(p => Enumerators.Singleton(p).Concat(p.IncludedProjects))
.OfType<Project<CSharpAutobuildOptions>>()
.FirstOrDefault(p => !p.DotNetProject);
.Where(p => !p.DotNetProject);
var notDotNetProject = notDotNetProjects.FirstOrDefault();
if (notDotNetProject is not null)
{
builder.Log(Severity.Info, "Not using .NET Core because of incompatible project {0}", notDotNetProject);