Skip to content

C#: Remove support for legacy LGTM options in autobuilder #16016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,7 @@ void EndCallback(int ret, string s, bool silent)
EndCallbackIn.Add(s);
}

CppAutobuilder CreateAutoBuilder(bool isWindows,
string? buildless = null, string? solution = null, string? buildCommand = null, string? ignoreErrors = null,
string? msBuildArguments = null, string? msBuildPlatform = null, string? msBuildConfiguration = null, string? msBuildTarget = null,
string? dotnetArguments = null, string? dotnetVersion = null, string? vsToolsVersion = null,
string? nugetRestore = null, string? allSolutions = null,
string cwd = @"C:\Project")
CppAutobuilder CreateAutoBuilder(bool isWindows, string? dotnetVersion = null, string cwd = @"C:\Project")
{
string codeqlUpperLanguage = Language.Cpp.UpperCaseName;
Actions.GetEnvironmentVariable[$"CODEQL_AUTOBUILDER_{codeqlUpperLanguage}_NO_INDEXING"] = "false";
Expand All @@ -265,22 +260,7 @@ CppAutobuilder CreateAutoBuilder(bool isWindows,
Actions.GetEnvironmentVariable[$"CODEQL_EXTRACTOR_{codeqlUpperLanguage}_DIAGNOSTIC_DIR"] = "";
Actions.GetEnvironmentVariable["CODEQL_JAVA_HOME"] = @"C:\codeql\tools\java";
Actions.GetEnvironmentVariable["CODEQL_PLATFORM"] = "win64";
Actions.GetEnvironmentVariable["SEMMLE_DIST"] = @"C:\odasa";
Actions.GetEnvironmentVariable["SEMMLE_JAVA_HOME"] = @"C:\odasa\tools\java";
Actions.GetEnvironmentVariable["SEMMLE_PLATFORM_TOOLS"] = @"C:\odasa\tools";
Actions.GetEnvironmentVariable["LGTM_INDEX_VSTOOLS_VERSION"] = vsToolsVersion;
Actions.GetEnvironmentVariable["LGTM_INDEX_MSBUILD_ARGUMENTS"] = msBuildArguments;
Actions.GetEnvironmentVariable["LGTM_INDEX_MSBUILD_PLATFORM"] = msBuildPlatform;
Actions.GetEnvironmentVariable["LGTM_INDEX_MSBUILD_CONFIGURATION"] = msBuildConfiguration;
Actions.GetEnvironmentVariable["LGTM_INDEX_MSBUILD_TARGET"] = msBuildTarget;
Actions.GetEnvironmentVariable["LGTM_INDEX_DOTNET_ARGUMENTS"] = dotnetArguments;
Actions.GetEnvironmentVariable["LGTM_INDEX_DOTNET_VERSION"] = dotnetVersion;
Actions.GetEnvironmentVariable["LGTM_INDEX_BUILD_COMMAND"] = buildCommand;
Actions.GetEnvironmentVariable["LGTM_INDEX_SOLUTION"] = solution;
Actions.GetEnvironmentVariable["LGTM_INDEX_IGNORE_ERRORS"] = ignoreErrors;
Actions.GetEnvironmentVariable["LGTM_INDEX_BUILDLESS"] = buildless;
Actions.GetEnvironmentVariable["LGTM_INDEX_ALL_SOLUTIONS"] = allSolutions;
Actions.GetEnvironmentVariable["LGTM_INDEX_NUGET_RESTORE"] = nugetRestore;
Actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_OPTION_DOTNET_VERSION"] = dotnetVersion;
Actions.GetEnvironmentVariable["ProgramFiles(x86)"] = isWindows ? @"C:\Program Files (x86)" : null;
Actions.GetCurrentDirectory = cwd;
Actions.IsWindows = isWindows;
Expand Down
3 changes: 0 additions & 3 deletions cpp/autobuilder/Semmle.Autobuild.Cpp/CppAutobuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public class CppAutobuilder : Autobuilder<CppAutobuildOptions>

public override BuildScript GetBuildScript()
{
if (Options.BuildCommand != null)
return new BuildCommandRule((_, f) => f(null)).Analyse(this, false);

return
// First try MSBuild
new MsBuildRule().Analyse(this, true) |
Expand Down
252 changes: 6 additions & 246 deletions csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs

Large diffs are not rendered by default.

30 changes: 3 additions & 27 deletions csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpAutobuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ public class CSharpAutobuildOptions : AutobuildOptionsShared
/// </summary>
public CSharpAutobuildOptions(IBuildActions actions) : base(actions)
{
Buildless = actions.GetEnvironmentVariable(lgtmPrefix + "BUILDLESS").AsBool("buildless", false) ||
Buildless =
actions.GetEnvironmentVariable(extractorOptionPrefix + "BUILDLESS").AsBool("buildless", false) ||
actions.GetEnvironmentVariable(buildModeEnvironmentVariable)?.ToLower() == "none";


}
}

Expand All @@ -46,19 +48,10 @@ public override BuildScript GetBuildScript()
var attempt = BuildScript.Failure;
switch (GetCSharpBuildStrategy())
{
case CSharpBuildStrategy.CustomBuildCommand:
attempt = new BuildCommandRule(DotNetRule.WithDotNet).Analyse(this, false) & CheckExtractorRun(true);
break;
case CSharpBuildStrategy.Buildless:
// No need to check that the extractor has been executed in buildless mode
attempt = new StandaloneBuildRule().Analyse(this, false);
break;
case CSharpBuildStrategy.MSBuild:
attempt = new MsBuildRule().Analyse(this, false) & CheckExtractorRun(true);
break;
case CSharpBuildStrategy.DotNet:
attempt = new DotNetRule().Analyse(this, false) & CheckExtractorRun(true);
break;
case CSharpBuildStrategy.Auto:
attempt =
// Attempt a few different build strategies to see if one works
Expand Down Expand Up @@ -198,32 +191,15 @@ Set up a [manual build command]({buildCommandDocsUrl}).
/// </summary>
private CSharpBuildStrategy GetCSharpBuildStrategy()
{
if (Options.BuildCommand is not null)
return CSharpBuildStrategy.CustomBuildCommand;

if (Options.Buildless)
return CSharpBuildStrategy.Buildless;

if (Options.MsBuildArguments is not null
|| Options.MsBuildConfiguration is not null
|| Options.MsBuildPlatform is not null
|| Options.MsBuildTarget is not null)
{
return CSharpBuildStrategy.MSBuild;
}

if (Options.DotNetArguments is not null || Options.DotNetVersion is not null)
return CSharpBuildStrategy.DotNet;

return CSharpBuildStrategy.Auto;
}

private enum CSharpBuildStrategy
{
CustomBuildCommand,
Buildless,
MSBuild,
DotNet,
Auto
}
}
Expand Down
3 changes: 1 addition & 2 deletions csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ private static BuildScript GetBuildScript(IAutobuilder<CSharpAutobuildOptions> b
Argument("--no-incremental");

return
script.Argument(builder.Options.DotNetArguments).
QuoteArgument(projOrSln).
script.QuoteArgument(projOrSln).
Script;
}
}
Expand Down
29 changes: 1 addition & 28 deletions csharp/autobuilder/Semmle.Autobuild.Shared/AutobuildOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,9 @@ namespace Semmle.Autobuild.Shared
/// </summary>
public abstract class AutobuildOptionsShared
{
protected const string lgtmPrefix = "LGTM_INDEX_";


public int SearchDepth { get; } = 3;
public string RootDirectory { get; }
public string? VsToolsVersion { get; }
public string? MsBuildArguments { get; }
public string? MsBuildPlatform { get; }
public string? MsBuildConfiguration { get; }
public string? MsBuildTarget { get; }
public string? DotNetArguments { get; }
public string? DotNetVersion { get; }
public string? BuildCommand { get; }
public IEnumerable<string> Solution { get; }
public bool IgnoreErrors { get; }

public bool AllSolutions { get; }
public bool NugetRestore { get; }
public abstract Language Language { get; }

/// <summary>
Expand All @@ -38,19 +23,7 @@ public abstract class AutobuildOptionsShared
public AutobuildOptionsShared(IBuildActions actions)
{
RootDirectory = actions.GetCurrentDirectory();
VsToolsVersion = actions.GetEnvironmentVariable(lgtmPrefix + "VSTOOLS_VERSION");
MsBuildArguments = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
MsBuildPlatform = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_PLATFORM");
MsBuildConfiguration = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_CONFIGURATION");
MsBuildTarget = actions.GetEnvironmentVariable(lgtmPrefix + "MSBUILD_TARGET");
DotNetArguments = actions.GetEnvironmentVariable(lgtmPrefix + "DOTNET_ARGUMENTS")?.AsStringWithExpandedEnvVars(actions);
DotNetVersion = actions.GetEnvironmentVariable(lgtmPrefix + "DOTNET_VERSION");
BuildCommand = actions.GetEnvironmentVariable(lgtmPrefix + "BUILD_COMMAND");
Solution = actions.GetEnvironmentVariable(lgtmPrefix + "SOLUTION").AsListWithExpandedEnvVars(actions, Array.Empty<string>());

IgnoreErrors = actions.GetEnvironmentVariable(lgtmPrefix + "IGNORE_ERRORS").AsBool("ignore_errors", false);
AllSolutions = actions.GetEnvironmentVariable(lgtmPrefix + "ALL_SOLUTIONS").AsBool("all_solutions", false);
NugetRestore = actions.GetEnvironmentVariable(lgtmPrefix + "NUGET_RESTORE").AsBool("nuget_restore", true);
DotNetVersion = actions.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_OPTION_DOTNET_VERSION");
}
}

Expand Down
19 changes: 0 additions & 19 deletions csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ public abstract class Autobuilder<TAutobuildOptions> : IAutobuilder<TAutobuildOp
if (matchingFiles.Length == 0)
return null;

if (Options.AllSolutions)
return matchingFiles.Select(p => p.ProjectOrSolution);

return matchingFiles
.Where(f => f.DistanceFromRoot == matchingFiles[0].DistanceFromRoot)
.Select(f => f.ProjectOrSolution);
Expand All @@ -185,19 +182,6 @@ protected Autobuilder(IBuildActions actions, TAutobuildOptions options, Diagnost
projectsOrSolutionsToBuildLazy = new Lazy<IList<IProjectOrSolution>>(() =>
{
List<IProjectOrSolution>? ret;
if (options.Solution.Any())
{
ret = new List<IProjectOrSolution>();
foreach (var solution in options.Solution)
{
if (actions.FileExists(solution))
ret.Add(new Solution<TAutobuildOptions>(this, solution, true));
else
logger.LogError($"The specified project or solution file {solution} was not found");
}
return ret;
}

// First look for `.proj` files
ret = FindFiles(".proj", f => new Project<TAutobuildOptions>(this, f))?.ToList();
if (ret is not null)
Expand Down Expand Up @@ -285,9 +269,6 @@ public int AttemptBuild()

var script = GetBuildScript();

if (Options.IgnoreErrors)
script |= BuildScript.Success;

void startCallback(string s, bool silent)
{
logger.Log(silent ? Severity.Debug : Severity.Info, $"\nRunning {s}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool au
{
var command = new CommandBuilder(builder.Actions, dir, environment);

// A specific Visual Studio version may be required
var vsTools = MsBuildRule.GetVcVarsBatFile(builder);
if (vsTools is not null)
command.CallBatFile(vsTools.Path);

command.RunCommand(this.ScriptPath);
return command.Script;
});
Expand Down
37 changes: 0 additions & 37 deletions csharp/autobuilder/Semmle.Autobuild.Shared/BuildCommandRule.cs

This file was deleted.

Loading