Skip to content

Commit b88382e

Browse files
committed
BuildCommandAutoRule: expose more information
We expose the list of candidate script paths and the chosen script path so that we can inspect them for diagnostics purposes.
1 parent 60afa6e commit b88382e

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,51 @@ namespace Semmle.Autobuild.Shared
1010
public class BuildCommandAutoRule : IBuildRule<AutobuildOptionsShared>
1111
{
1212
private readonly WithDotNet<AutobuildOptionsShared> withDotNet;
13+
private IEnumerable<string> candidatePaths;
14+
private string? scriptPath;
15+
16+
/// <summary>
17+
/// A list of paths to files in the project directory which we classified as scripts.
18+
/// </summary>
19+
public IEnumerable<string> CandidatePaths
20+
{
21+
get { return this.candidatePaths; }
22+
}
23+
24+
/// <summary>
25+
/// The path of the script we decided to run, if any.
26+
/// </summary>
27+
public string? ScriptPath
28+
{
29+
get { return this.scriptPath; }
30+
}
1331

1432
public BuildCommandAutoRule(WithDotNet<AutobuildOptionsShared> withDotNet)
1533
{
1634
this.withDotNet = withDotNet;
35+
this.candidatePaths = new List<string>();
1736
}
1837

38+
/// <summary>
39+
/// A list of extensions that we consider to be for scripts on Windows.
40+
/// </summary>
1941
private readonly IEnumerable<string> winExtensions = new List<string> {
2042
".bat",
2143
".cmd",
2244
".exe"
2345
};
2446

47+
/// <summary>
48+
/// A list of extensions that we consider to be for scripts on Linux.
49+
/// </summary>
2550
private readonly IEnumerable<string> linuxExtensions = new List<string> {
2651
"",
2752
".sh"
2853
};
2954

55+
/// <summary>
56+
/// A list of filenames without extensions that we think might be build scripts.
57+
/// </summary>
3058
private readonly IEnumerable<string> buildScripts = new List<string> {
3159
"build"
3260
};
@@ -35,9 +63,16 @@ public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool au
3563
{
3664
builder.Log(Severity.Info, "Attempting to locate build script");
3765

66+
// a list of extensions for files that we consider to be scripts on the current platform
3867
var extensions = builder.Actions.IsWindows() ? winExtensions : linuxExtensions;
68+
// a list of combined base script names with the current platform's script extensions
69+
// e.g. for Linux: build, build.sh
3970
var scripts = buildScripts.SelectMany(s => extensions.Select(e => s + e));
40-
var scriptPath = builder.Paths.Where(p => scripts.Any(p.Item1.ToLower().EndsWith)).OrderBy(p => p.Item2).Select(p => p.Item1).FirstOrDefault();
71+
// search through the files in the project directory for paths which end in one of
72+
// the names given by `scripts`, then order them by their distance from the root
73+
this.candidatePaths = builder.Paths.Where(p => scripts.Any(p.Item1.ToLower().EndsWith)).OrderBy(p => p.Item2).Select(p => p.Item1);
74+
// pick the first matching path, if there is one
75+
this.scriptPath = candidatePaths.FirstOrDefault();
4176

4277
if (scriptPath is null)
4378
return BuildScript.Failure;

0 commit comments

Comments
 (0)