Skip to content

Commit 64d05c6

Browse files
Support --cli argument for CsProjClassicNetToolchain (#2381)
* Support `--cli` argument for `CsProjClassicNetToolchain` * Update src/BenchmarkDotNet/Diagnosers/PerfCollectProfiler.cs Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com> --------- Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
1 parent 4d6f168 commit 64d05c6

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
518518
case RuntimeMoniker.Net481:
519519
return baseJob
520520
.WithRuntime(runtimeMoniker.GetRuntime())
521-
.WithToolchain(CsProjClassicNetToolchain.From(runtimeId, options.RestorePath?.FullName));
521+
.WithToolchain(CsProjClassicNetToolchain.From(runtimeId, options.RestorePath?.FullName, options.CliPath?.FullName));
522522

523523
case RuntimeMoniker.NetCoreApp20:
524524
case RuntimeMoniker.NetCoreApp21:

src/BenchmarkDotNet/Toolchains/CsProj/CsProjClassicNetToolchain.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ public class CsProjClassicNetToolchain : Toolchain
2323
[PublicAPI] public static readonly IToolchain Net48 = new CsProjClassicNetToolchain("net48", ".NET Framework 4.8");
2424
[PublicAPI] public static readonly IToolchain Net481 = new CsProjClassicNetToolchain("net481", ".NET Framework 4.8.1");
2525

26-
private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, string packagesPath = null)
26+
internal string CustomDotNetCliPath { get; }
27+
28+
private CsProjClassicNetToolchain(string targetFrameworkMoniker, string name, string packagesPath = null, string customDotNetCliPath = null)
2729
: base(name,
28-
new CsProjGenerator(targetFrameworkMoniker, cliPath: null, packagesPath: packagesPath, runtimeFrameworkVersion: null, isNetCore: false),
29-
new DotNetCliBuilder(targetFrameworkMoniker, customDotNetCliPath: null),
30+
new CsProjGenerator(targetFrameworkMoniker, customDotNetCliPath, packagesPath, runtimeFrameworkVersion: null, isNetCore: false),
31+
new DotNetCliBuilder(targetFrameworkMoniker, customDotNetCliPath),
3032
new Executor())
3133
{
34+
CustomDotNetCliPath = customDotNetCliPath;
3235
}
3336

34-
public static IToolchain From(string targetFrameworkMoniker, string packagesPath = null)
35-
=> new CsProjClassicNetToolchain(targetFrameworkMoniker, targetFrameworkMoniker, packagesPath);
37+
public static IToolchain From(string targetFrameworkMoniker, string packagesPath = null, string customDotNetCliPath = null)
38+
=> new CsProjClassicNetToolchain(targetFrameworkMoniker, targetFrameworkMoniker, packagesPath, customDotNetCliPath);
3639

3740
public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCase, IResolver resolver)
3841
{
@@ -47,7 +50,7 @@ public override IEnumerable<ValidationError> Validate(BenchmarkCase benchmarkCas
4750
$"Classic .NET toolchain is supported only for Windows, benchmark '{benchmarkCase.DisplayInfo}' will not be executed",
4851
benchmarkCase);
4952
}
50-
else if (IsCliPathInvalid(customDotNetCliPath: null, benchmarkCase, out var invalidCliError))
53+
else if (IsCliPathInvalid(CustomDotNetCliPath, benchmarkCase, out var invalidCliError))
5154
{
5255
yield return invalidCliError;
5356
}

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,30 @@ public void IlCompilerPathParsedCorrectly()
270270
}
271271

272272
[Theory]
273-
[InlineData("netcoreapp2.0")]
274-
[InlineData("netcoreapp2.1")]
275-
[InlineData("netcoreapp2.2")]
276-
[InlineData("netcoreapp3.0")]
277-
public void DotNetCliParsedCorrectly(string tfm)
273+
[InlineData("netcoreapp2.0", true)]
274+
[InlineData("netcoreapp2.1", true)]
275+
[InlineData("netcoreapp2.2", true)]
276+
[InlineData("netcoreapp3.0", true)]
277+
[InlineData("net462", false)]
278+
[InlineData("net48", false)]
279+
public void DotNetCliParsedCorrectly(string tfm, bool isCore)
278280
{
279281
var fakeDotnetCliPath = typeof(object).Assembly.Location;
280282
var config = ConfigParser.Parse(new[] { "-r", tfm, "--cli", fakeDotnetCliPath }, new OutputLogger(Output)).config;
281283

282284
Assert.Single(config.GetJobs());
283-
CsProjCoreToolchain toolchain = config.GetJobs().Single().GetToolchain() as CsProjCoreToolchain;
284-
Assert.NotNull(toolchain);
285+
var toolchain = config.GetJobs().Single().GetToolchain();
286+
if (isCore)
287+
{
288+
Assert.True(toolchain is CsProjCoreToolchain);
289+
Assert.Equal(fakeDotnetCliPath, ((CsProjCoreToolchain) toolchain).CustomDotNetCliPath);
290+
}
291+
else
292+
{
293+
Assert.True(toolchain is CsProjClassicNetToolchain);
294+
Assert.Equal(fakeDotnetCliPath, ((CsProjClassicNetToolchain) toolchain).CustomDotNetCliPath);
295+
}
285296
Assert.Equal(tfm, ((DotNetCliGenerator)toolchain.Generator).TargetFrameworkMoniker);
286-
Assert.Equal(fakeDotnetCliPath, toolchain.CustomDotNetCliPath);
287297
}
288298

289299
[Theory]

0 commit comments

Comments
 (0)