-
-
Notifications
You must be signed in to change notification settings - Fork 983
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
Add support for user-supplied project file detection #2684
Conversation
@@ -246,36 +247,32 @@ private static string GetIndentedXmlString(XmlDocument doc) | |||
/// returns a path to the project file which defines the benchmarks | |||
/// </summary> | |||
[PublicAPI] | |||
protected virtual FileInfo GetProjectFilePath(Type benchmarkTarget, ILogger logger) | |||
protected virtual FileInfo GetProjectFilePath(BenchmarkCase benchmark, ILogger logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting the breaking change to a public API.
Also the |
Most suggestions are now implemented. |
Update: ProjectLocator no longer exists. Instead, we simply give the user the ability to extend ManualConfig with a set of IFileLocators, which are executed before the default logic inside |
Can you please add an integration test? |
The only solution I can think of is a separate project. Ideally, it would be a test inBenchmarkDotNet.IntegrationTests, but I cannot think of a way to do that. Do you have any ideas? |
and rename LocatorArgs to FileLocatorArgs
Why can't you do it in fileInfo = new FileInfo(Path.Combine(dir, "../../../BenchmarkDotNet.IntegrationTests.csproj")); |
Co-authored-by: Tim Cassell <[email protected]>
I would change the assembly name of BenchmarkDotNet.IntegrationTests.csproj, which will affect all the other tests. Adding a FileLocator that points to IntegrationTests.csproj could still work, even if FileLocators don't. The fallback will find the project instead, thereby hiding a bug. So the alternative is to create a new integration test project like |
Ah, that's a good point. Yes, you can create a new project and set it up like |
An integration test has been implemented. |
Please check that the csproj has the correct properties set. There were package ids and other stuff in the other projects that seemed irrelevant. The tests also fails when running as debug. Not sure if this is intended or not. It is not something I've caused :) |
...arkDotNet.IntegrationTests.FileLocators/BenchmarkDotNet.IntegrationTests.FileLocators.csproj
Outdated
Show resolved
Hide resolved
tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. We can update the GetBuildArtifactsDirectoryPath
to support the new file locators separately.
Thanks @Genbox!
Likewise! Thanks for your help and contributions. Very much appreciated. |
This reverts commit 1aab1c0.
This update adds support for "Locators" in the IConfig interface. A Locator is an extensibility point where users can define path-handling logic that differs from the built-in logic.
For example, if the user sets
AssemblyName
in their csproj, they are forced to use the InProcess job, or else BenchmarkDotnet gives an error with:The error is caused by the built-in logic trying to find a project file relative to the project root, which has the same name as the DLL. Unfortunately, lots of projects use AssemblyName to generate a short name, different from the project name (Like GNU utilities) or prepend the owners name (like GitHub/Nuget prefixes) to avoid assembly name collisions.
The issue has been repeatedly raised on the BenchmarkDotnet issue tracker and StackOverlow. For issues, see #1019, #498, #1178, #1785 and #1927.
The code
ILocator is a new public interface where users can define their logic. The interface is implemented like this:
The LocatorType is not strictly necessary, as the locator is only used in a single place right now. However, if there are other places where the user could benefit from the extensibility, it is necessary to have to distinguish between locators.
If that is not wanted, let me know, and I'll remove it and rename ILocator to IProjectLocator to specialize the code for its intended purpose.
Users can add their locator to a ManualConfig like so:
Notes
CreateMinimumViable
includes ProjectLocator.Default