mirror of
https://github.com/github/codeql.git
synced 2025-12-17 09:13:20 +01:00
This commit fixes a few issues that were identified during the last dist upgrade,
and which were introduced/revealed on 836daaf07b.
- Expand environment variables that are passed from `lgtm.yml` to the autobuilder,
for example `solution: $LGTM_SRC/mysolution.sln`.
- Distinguish between when a build rule is applied automatically and when it is applied
manually via `lgtm.yml`.
- Catch `FileNotFoundException`s when parsing project files and solution files.
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Semmle.Util.Logging;
|
|
|
|
namespace Semmle.Autobuild
|
|
{
|
|
/// <summary>
|
|
/// Auto-detection of build scripts.
|
|
/// </summary>
|
|
class BuildCommandAutoRule : IBuildRule
|
|
{
|
|
readonly IEnumerable<string> winExtensions = new List<string> {
|
|
".bat",
|
|
".cmd",
|
|
".exe"
|
|
};
|
|
|
|
readonly IEnumerable<string> linuxExtensions = new List<string> {
|
|
"",
|
|
".sh"
|
|
};
|
|
|
|
readonly IEnumerable<string> buildScripts = new List<string> {
|
|
"build"
|
|
};
|
|
|
|
public BuildScript Analyse(Autobuilder builder, bool auto)
|
|
{
|
|
builder.Log(Severity.Info, "Attempting to locate build script");
|
|
|
|
var extensions = builder.Actions.IsWindows() ? winExtensions : linuxExtensions;
|
|
var scripts = buildScripts.SelectMany(s => extensions.Select(e => s + e));
|
|
var scriptPath = builder.Paths.Where(p => scripts.Any(p.Item1.ToLower().EndsWith)).OrderBy(p => p.Item2).Select(p => p.Item1).FirstOrDefault();
|
|
|
|
if (scriptPath == null)
|
|
return BuildScript.Failure;
|
|
|
|
var chmod = new CommandBuilder(builder.Actions);
|
|
chmod.RunCommand("/bin/chmod", $"u+x {scriptPath}");
|
|
var chmodScript = builder.Actions.IsWindows() ? BuildScript.Success : BuildScript.Try(chmod.Script);
|
|
|
|
var dir = Path.GetDirectoryName(scriptPath);
|
|
|
|
// A specific .NET Core version may be required
|
|
return chmodScript & DotNetRule.WithDotNet(builder, dotNet =>
|
|
{
|
|
var command = new CommandBuilder(builder.Actions, dir, dotNet?.Environment);
|
|
|
|
// A specific Visual Studio version may be required
|
|
var vsTools = MsBuildRule.GetVcVarsBatFile(builder);
|
|
if (vsTools != null)
|
|
command.CallBatFile(vsTools.Path);
|
|
|
|
command.IndexCommand(builder.Odasa, scriptPath);
|
|
return command.Script;
|
|
});
|
|
}
|
|
}
|
|
}
|