Skip to content

Commit

Permalink
Fix Windows path too long.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Dec 22, 2024
1 parent cd50f7b commit 44e19d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
33 changes: 28 additions & 5 deletions src/BenchmarkDotNet/Running/BuildPartition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using BenchmarkDotNet.Characteristics;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Detectors;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Jobs;
Expand All @@ -28,11 +29,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
Resolver = resolver;
RepresentativeBenchmarkCase = benchmarks[0].BenchmarkCase;
Benchmarks = benchmarks;
// Combine the benchmark's assembly name, folder info, and build partition id.
string benchmarkAssemblyName = RepresentativeBenchmarkCase.Descriptor.Type.Assembly.GetName().Name;
string folderInfo = RepresentativeBenchmarkCase.Job.FolderInfo;
int id = Interlocked.Increment(ref s_partitionCounter);
ProgramName = $"{benchmarkAssemblyName}-{folderInfo}-{id}";
ProgramName = GetProgramName(RepresentativeBenchmarkCase, Interlocked.Increment(ref s_partitionCounter));
LogBuildOutput = benchmarks[0].Config.Options.IsSet(ConfigOptions.LogBuildOutput);
GenerateMSBuildBinLog = benchmarks[0].Config.Options.IsSet(ConfigOptions.GenerateMSBuildBinLog);
}
Expand Down Expand Up @@ -85,6 +82,32 @@ private static string GetResolvedAssemblyLocation(Assembly assembly) =>
// manually construct the path.
assembly.Location.Length == 0 ? Path.Combine(AppContext.BaseDirectory, assembly.GetName().Name) : assembly.Location;

internal static string GetProgramName(BenchmarkCase representativeBenchmarkCase, int id)
{
// Combine the benchmark's assembly name, folder info, and build partition id.
string benchmarkAssemblyName = representativeBenchmarkCase.Descriptor.Type.Assembly.GetName().Name;
string folderInfo = representativeBenchmarkCase.Job.FolderInfo;
var programName = $"{benchmarkAssemblyName}-{folderInfo}-{id}";
// Very long program name can cause the path to exceed Window's 260 character limit,
// for example BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.
// 36 is an arbitrary limit, but it's the length of Guid strings which is what was used previously.
if (!OsDetector.IsWindows() || programName.Length <= 36)
{
return programName;
}
programName = $"{benchmarkAssemblyName}-{id}";
if (programName.Length <= 36)
{
return programName;
}
programName = $"{folderInfo}-{id}";
if (programName.Length <= 36)
{
return programName;
}
return id.ToString();
}

internal bool ForcedNoDependenciesForIntegrationTests
{
get
Expand Down
5 changes: 2 additions & 3 deletions tests/BenchmarkDotNet.IntegrationTests/InProcessEmitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ private void DiffEmit(Summary summary)
return;

var benchmarkCase = summary.BenchmarksCases.First();
var caseName = $"{benchmarkCase.Descriptor.Type.Assembly.GetName().Name}-{benchmarkCase.Job.FolderInfo}";
// The benchmark config built jobs with 2 toolchains, 1 InProcessEmit and 1 Roslyn,
// so we need to subtract 1 from the partition counter to obtain the emit output.
NaiveRunnableEmitDiff.RunDiff(
$@"{caseName}-{BuildPartition.s_partitionCounter}.exe",
$@"{caseName}-{BuildPartition.s_partitionCounter - 1}Emitted.dll",
$@"{BuildPartition.GetProgramName(benchmarkCase, BuildPartition.s_partitionCounter)}.exe",
$@"{BuildPartition.GetProgramName(benchmarkCase, BuildPartition.s_partitionCounter - 1)}Emitted.dll",
ConsoleLogger.Default);
}

Expand Down

0 comments on commit 44e19d3

Please sign in to comment.