Skip to content

Commit 804482d

Browse files
authored
Revert "Add support for user-supplied project file detection (#2684)" (#2687)
This reverts commit 1aab1c0.
1 parent 3904631 commit 804482d

19 files changed

+17
-243
lines changed

BenchmarkDotNet.sln

-7
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Exporters.P
5959
EndProject
6060
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Exporters.Plotting.Tests", "tests\BenchmarkDotNet.Exporters.Plotting.Tests\BenchmarkDotNet.Exporters.Plotting.Tests.csproj", "{199AC83E-30BD-40CD-87CE-0C838AC0320D}"
6161
EndProject
62-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.IntegrationTests.FileLocators", "tests\BenchmarkDotNet.IntegrationTests.FileLocators\BenchmarkDotNet.IntegrationTests.FileLocators.csproj", "{7AD9FCF9-69B5-4984-93AC-D6E30344DADC}"
63-
EndProject
6462
Global
6563
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6664
Debug|Any CPU = Debug|Any CPU
@@ -163,10 +161,6 @@ Global
163161
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Debug|Any CPU.Build.0 = Debug|Any CPU
164162
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.ActiveCfg = Release|Any CPU
165163
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.Build.0 = Release|Any CPU
166-
{7AD9FCF9-69B5-4984-93AC-D6E30344DADC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167-
{7AD9FCF9-69B5-4984-93AC-D6E30344DADC}.Debug|Any CPU.Build.0 = Debug|Any CPU
168-
{7AD9FCF9-69B5-4984-93AC-D6E30344DADC}.Release|Any CPU.ActiveCfg = Release|Any CPU
169-
{7AD9FCF9-69B5-4984-93AC-D6E30344DADC}.Release|Any CPU.Build.0 = Release|Any CPU
170164
EndGlobalSection
171165
GlobalSection(SolutionProperties) = preSolution
172166
HideSolutionNode = FALSE
@@ -196,7 +190,6 @@ Global
196190
{2E2283A3-6DA6-4482-8518-99D6D9F689AB} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
197191
{B92ECCEF-7C27-4012-9E19-679F3C40A6A6} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
198192
{199AC83E-30BD-40CD-87CE-0C838AC0320D} = {14195214-591A-45B7-851A-19D3BA2413F9}
199-
{7AD9FCF9-69B5-4984-93AC-D6E30344DADC} = {14195214-591A-45B7-851A-19D3BA2413F9}
200193
EndGlobalSection
201194
GlobalSection(ExtensibilityGlobals) = postSolution
202195
SolutionGuid = {4D9AF12B-1F7F-45A7-9E8C-E4E46ADCBD1F}

src/BenchmarkDotNet/Configs/DebugConfig.cs

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using BenchmarkDotNet.Exporters;
99
using BenchmarkDotNet.Filters;
1010
using BenchmarkDotNet.Jobs;
11-
using BenchmarkDotNet.Locators;
1211
using BenchmarkDotNet.Loggers;
1312
using BenchmarkDotNet.Order;
1413
using BenchmarkDotNet.Reports;
@@ -59,7 +58,6 @@ public abstract class DebugConfig : IConfig
5958
public IEnumerable<IValidator> GetValidators() => Array.Empty<IValidator>();
6059
public IEnumerable<IColumnProvider> GetColumnProviders() => DefaultColumnProviders.Instance;
6160
public IEnumerable<IExporter> GetExporters() => Array.Empty<IExporter>();
62-
public IEnumerable<IFileLocator> GetFileLocators() => Array.Empty<IFileLocator>();
6361
public IEnumerable<ILogger> GetLoggers() => new[] { ConsoleLogger.Default };
6462
public IEnumerable<IDiagnoser> GetDiagnosers() => Array.Empty<IDiagnoser>();
6563
public IEnumerable<IAnalyser> GetAnalysers() => Array.Empty<IAnalyser>();

src/BenchmarkDotNet/Configs/DefaultConfig.cs

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using BenchmarkDotNet.Exporters.Csv;
1212
using BenchmarkDotNet.Filters;
1313
using BenchmarkDotNet.Jobs;
14-
using BenchmarkDotNet.Locators;
1514
using BenchmarkDotNet.Loggers;
1615
using BenchmarkDotNet.Order;
1716
using BenchmarkDotNet.Portability;
@@ -41,8 +40,6 @@ public IEnumerable<IExporter> GetExporters()
4140
yield return HtmlExporter.Default;
4241
}
4342

44-
public IEnumerable<IFileLocator> GetFileLocators() => Array.Empty<IFileLocator>();
45-
4643
public IEnumerable<ILogger> GetLoggers()
4744
{
4845
if (LinqPadLogger.IsAvailable)

src/BenchmarkDotNet/Configs/IConfig.cs

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using BenchmarkDotNet.Exporters;
99
using BenchmarkDotNet.Filters;
1010
using BenchmarkDotNet.Jobs;
11-
using BenchmarkDotNet.Locators;
1211
using BenchmarkDotNet.Loggers;
1312
using BenchmarkDotNet.Order;
1413
using BenchmarkDotNet.Reports;
@@ -21,7 +20,6 @@ public interface IConfig
2120
{
2221
IEnumerable<IColumnProvider> GetColumnProviders();
2322
IEnumerable<IExporter> GetExporters();
24-
IEnumerable<IFileLocator> GetFileLocators();
2523
IEnumerable<ILogger> GetLoggers();
2624
IEnumerable<IDiagnoser> GetDiagnosers();
2725
IEnumerable<IAnalyser> GetAnalysers();

src/BenchmarkDotNet/Configs/ImmutableConfig.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
44
using System.Globalization;
@@ -10,7 +10,6 @@
1010
using BenchmarkDotNet.Exporters;
1111
using BenchmarkDotNet.Filters;
1212
using BenchmarkDotNet.Jobs;
13-
using BenchmarkDotNet.Locators;
1413
using BenchmarkDotNet.Loggers;
1514
using BenchmarkDotNet.Order;
1615
using BenchmarkDotNet.Reports;
@@ -25,7 +24,6 @@ public sealed class ImmutableConfig : IConfig
2524
// if something is an array here instead of hashset it means it must have a guaranteed order of elements
2625
private readonly ImmutableArray<IColumnProvider> columnProviders;
2726
private readonly ImmutableArray<IExporter> exporters;
28-
private readonly ImmutableArray<IFileLocator> fileLocators;
2927
private readonly ImmutableHashSet<ILogger> loggers;
3028
private readonly ImmutableHashSet<IDiagnoser> diagnosers;
3129
private readonly ImmutableHashSet<IAnalyser> analysers;
@@ -43,7 +41,6 @@ internal ImmutableConfig(
4341
ImmutableHashSet<HardwareCounter> uniqueHardwareCounters,
4442
ImmutableHashSet<IDiagnoser> uniqueDiagnosers,
4543
ImmutableArray<IExporter> uniqueExporters,
46-
ImmutableArray<IFileLocator> uniqueFileLocators,
4744
ImmutableHashSet<IAnalyser> uniqueAnalyzers,
4845
ImmutableHashSet<IValidator> uniqueValidators,
4946
ImmutableHashSet<IFilter> uniqueFilters,
@@ -66,7 +63,6 @@ internal ImmutableConfig(
6663
hardwareCounters = uniqueHardwareCounters;
6764
diagnosers = uniqueDiagnosers;
6865
exporters = uniqueExporters;
69-
fileLocators = uniqueFileLocators;
7066
analysers = uniqueAnalyzers;
7167
validators = uniqueValidators;
7268
filters = uniqueFilters;
@@ -96,7 +92,6 @@ internal ImmutableConfig(
9692

9793
public IEnumerable<IColumnProvider> GetColumnProviders() => columnProviders;
9894
public IEnumerable<IExporter> GetExporters() => exporters;
99-
public IEnumerable<IFileLocator> GetFileLocators() => fileLocators;
10095
public IEnumerable<ILogger> GetLoggers() => loggers;
10196
public IEnumerable<IDiagnoser> GetDiagnosers() => diagnosers;
10297
public IEnumerable<IAnalyser> GetAnalysers() => analysers;

src/BenchmarkDotNet/Configs/ImmutableConfigBuilder.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Collections.Immutable;
33
using System.Linq;
44
using BenchmarkDotNet.Analysers;
@@ -44,7 +44,6 @@ public static ImmutableConfig Create(IConfig source)
4444
var uniqueHardwareCounters = source.GetHardwareCounters().Where(counter => counter != HardwareCounter.NotSet).ToImmutableHashSet();
4545
var uniqueDiagnosers = GetDiagnosers(source.GetDiagnosers(), uniqueHardwareCounters);
4646
var uniqueExporters = GetExporters(source.GetExporters(), uniqueDiagnosers, configAnalyse);
47-
var uniqueFileLocators = source.GetFileLocators().ToImmutableArray();
4847
var uniqueAnalyzers = GetAnalysers(source.GetAnalysers(), uniqueDiagnosers);
4948

5049
var uniqueValidators = GetValidators(source.GetValidators(), MandatoryValidators, source.Options);
@@ -62,7 +61,6 @@ public static ImmutableConfig Create(IConfig source)
6261
uniqueHardwareCounters,
6362
uniqueDiagnosers,
6463
uniqueExporters,
65-
uniqueFileLocators,
6664
uniqueAnalyzers,
6765
uniqueValidators,
6866
uniqueFilters,

src/BenchmarkDotNet/Configs/ManualConfig.cs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Globalization;
@@ -11,7 +11,6 @@
1111
using BenchmarkDotNet.Extensions;
1212
using BenchmarkDotNet.Filters;
1313
using BenchmarkDotNet.Jobs;
14-
using BenchmarkDotNet.Locators;
1514
using BenchmarkDotNet.Loggers;
1615
using BenchmarkDotNet.Order;
1716
using BenchmarkDotNet.Reports;
@@ -27,7 +26,6 @@ public class ManualConfig : IConfig
2726

2827
private readonly List<IColumnProvider> columnProviders = new List<IColumnProvider>();
2928
private readonly List<IExporter> exporters = new List<IExporter>();
30-
private readonly List<IFileLocator> locators = new List<IFileLocator>();
3129
private readonly List<ILogger> loggers = new List<ILogger>();
3230
private readonly List<IDiagnoser> diagnosers = new List<IDiagnoser>();
3331
private readonly List<IAnalyser> analysers = new List<IAnalyser>();
@@ -41,7 +39,6 @@ public class ManualConfig : IConfig
4139

4240
public IEnumerable<IColumnProvider> GetColumnProviders() => columnProviders;
4341
public IEnumerable<IExporter> GetExporters() => exporters;
44-
public IEnumerable<IFileLocator> GetFileLocators() => locators;
4542
public IEnumerable<ILogger> GetLoggers() => loggers;
4643
public IEnumerable<IDiagnoser> GetDiagnosers() => diagnosers;
4744
public IEnumerable<IAnalyser> GetAnalysers() => analysers;
@@ -142,12 +139,6 @@ public ManualConfig AddExporter(params IExporter[] newExporters)
142139
return this;
143140
}
144141

145-
public ManualConfig AddFileLocator(params IFileLocator[] newLocators)
146-
{
147-
locators.AddRange(newLocators);
148-
return this;
149-
}
150-
151142
[EditorBrowsable(EditorBrowsableState.Never)]
152143
[Obsolete("This method will soon be removed, please start using .AddLogger() instead.")]
153144
public void Add(params ILogger[] newLoggers) => AddLogger(newLoggers);
@@ -265,7 +256,6 @@ public void Add(IConfig config)
265256
{
266257
columnProviders.AddRange(config.GetColumnProviders());
267258
exporters.AddRange(config.GetExporters());
268-
locators.AddRange(config.GetFileLocators());
269259
loggers.AddRange(config.GetLoggers());
270260
diagnosers.AddRange(config.GetDiagnosers());
271261
analysers.AddRange(config.GetAnalysers());

src/BenchmarkDotNet/Locators/FileLocatorArgs.cs

-16
This file was deleted.

src/BenchmarkDotNet/Locators/FileLocatorType.cs

-6
This file was deleted.

src/BenchmarkDotNet/Locators/IFileLocator.cs

-22
This file was deleted.

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

+7-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Collections.Immutable;
44
using System.Diagnostics.CodeAnalysis;
@@ -11,7 +11,6 @@
1111
using BenchmarkDotNet.Extensions;
1212
using BenchmarkDotNet.Helpers;
1313
using BenchmarkDotNet.Jobs;
14-
using BenchmarkDotNet.Locators;
1514
using BenchmarkDotNet.Loggers;
1615
using BenchmarkDotNet.Running;
1716
using BenchmarkDotNet.Toolchains.DotNetCli;
@@ -72,7 +71,7 @@ protected override string GetIntermediateDirectoryPath(string buildArtifactsDire
7271
protected override void GenerateProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger)
7372
{
7473
var benchmark = buildPartition.RepresentativeBenchmarkCase;
75-
var projectFile = GetProjectFilePath(benchmark, logger);
74+
var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger);
7675

7776
var xmlDoc = new XmlDocument();
7877
xmlDoc.Load(projectFile.FullName);
@@ -247,29 +246,8 @@ private static string GetIndentedXmlString(XmlDocument doc)
247246
/// returns a path to the project file which defines the benchmarks
248247
/// </summary>
249248
[PublicAPI]
250-
protected virtual FileInfo GetProjectFilePath(BenchmarkCase benchmark, ILogger logger)
249+
protected virtual FileInfo GetProjectFilePath(Type benchmarkTarget, ILogger logger)
251250
{
252-
var args = new FileLocatorArgs(benchmark, logger);
253-
254-
// Try locators first. Logic is provided by the user for uses-cases such as they have set AssemblyName to a custom value.
255-
var notFound = new List<string>();
256-
foreach (var locator in benchmark.Config.GetFileLocators())
257-
{
258-
if (locator.LocatorType != FileLocatorType.Project)
259-
{
260-
continue;
261-
}
262-
263-
if (locator.TryLocate(args, out var fileInfo))
264-
{
265-
if (fileInfo.Exists)
266-
return fileInfo;
267-
268-
notFound.Add(fileInfo.FullName);
269-
}
270-
}
271-
272-
// Fall back to default project detection logic
273251
if (!GetSolutionRootDirectory(out var rootDirectory) && !GetProjectRootDirectory(out rootDirectory))
274252
{
275253
logger.WriteLineError(
@@ -278,7 +256,7 @@ protected virtual FileInfo GetProjectFilePath(BenchmarkCase benchmark, ILogger l
278256
}
279257

280258
// important assumption! project's file name === output dll name
281-
string projectName = benchmark.Descriptor.Type.GetTypeInfo().Assembly.GetName().Name;
259+
string projectName = benchmarkTarget.GetTypeInfo().Assembly.GetName().Name;
282260

283261
var possibleNames = new HashSet<string> { $"{projectName}.csproj", $"{projectName}.fsproj", $"{projectName}.vbproj" };
284262
var projectFiles = rootDirectory
@@ -288,18 +266,12 @@ protected virtual FileInfo GetProjectFilePath(BenchmarkCase benchmark, ILogger l
288266

289267
if (projectFiles.Length == 0)
290268
{
291-
string message;
292-
293-
if (notFound.Count > 0)
294-
message = $"Unable to find {projectName} in any of the paths: {string.Join(", ", notFound)} or in {rootDirectory.FullName} and its subfolders";
295-
else
296-
message = $"Unable to find {projectName} in {rootDirectory.FullName} and its subfolders. Most probably the name of output exe is different than the name of the .(c/f)sproj. You can add an IFileLocator to the config if this is on purpose.";
297-
298-
throw new FileNotFoundException(message);
269+
throw new NotSupportedException(
270+
$"Unable to find {projectName} in {rootDirectory.FullName} and its subfolders. Most probably the name of output exe is different than the name of the .(c/f)sproj");
299271
}
300272
else if (projectFiles.Length > 1)
301273
{
302-
throw new InvalidOperationException(
274+
throw new NotSupportedException(
303275
$"Found more than one matching project file for {projectName} in {rootDirectory.FullName} and its subfolders: {string.Join(",", projectFiles.Select(pf => $"'{pf.FullName}'"))}. Benchmark project names needs to be unique.");
304276
}
305277

src/BenchmarkDotNet/Toolchains/MonoAotLLVM/MonoAotLLVMGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public MonoAotLLVMGenerator(string targetFrameworkMoniker, string cliPath, strin
2828
protected override void GenerateProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger)
2929
{
3030
BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase;
31-
var projectFile = GetProjectFilePath(benchmark, logger);
31+
var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger);
3232

3333
string useLLVM = AotCompilerMode == MonoAotCompilerMode.llvm ? "true" : "false";
3434

src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
4141
protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, bool aot, ILogger logger)
4242
{
4343
BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase;
44-
var projectFile = GetProjectFilePath(benchmark, logger);
44+
var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger);
4545

4646
WasmRuntime runtime = (WasmRuntime) buildPartition.Runtime;
4747

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
151151
</ItemGroup>
152152
<ItemGroup>
153153
{GetILCompilerPackageReference()}
154-
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase, logger).FullName}"" />
154+
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).FullName}"" />
155155
</ItemGroup>
156156
<ItemGroup>
157-
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
157+
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
158158
</ItemGroup>
159159
{GetCustomProperties(buildPartition, logger)}
160160
</Project>";
161161

162162
private string GetCustomProperties(BuildPartition buildPartition, ILogger logger)
163163
{
164-
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase, logger);
164+
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger);
165165
var xmlDoc = new XmlDocument();
166166
xmlDoc.Load(projectFile.FullName);
167167

@@ -186,11 +186,11 @@ private string GetInstructionSetSettings(BuildPartition buildPartition)
186186
return !string.IsNullOrEmpty(instructionSet) ? $"<IlcInstructionSet>{instructionSet}</IlcInstructionSet>" : "";
187187
}
188188

189-
public IEnumerable<string> GetRdXmlFiles(BenchmarkCase benchmark, ILogger logger)
189+
public IEnumerable<string> GetRdXmlFiles(Type benchmarkTarget, ILogger logger)
190190
{
191191
yield return GeneratedRdXmlFileName;
192192

193-
var projectFile = GetProjectFilePath(benchmark, logger);
193+
var projectFile = GetProjectFilePath(benchmarkTarget, logger);
194194
var projectFileFolder = projectFile.DirectoryName;
195195
var rdXml = Path.Combine(projectFileFolder, "rd.xml");
196196
if (File.Exists(rdXml))

tests/BenchmarkDotNet.IntegrationTests.FileLocators/AssemblyNameIsSetBenchmarks.cs

-13
This file was deleted.

0 commit comments

Comments
 (0)