Skip to content

Commit 8f35e9a

Browse files
committed
Moved no dependencies check for integration tests to BuildPartition.
Removed instead of deprecated methods/properties.
1 parent c4ac43e commit 8f35e9a

File tree

7 files changed

+34
-26
lines changed

7 files changed

+34
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BenchmarkDotNet.Portability;
21
using System;
32
using System.Linq;
43

@@ -8,6 +7,4 @@ internal static class XUnitHelper
87
{
98
public static Lazy<bool> IsIntegrationTest =
109
new (() => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.GetName().Name == "BenchmarkDotNet.IntegrationTests"));
11-
12-
public static bool ForceNoDependenciesForCore => IsIntegrationTest.Value && RuntimeInformation.IsNetCore;
1310
}

src/BenchmarkDotNet/Running/BuildPartition.cs

+24-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
using BenchmarkDotNet.Characteristics;
66
using BenchmarkDotNet.Configs;
77
using BenchmarkDotNet.Environments;
8+
using BenchmarkDotNet.Helpers;
89
using BenchmarkDotNet.Jobs;
10+
using BenchmarkDotNet.Portability;
11+
using BenchmarkDotNet.Toolchains;
912
using BenchmarkDotNet.Toolchains.CsProj;
13+
using BenchmarkDotNet.Toolchains.DotNetCli;
1014
using BenchmarkDotNet.Toolchains.MonoWasm;
1115
using BenchmarkDotNet.Toolchains.Roslyn;
1216
using JetBrains.Annotations;
@@ -27,8 +31,7 @@ public BuildPartition(BenchmarkBuildInfo[] benchmarks, IResolver resolver)
2731
LogBuildOutput = benchmarks[0].Config.Options.IsSet(ConfigOptions.LogBuildOutput);
2832
GenerateMSBuildBinLog = benchmarks[0].Config.Options.IsSet(ConfigOptions.GenerateMSBuildBinLog);
2933

30-
int id = Interlocked.Increment(ref s_id);
31-
Id = $"{id}_";
34+
Id = $"{Interlocked.Increment(ref s_id)}_";
3235
var random = new Random(guid.GetHashCode());
3336
for (int i = 0; i < 6; i++)
3437
Id += (char) ('A' + random.Next(26));
@@ -83,5 +86,24 @@ private static string GetResolvedAssemblyLocation(Assembly assembly) =>
8386
// in case of SingleFile, location.Length returns 0, so we use GetName() and
8487
// manually construct the path.
8588
assembly.Location.Length == 0 ? Path.Combine(AppContext.BaseDirectory, assembly.GetName().Name) : assembly.Location;
89+
90+
internal bool ForcedNoDependenciesForIntegrationTests
91+
{
92+
get
93+
{
94+
if (!XUnitHelper.IsIntegrationTest.Value || !RuntimeInformation.IsNetCore)
95+
return false;
96+
97+
var job = RepresentativeBenchmarkCase.Job;
98+
if (job.GetToolchain().Builder is not DotNetCliBuilder)
99+
return false;
100+
101+
bool hasDynamicBuildCharacteristic = job.HasValue(InfrastructureMode.NuGetReferencesCharacteristic)
102+
|| job.HasValue(InfrastructureMode.BuildConfigurationCharacteristic)
103+
|| job.HasValue(InfrastructureMode.ArgumentsCharacteristic);
104+
105+
return !hasDynamicBuildCharacteristic;
106+
}
107+
}
86108
}
87109
}

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected override string GetProjectFilePath(string buildArtifactsDirectoryPath)
6161
=> Path.Combine(buildArtifactsDirectoryPath, "BenchmarkDotNet.Autogenerated.csproj");
6262

6363
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, BuildPartition buildPartition)
64-
=> XUnitHelper.ForceNoDependenciesForCore
64+
=> buildPartition.ForcedNoDependenciesForIntegrationTests
6565
? Path.Combine(buildArtifactsDirectoryPath, "bin", buildPartition.BuildConfiguration, TargetFrameworkMoniker)
6666
: Path.Combine(buildArtifactsDirectoryPath, "bin", $"bdn_partition_{buildPartition.Id}");
6767

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.IO;
53
using System.Linq;
64
using System.Text;
75
using BenchmarkDotNet.Characteristics;
86
using BenchmarkDotNet.Extensions;
9-
using BenchmarkDotNet.Helpers;
107
using BenchmarkDotNet.Jobs;
118
using BenchmarkDotNet.Loggers;
129
using BenchmarkDotNet.Portability;
@@ -34,9 +31,6 @@ public class DotNetCliCommand
3431

3532
[PublicAPI] public bool LogOutput { get; }
3633

37-
[Obsolete("Building with no dependencies is no longer supported.", false), EditorBrowsable(EditorBrowsableState.Never)]
38-
public bool RetryFailedBuildWithNoDeps => false;
39-
4034
public DotNetCliCommand(string cliPath, string arguments, GenerateResult generateResult, ILogger logger,
4135
BuildPartition buildPartition, IReadOnlyList<EnvironmentVariable> environmentVariables, TimeSpan timeout, bool logOutput = false)
4236
{
@@ -77,11 +71,11 @@ public BuildResult RestoreThenBuild()
7771

7872
// On our CI, Integration tests take too much time, because each benchmark run rebuilds BenchmarkDotNet itself.
7973
// To reduce the total duration of the CI workflows, we build all the projects without dependencies
80-
if (XUnitHelper.ForceNoDependenciesForCore)
74+
if (BuildPartition.ForcedNoDependenciesForIntegrationTests)
8175
{
82-
#pragma warning disable CS0618 // Type or member is obsolete
83-
return BuildNoRestoreNoDependencies().ToBuildResult(GenerateResult);
84-
#pragma warning restore CS0618 // Type or member is obsolete
76+
return DotNetCliCommandExecutor.Execute(WithArguments(
77+
GetBuildCommand(GenerateResult.ArtifactsPaths, BuildPartition, $"{Arguments} --no-restore --no-dependencies", "build-no-restore-no-deps", excludeOutput: true)))
78+
.ToBuildResult(GenerateResult);
8579
}
8680

8781
// We no longer retry with --no-dependencies, because it fails with --output set at the same time,
@@ -138,11 +132,6 @@ public DotNetCliCommandResult BuildNoRestore()
138132
=> DotNetCliCommandExecutor.Execute(WithArguments(
139133
GetBuildCommand(GenerateResult.ArtifactsPaths, BuildPartition, $"{Arguments} --no-restore", "build-no-restore")));
140134

141-
[Obsolete("Building with no dependencies is no longer supported, and will probably fail.", false), EditorBrowsable(EditorBrowsableState.Never)]
142-
public DotNetCliCommandResult BuildNoRestoreNoDependencies()
143-
=> DotNetCliCommandExecutor.Execute(WithArguments(
144-
GetBuildCommand(GenerateResult.ArtifactsPaths, BuildPartition, $"{Arguments} --no-restore --no-dependencies", "build-no-restore-no-deps", excludeOutput: true)));
145-
146135
public DotNetCliCommandResult Publish()
147136
=> DotNetCliCommandExecutor.Execute(WithArguments(
148137
GetPublishCommand(GenerateResult.ArtifactsPaths, BuildPartition, Arguments, "publish")));

src/BenchmarkDotNet/Toolchains/MonoAotLLVM/MonoAotLLVMGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override string GetExecutablePath(string binariesDirectoryPath, string
5959
: Path.Combine(binariesDirectoryPath, programName);
6060

6161
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, BuildPartition buildPartition)
62-
=> XUnitHelper.ForceNoDependenciesForCore
62+
=> buildPartition.ForcedNoDependenciesForIntegrationTests
6363
? Path.Combine(buildArtifactsDirectoryPath, "bin", TargetFrameworkMoniker, CustomDotNetCliToolchainBuilder.GetPortableRuntimeIdentifier(), "publish")
6464
: Path.Combine(base.GetBinariesDirectoryPath(buildArtifactsDirectoryPath, buildPartition), CustomDotNetCliToolchainBuilder.GetPortableRuntimeIdentifier(), "publish");
6565
}

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths
6969
protected override string GetExecutablePath(string binariesDirectoryPath, string programName) => Path.Combine(binariesDirectoryPath, MainJS);
7070

7171
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, BuildPartition buildPartition)
72-
=> XUnitHelper.ForceNoDependenciesForCore
72+
=> buildPartition.ForcedNoDependenciesForIntegrationTests
7373
? Path.Combine(buildArtifactsDirectoryPath, "bin", TargetFrameworkMoniker, "browser-wasm", "AppBundle")
7474
: Path.Combine(base.GetBinariesDirectoryPath(buildArtifactsDirectoryPath, buildPartition), "browser-wasm", "AppBundle");
7575
}

tests/BenchmarkDotNet.IntegrationTests.ManualRunning/MsBuildArgumentTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void ProcessIsBuiltWithCustomProperty(bool setCustomProperty)
2121
.WithArguments(new Argument[] { new MsBuildArgument($"/p:CustomProp={setCustomProperty}") })
2222
.WithEnvironmentVariable(CustomPropEnvVarName, setCustomProperty.ToString())
2323
);
24-
CanExecute<ValuePerTfm>(config);
24+
CanExecute<PropertyDefine>(config);
2525
}
2626

2727
[Fact]
@@ -40,10 +40,10 @@ public void MultipleProcessesAreBuiltWithCorrectProperties()
4040
.AddJob(Job.Dry
4141
.WithEnvironmentVariable(CustomPropEnvVarName, false.ToString())
4242
);
43-
CanExecute<ValuePerTfm>(config);
43+
CanExecute<PropertyDefine>(config);
4444
}
4545

46-
public class ValuePerTfm
46+
public class PropertyDefine
4747
{
4848
private const bool customPropWasSet =
4949
#if CUSTOM_PROP

0 commit comments

Comments
 (0)