From 621de2b977c5376ce4dc481930320e6af2c93129 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Fri, 5 Apr 2024 14:04:29 +0200 Subject: [PATCH] C#: Avoid process creation indirection in auto-builder --- .../BuildScripts.cs | 60 ------------------- .../Semmle.Autobuild.CSharp.csproj | 1 + .../StandaloneBuildRule.cs | 12 +--- .../Semmle.Autobuild.Shared/Autobuilder.cs | 23 ------- csharp/tools/tracing-config.lua | 5 -- 5 files changed, 2 insertions(+), 99 deletions(-) diff --git a/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs b/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs index 3288eb5e852..1814a76bb2a 100644 --- a/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs +++ b/csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs @@ -544,51 +544,6 @@ namespace Semmle.Autobuild.CSharp.Tests Assert.Equal(2, vcvarsfiles.Length); } - [Fact] - public void TestLinuxBuildlessExtractionSuccess() - { - actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0; - actions.FileExists["csharp.log"] = true; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR"] = "scratch"; - actions.EnumerateFiles[@"C:\Project"] = "foo.cs\ntest.sln"; - actions.EnumerateDirectories[@"C:\Project"] = ""; - - var autobuilder = CreateAutoBuilder(false, buildless: "true"); - TestAutobuilderScript(autobuilder, 0, 1); - } - - [Fact] - public void TestLinuxBuildlessExtractionFailed() - { - actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 10; - actions.FileExists["csharp.log"] = true; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR"] = "scratch"; - actions.EnumerateFiles[@"C:\Project"] = "foo.cs\ntest.sln"; - actions.EnumerateDirectories[@"C:\Project"] = ""; - - var autobuilder = CreateAutoBuilder(false, buildless: "true"); - TestAutobuilderScript(autobuilder, 10, 1); - } - - [Fact] - public void TestLinuxBuildlessExtractionSolution() - { - actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0; - actions.FileExists["csharp.log"] = true; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR"] = "scratch"; - actions.EnumerateFiles[@"C:\Project"] = "foo.cs\ntest.sln"; - actions.EnumerateDirectories[@"C:\Project"] = ""; - - var autobuilder = CreateAutoBuilder(false, buildless: "true"); - TestAutobuilderScript(autobuilder, 0, 1); - } - private void TestAutobuilderScript(CSharpAutobuilder autobuilder, int expectedOutput, int commandsRun) { Assert.Equal(expectedOutput, autobuilder.GetBuildScript().Run(actions, StartCallback, EndCallback)); @@ -677,21 +632,6 @@ namespace Semmle.Autobuild.CSharp.Tests TestAutobuilderScript(autobuilder, 0, 1); } - [Fact] - public void TestSkipNugetBuildless() - { - actions.RunProcess[@"C:\codeql\csharp/tools/linux64/Semmle.Extraction.CSharp.Standalone"] = 0; - actions.FileExists["csharp.log"] = true; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_TRAP_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SOURCE_ARCHIVE_DIR"] = ""; - actions.GetEnvironmentVariable["CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR"] = "scratch"; - actions.EnumerateFiles[@"C:\Project"] = "foo.cs\ntest.sln"; - actions.EnumerateDirectories[@"C:\Project"] = ""; - - var autobuilder = CreateAutoBuilder(false, buildless: "true"); - TestAutobuilderScript(autobuilder, 0, 1); - } - [Fact] public void TestDotnetVersionNotInstalled() { diff --git a/csharp/autobuilder/Semmle.Autobuild.CSharp/Semmle.Autobuild.CSharp.csproj b/csharp/autobuilder/Semmle.Autobuild.CSharp/Semmle.Autobuild.CSharp.csproj index 72631931150..7c4f1d68177 100644 --- a/csharp/autobuilder/Semmle.Autobuild.CSharp/Semmle.Autobuild.CSharp.csproj +++ b/csharp/autobuilder/Semmle.Autobuild.CSharp/Semmle.Autobuild.CSharp.csproj @@ -5,6 +5,7 @@ + diff --git a/csharp/autobuilder/Semmle.Autobuild.CSharp/StandaloneBuildRule.cs b/csharp/autobuilder/Semmle.Autobuild.CSharp/StandaloneBuildRule.cs index c202a029674..5b844e6cf6c 100644 --- a/csharp/autobuilder/Semmle.Autobuild.CSharp/StandaloneBuildRule.cs +++ b/csharp/autobuilder/Semmle.Autobuild.CSharp/StandaloneBuildRule.cs @@ -10,17 +10,7 @@ namespace Semmle.Autobuild.CSharp { public BuildScript Analyse(IAutobuilder builder, bool auto) { - if (builder.CodeQLExtractorLangRoot is null - || builder.CodeQlPlatform is null) - { - return BuildScript.Failure; - } - - var standalone = builder.Actions.PathCombine(builder.CodeQLExtractorLangRoot, "tools", builder.CodeQlPlatform, "Semmle.Extraction.CSharp.Standalone"); - var cmd = new CommandBuilder(builder.Actions); - cmd.RunCommand(standalone); - - return cmd.Script; + return BuildScript.Create(_ => Semmle.Extraction.CSharp.Standalone.Program.Main([])); } } } diff --git a/csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs b/csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs index 2414791ad4c..371352cf5e2 100644 --- a/csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs +++ b/csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs @@ -73,16 +73,6 @@ namespace Semmle.Autobuild.Shared /// A logger. /// ILogger Logger { get; } - - /// - /// Value of CODEQL_EXTRACTOR__ROOT environment variable. - /// - string? CodeQLExtractorLangRoot { get; } - - /// - /// Value of CODEQL_PLATFORM environment variable. - /// - string? CodeQlPlatform { get; } } /// @@ -197,9 +187,6 @@ namespace Semmle.Autobuild.Shared return ret ?? new List(); }); - CodeQLExtractorLangRoot = Actions.GetEnvironmentVariable(EnvVars.Root(this.Options.Language)); - CodeQlPlatform = Actions.GetEnvironmentVariable(EnvVars.Platform); - TrapDir = RequireEnvironmentVariable(EnvVars.TrapDir(this.Options.Language)); SourceArchiveDir = RequireEnvironmentVariable(EnvVars.SourceArchiveDir(this.Options.Language)); DiagnosticsDir = RequireEnvironmentVariable(EnvVars.DiagnosticDir(this.Options.Language)); @@ -364,15 +351,5 @@ namespace Semmle.Autobuild.Shared diagnostics.Dispose(); } } - - /// - /// Value of CODEQL_EXTRACTOR__ROOT environment variable. - /// - public string? CodeQLExtractorLangRoot { get; } - - /// - /// Value of CODEQL_PLATFORM environment variable. - /// - public string? CodeQlPlatform { get; } } } diff --git a/csharp/tools/tracing-config.lua b/csharp/tools/tracing-config.lua index 5fc1cc8e80e..a48a93c073c 100644 --- a/csharp/tools/tracing-config.lua +++ b/csharp/tools/tracing-config.lua @@ -179,8 +179,6 @@ function RegisterExtractorPack(id) end local windowsMatchers = { - CreatePatternMatcher({ '^semmle%.extraction%.csharp%.standalone%.exe$' }, - MatchCompilerName, nil, { trace = false }), DotnetMatcherBuild, MsBuildMatcher, CreatePatternMatcher({ '^csc.*%.exe$' }, MatchCompilerName, extractor, { @@ -222,9 +220,6 @@ function RegisterExtractorPack(id) end } local posixMatchers = { - -- The compiler name is case sensitive on Linux and lower cased on MacOS - CreatePatternMatcher({ '^semmle%.extraction%.csharp%.standalone$', '^Semmle%.Extraction%.CSharp%.Standalone$' }, - MatchCompilerName, nil, { trace = false }), DotnetMatcherBuild, CreatePatternMatcher({ '^mcs%.exe$', '^csc%.exe$' }, MatchCompilerName, extractor, {