Skip to content
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

Fix Windows path too long #2681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 Windows' 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
Loading