C#: Use `CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR` instead of `Path.GetTem… · github/codeql@866f124 · GitHub
Skip to content

Commit 866f124

Browse files
committed
C#: Use CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR instead of Path.GetTempPath
1 parent 7819dcf commit 866f124

9 files changed

Lines changed: 65 additions & 37 deletions

File tree

‎cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs‎

Lines changed: 4 additions & 3 deletions

‎csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs‎

Lines changed: 48 additions & 23 deletions
Large diffs are not rendered by default.

‎csharp/autobuilder/Semmle.Autobuild.CSharp/DotNetRule.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public BuildScript Analyse(IAutobuilder<CSharpAutobuildOptions> builder, bool au
8181
/// </summary>
8282
public static BuildScript WithDotNet(IAutobuilder<AutobuildOptionsShared> builder, Func<string?, IDictionary<string, string>?, BuildScript> f)
8383
{
84-
var installDir = builder.Actions.PathCombine(builder.Options.RootDirectory, ".dotnet");
84+
var installDir = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var _), ".dotnet");
8585
var installScript = DownloadDotNet(builder, installDir);
8686
return BuildScript.Bind(installScript, installed =>
8787
{

‎csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool au
6060
// Use `nuget.exe` from source code repo, if present, otherwise first attempt with global
6161
// `nuget` command, and if that fails, attempt to download `nuget.exe` from nuget.org
6262
var nuget = builder.GetFilename("nuget.exe").Select(t => t.Item1).FirstOrDefault() ?? "nuget";
63-
var nugetDownload = builder.Actions.PathCombine(builder.Options.RootDirectory, ".nuget", "nuget.exe");
63+
var nugetDownloadPath = builder.Actions.PathCombine(FileUtils.GetTemporaryWorkingDirectory(builder.Actions.GetEnvironmentVariable, builder.Options.Language.UpperCaseName, out var _), ".nuget", "nuget.exe");
6464
var nugetDownloaded = false;
6565

6666
var ret = BuildScript.Success;
@@ -96,13 +96,13 @@ BuildScript GetNugetRestoreScript() =>
9696
// If `nuget restore` fails, and we have not already attempted to download `nuget.exe`,
9797
// download it and reattempt `nuget restore`.
9898
var nugetDownloadAndRestore =
99-
BuildScript.Bind(DownloadNugetExe(builder, nugetDownload), exitCode =>
99+
BuildScript.Bind(DownloadNugetExe(builder, nugetDownloadPath), exitCode =>
100100
{
101101
nugetDownloaded = true;
102102
if (exitCode != 0)
103103
return BuildScript.Failure;
104104

105-
nuget = nugetDownload;
105+
nuget = nugetDownloadPath;
106106
return GetNugetRestoreScript();
107107
});
108108
ret &= BuildScript.Try(nugetRestore | nugetDownloadAndRestore | msbuildRestoreCommand.Script);

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private static string ComputeTempDirectory(string srcDir, string packages = "pac
479479
foreach (var b in sha.Take(8))
480480
sb.AppendFormat("{0:x2}", b);
481481

482-
return Path.Combine(Path.GetTempPath(), "GitHub", packages, sb.ToString());
482+
return Path.Combine(FileUtils.GetTemporaryWorkingDirectory(out var _), "GitHub", packages, sb.ToString());
483483
}
484484

485485
/// <summary>

‎csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Razor.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Text;
55
using System.Linq;
6+
using Semmle.Util;
67

78
namespace Semmle.Extraction.CSharp.DependencyFetching
89
{
@@ -51,7 +52,7 @@ private static void GenerateAnalyzerConfig(IEnumerable<string> cshtmls, string a
5152
public IEnumerable<string> GenerateFiles(IEnumerable<string> cshtmls, IEnumerable<string> references, string workingDirectory)
5253
{
5354
var name = Guid.NewGuid().ToString("N").ToUpper();
54-
var tempPath = Path.GetTempPath();
55+
var tempPath = FileUtils.GetTemporaryWorkingDirectory(out var _);
5556
var analyzerConfig = Path.Combine(tempPath, $"{name}.txt");
5657
var dllPath = Path.Combine(tempPath, $"{name}.dll");
5758
var cscArgsPath = Path.Combine(tempPath, $"{name}.rsp");

‎csharp/extractor/Semmle.Extraction/TrapWriter.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, s
4848

4949
writerLazy = new Lazy<StreamWriter>(() =>
5050
{
51-
var tempPath = trap ?? Path.GetTempPath();
51+
var tempPath = trap ?? FileUtils.GetTemporaryWorkingDirectory(out var _);
5252

5353
do
5454
{

‎csharp/extractor/Semmle.Util/EnvironmentVariables.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public class EnvironmentVariables
77
public static string? GetExtractorOption(string name) =>
88
Environment.GetEnvironmentVariable($"CODEQL_EXTRACTOR_CSHARP_OPTION_{name.ToUpper()}");
99

10-
public static string? GetScratchDirectory() => Environment.GetEnvironmentVariable("CODEQL_EXTRACTOR_CSHARP_SCRATCH_DIR");
11-
1210
public static int GetDefaultNumberOfThreads()
1311
{
1412
if (!int.TryParse(Environment.GetEnvironmentVariable("CODEQL_THREADS"), out var threads) || threads == -1)

‎csharp/extractor/Semmle.Util/FileUtils.cs‎

Lines changed: 5 additions & 2 deletions

0 commit comments

Comments
 (0)