Skip to content

Commit 58663f7

Browse files
committed
Include guid in build artifacts directory when --keepFiles is specified.
1 parent ca5dfdf commit 58663f7

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

src/BenchmarkDotNet/Running/BuildPartition.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
2323
Resolver = resolver;
2424
RepresentativeBenchmarkCase = benchmarks[0].BenchmarkCase;
2525
Benchmarks = benchmarks;
26-
ProgramName = benchmarks[0].Config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles) ? RepresentativeBenchmarkCase.Job.FolderInfo : Guid.NewGuid().ToString();
26+
var keepBenchmarkFiles = benchmarks[0].Config.Options.IsSet(ConfigOptions.KeepBenchmarkFiles);
27+
var guid = Guid.NewGuid().ToString();
28+
ProgramName = keepBenchmarkFiles ? RepresentativeBenchmarkCase.Job.FolderInfo : guid;
29+
ProgramDirectory = keepBenchmarkFiles ? Path.Combine(RepresentativeBenchmarkCase.Job.FolderInfo, guid) : guid;
2730
LogBuildOutput = benchmarks[0].Config.Options.IsSet(ConfigOptions.LogBuildOutput);
2831
GenerateMSBuildBinLog = benchmarks[0].Config.Options.IsSet(ConfigOptions.GenerateMSBuildBinLog);
2932
}
@@ -32,6 +35,8 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
3235

3336
public string ProgramName { get; }
3437

38+
public string ProgramDirectory { get; }
39+
3540
/// <summary>
3641
/// the benchmarks are grouped by the build settings
3742
/// so you can use this benchmark to get the runtime settings

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ protected DotNetCliGenerator(string targetFrameworkMoniker, string cliPath, stri
3636
/// we are limited by xprojs (by default compiles all .cs files in all subfolders, Program.cs could be doubled and fail the build)
3737
/// and also by NuGet internal implementation like looking for global.json file in parent folders
3838
/// </summary>
39-
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programName)
39+
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programDirectory)
4040
{
4141
if (GetSolutionRootDirectory(out var directoryInfo))
4242
{
43-
return Path.Combine(directoryInfo.FullName, programName);
43+
return Path.Combine(directoryInfo.FullName, programDirectory);
4444
}
4545

4646
// we did not find global.json or any Visual Studio solution file?
4747
// let's return it in the old way and hope that it works ;)
4848
var parent = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent;
4949
if (parent == null)
5050
throw new DirectoryNotFoundException("Parent directory for current directory");
51-
return Path.Combine(parent.FullName, programName);
51+
return Path.Combine(parent.FullName, programDirectory);
5252
}
5353

5454
internal static bool GetSolutionRootDirectory(out DirectoryInfo directoryInfo)

src/BenchmarkDotNet/Toolchains/GeneratorBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GenerateResult GenerateProject(BuildPartition buildPartition, ILogger log
4242
/// <summary>
4343
/// returns a path to the folder where auto-generated project and code are going to be placed
4444
/// </summary>
45-
[PublicAPI] protected abstract string GetBuildArtifactsDirectoryPath(BuildPartition assemblyLocation, string programName);
45+
[PublicAPI] protected abstract string GetBuildArtifactsDirectoryPath(BuildPartition assemblyLocation, string programDirectory);
4646

4747
/// <summary>
4848
/// returns a path where executable should be found after the build (usually \bin)
@@ -128,10 +128,10 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
128128
// its not ".cs" in order to avoid VS from displaying and compiling it with xprojs/csprojs that include all *.cs by default
129129
const string codeFileExtension = ".notcs";
130130

131-
string programName = buildPartition.ProgramName;
132-
string buildArtifactsDirectoryPath = GetBuildArtifactsDirectoryPath(buildPartition, programName);
131+
string buildArtifactsDirectoryPath = GetBuildArtifactsDirectoryPath(buildPartition, buildPartition.ProgramDirectory);
133132
string binariesDirectoryPath = GetBinariesDirectoryPath(buildArtifactsDirectoryPath, buildPartition.BuildConfiguration);
134133

134+
string programName = buildPartition.ProgramName;
135135
string executablePath = GetExecutablePath(binariesDirectoryPath, programName);
136136

137137
return new ArtifactsPaths(

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ internal Generator(string ilCompilerVersion,
6060

6161
protected override string GetExecutableExtension() => OsDetector.ExecutableExtension;
6262

63-
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programName)
63+
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programDirectory)
6464
=> useTempFolderForRestore
65-
? Path.Combine(Path.GetTempPath(), programName) // store everything in temp to avoid collisions with IDE
66-
: base.GetBuildArtifactsDirectoryPath(buildPartition, programName);
65+
? Path.Combine(Path.GetTempPath(), programDirectory) // store everything in temp to avoid collisions with IDE
66+
: base.GetBuildArtifactsDirectoryPath(buildPartition, programDirectory);
6767

6868
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
6969
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, runtimeIdentifier, "publish");

src/BenchmarkDotNet/Toolchains/Roslyn/Generator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace BenchmarkDotNet.Toolchains.Roslyn
1313
[PublicAPI]
1414
public class Generator : GeneratorBase
1515
{
16-
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programName)
16+
protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPartition, string programDirectory)
1717
=> Path.GetDirectoryName(buildPartition.AssemblyLocation);
1818

1919
[PublicAPI]

tests/BenchmarkDotNet.Tests/CsProjGeneratorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ public void TestAssemblyFilePathIsUsedWhenTheAssemblyLocationIsNotEmpty()
220220

221221
private class SteamLoadedBuildPartition : CsProjGenerator
222222
{
223-
internal string ResolvePathForBinaries(BuildPartition buildPartition, string programName)
223+
internal string ResolvePathForBinaries(BuildPartition buildPartition, string programDirectory)
224224
{
225-
return base.GetBuildArtifactsDirectoryPath(buildPartition, programName);
225+
return base.GetBuildArtifactsDirectoryPath(buildPartition, programDirectory);
226226
}
227227

228228
public SteamLoadedBuildPartition(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion, bool isNetCore)

0 commit comments

Comments
 (0)