Skip to content

Commit ca43aaf

Browse files
authored
DotNetCliCommand: Add new RetryFailedBuildWithNoDeps property (#1982)
* DotNetCliCommand: Add new `RetryFailedBuildWithNoDeps` property If a build fails, then it is retried with `--no-dependencies`. But this can be problematic because msbuild can end up skipping some steps, resulting in an incorrect build. And that can cause inexplicable issues when running the benchmarks. This is seen with wasm/aot builds with emcc, or wasm-ld crashes. The property defaults to true, but is disabled for wasm builds.
1 parent 5fdafbc commit ca43aaf

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public class DotNetCliBuilder : IBuilder
1414

1515
private string CustomDotNetCliPath { get; }
1616
private bool LogOutput { get; }
17+
private bool RetryFailedBuildWithNoDeps { get; }
1718

1819
[PublicAPI]
19-
public DotNetCliBuilder(string targetFrameworkMoniker, string customDotNetCliPath = null, bool logOutput = false)
20+
public DotNetCliBuilder(string targetFrameworkMoniker, string customDotNetCliPath = null, bool logOutput = false, bool retryFailedBuildWithNoDeps = true)
2021
{
2122
TargetFrameworkMoniker = targetFrameworkMoniker;
2223
CustomDotNetCliPath = customDotNetCliPath;
2324
LogOutput = logOutput;
25+
RetryFailedBuildWithNoDeps = retryFailedBuildWithNoDeps;
2426
}
2527

2628
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
@@ -32,7 +34,8 @@ public BuildResult Build(GenerateResult generateResult, BuildPartition buildPart
3234
buildPartition,
3335
Array.Empty<EnvironmentVariable>(),
3436
buildPartition.Timeout,
35-
logOutput: LogOutput)
37+
logOutput: LogOutput,
38+
retryFailedBuildWithNoDeps: RetryFailedBuildWithNoDeps)
3639
.RestoreThenBuild();
3740
}
3841
}

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ public class DotNetCliCommand
3131

3232
[PublicAPI] public bool LogOutput { get; }
3333

34+
[PublicAPI] public bool RetryFailedBuildWithNoDeps { get; }
35+
3436
public DotNetCliCommand(string cliPath, string arguments, GenerateResult generateResult, ILogger logger,
35-
BuildPartition buildPartition, IReadOnlyList<EnvironmentVariable> environmentVariables, TimeSpan timeout, bool logOutput = false)
37+
BuildPartition buildPartition, IReadOnlyList<EnvironmentVariable> environmentVariables, TimeSpan timeout, bool logOutput = false,
38+
bool retryFailedBuildWithNoDeps = true)
3639
{
3740
CliPath = cliPath ?? DotNetCliCommandExecutor.DefaultDotNetCliPath.Value;
3841
Arguments = arguments;
@@ -42,6 +45,7 @@ public DotNetCliCommand(string cliPath, string arguments, GenerateResult generat
4245
EnvironmentVariables = environmentVariables;
4346
Timeout = timeout;
4447
LogOutput = logOutput || buildPartition.LogBuildOutput;
48+
RetryFailedBuildWithNoDeps = retryFailedBuildWithNoDeps;
4549
}
4650

4751
public DotNetCliCommand WithArguments(string arguments)
@@ -67,7 +71,7 @@ public BuildResult RestoreThenBuild()
6771
return BuildResult.Failure(GenerateResult, restoreResult.AllInformation);
6872

6973
var buildResult = BuildNoRestore();
70-
if (!buildResult.IsSuccess) // if we fail to do the full build, we try with --no-dependencies
74+
if (!buildResult.IsSuccess && RetryFailedBuildWithNoDeps) // if we fail to do the full build, we try with --no-dependencies
7175
buildResult = BuildNoRestoreNoDependencies();
7276

7377
return buildResult.ToBuildResult(GenerateResult);
@@ -93,7 +97,7 @@ public BuildResult RestoreThenBuildThenPublish()
9397
return BuildResult.Failure(GenerateResult, restoreResult.AllInformation);
9498

9599
var buildResult = BuildNoRestore();
96-
if (!buildResult.IsSuccess) // if we fail to do the full build, we try with --no-dependencies
100+
if (!buildResult.IsSuccess && RetryFailedBuildWithNoDeps) // if we fail to do the full build, we try with --no-dependencies
97101
buildResult = BuildNoRestoreNoDependencies();
98102

99103
if (!buildResult.IsSuccess)

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmToolChain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public static IToolchain From(NetCoreAppSettings netCoreAppSettings)
4343
new DotNetCliBuilder(netCoreAppSettings.TargetFrameworkMoniker,
4444
netCoreAppSettings.CustomDotNetCliPath,
4545
// aot builds can be very slow
46-
logOutput: netCoreAppSettings.AOTCompilerMode == MonoAotLLVM.MonoAotCompilerMode.wasm),
46+
logOutput: netCoreAppSettings.AOTCompilerMode == MonoAotLLVM.MonoAotCompilerMode.wasm,
47+
retryFailedBuildWithNoDeps: false),
4748
new Executor(),
4849
netCoreAppSettings.CustomDotNetCliPath);
4950
}

0 commit comments

Comments
 (0)