Skip to content

Commit bdbcaab

Browse files
committed
Use relative paths
1 parent 1e2329d commit bdbcaab

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using Semmle.Extraction.CSharp;
1+
using Semmle.Extraction.CSharp;
22
using Semmle.Util.Logging;
33
using Semmle.Autobuild.Shared;
44
using Semmle.Util;
55
using System.Linq;
6-
using System.Collections.Generic;
76

87
namespace Semmle.Autobuild.CSharp
98
{
@@ -99,6 +98,7 @@ protected override void AutobuildFailureDiagnostic()
9998
if (this.autoBuildRule.BuildCommandAutoRule.ScriptPath is not null)
10099
{
101100
DiagnosticMessage message;
101+
var relScriptPath = this.MakeRelative(autoBuildRule.BuildCommandAutoRule.ScriptPath);
102102

103103
// if we found multiple build scripts in the project directory, then we can say
104104
// as much to indicate that we may have picked the wrong one;
@@ -108,7 +108,7 @@ protected override void AutobuildFailureDiagnostic()
108108
message = MakeDiagnostic("multiple-build-scripts", "There are multiple potential build scripts");
109109
message.MarkdownMessage =
110110
"CodeQL found multiple potential build scripts for your project and " +
111-
$"attempted to run `{autoBuildRule.BuildCommandAutoRule.ScriptPath}`, which failed. " +
111+
$"attempted to run `{relScriptPath}`, which failed. " +
112112
"This may not be the right build script for your project. " +
113113
$"Set up a [manual build command]({buildCommandDocsUrl}).";
114114
}
@@ -117,7 +117,7 @@ protected override void AutobuildFailureDiagnostic()
117117
message = MakeDiagnostic("script-failure", "Unable to build project using build script");
118118
message.MarkdownMessage =
119119
"CodeQL attempted to build your project using a script located at " +
120-
$"`{autoBuildRule.BuildCommandAutoRule.ScriptPath}`, which failed. " +
120+
$"`{relScriptPath}`, which failed. " +
121121
$"Set up a [manual build command]({buildCommandDocsUrl}).";
122122
}
123123

@@ -142,7 +142,7 @@ protected override void AutobuildFailureDiagnostic()
142142
var message = MakeDiagnostic("dotnet-incompatible-projects", "Some projects are incompatible with .NET Core");
143143
message.MarkdownMessage =
144144
"CodeQL found some projects which cannot be built with .NET Core:\n" +
145-
autoBuildRule.DotNetRule.NotDotNetProjects.ToMarkdownList(5);
145+
autoBuildRule.DotNetRule.NotDotNetProjects.Select(p => this.MakeRelative(p.FullPath)).ToMarkdownList(MarkdownUtil.CodeFormatter, 5);
146146
message.Severity = DiagnosticMessage.TspSeverity.Warning;
147147

148148
AddDiagnostic(message);
@@ -154,7 +154,7 @@ protected override void AutobuildFailureDiagnostic()
154154
var message = MakeDiagnostic("dotnet-build-failure", "Some projects or solutions failed to build using .NET Core");
155155
message.MarkdownMessage =
156156
"CodeQL was unable to build the following projects using .NET Core:\n" +
157-
autoBuildRule.DotNetRule.FailedProjectsOrSolutions.ToMarkdownList(10) +
157+
autoBuildRule.DotNetRule.FailedProjectsOrSolutions.Select(p => this.MakeRelative(p.FullPath)).ToMarkdownList(MarkdownUtil.CodeFormatter, 10) +
158158
$"\nSet up a [manual build command]({buildCommandDocsUrl}).";
159159
message.Severity = DiagnosticMessage.TspSeverity.Error;
160160

@@ -167,7 +167,7 @@ protected override void AutobuildFailureDiagnostic()
167167
var message = MakeDiagnostic("msbuild-build-failure", "Some projects or solutions failed to build using MSBuild");
168168
message.MarkdownMessage =
169169
"CodeQL was unable to build the following projects using MSBuild:\n" +
170-
autoBuildRule.MsBuildRule.FailedProjectsOrSolutions.ToMarkdownList(10) +
170+
autoBuildRule.MsBuildRule.FailedProjectsOrSolutions.Select(p => this.MakeRelative(p.FullPath)).ToMarkdownList(MarkdownUtil.CodeFormatter, 10) +
171171
$"\nSet up a [manual build command]({buildCommandDocsUrl}).";
172172
message.Severity = DiagnosticMessage.TspSeverity.Error;
173173

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public DiagnosticMessage ToDiagnosticMessage<T>(Autobuilder<T> builder) where T
8282
);
8383
diag.MarkdownMessage =
8484
"Some project files were not found when CodeQL built your project:\n\n" +
85-
this.MissingProjectFiles.AsEnumerable().ToMarkdownList(MarkdownUtil.CodeFormatter, 5) +
85+
this.MissingProjectFiles.AsEnumerable().Select(p => builder.MakeRelative(p)).ToMarkdownList(MarkdownUtil.CodeFormatter, 5) +
8686
"\n\nThis may lead to subsequent failures. " +
8787
"You can check for common causes for missing project files:\n\n" +
8888
$"- Ensure that the project is built using the {runsOnDocsUrl.ToMarkdownLink("intended operating system")} and that filenames on case-sensitive platforms are correctly specified.\n" +

csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ protected string RequireEnvironmentVariable(string name)
270270

271271
private readonly DiagnosticsStream diagnostics;
272272

273+
/// <summary>
274+
/// Makes <see cref="path" /> relative to the root source directory.
275+
/// </summary>
276+
/// <param name="path">The path which to make relative.</param>
277+
/// <returns>The relative path.</returns>
278+
public string MakeRelative(string path)
279+
{
280+
return Path.GetRelativePath(this.RootDirectory, path);
281+
}
282+
273283
/// <summary>
274284
/// Log a given build event to the console.
275285
/// </summary>

0 commit comments

Comments
 (0)