Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace BenchmarkDotNet.Toolchains.NativeAot
public class Generator : CsProjGenerator
{
internal const string NativeAotNuGetFeed = "nativeAotNuGetFeed";
internal const string GeneratedRdXmlFileName = "bdn_generated.rd.xml";

internal Generator(string ilCompilerVersion, bool useCppCodeGenerator,
string runtimeFrameworkVersion, string targetFrameworkMoniker, string cliPath,
Expand Down Expand Up @@ -150,7 +151,7 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).FullName}"" />
</ItemGroup>
<ItemGroup>
<RdXmlFile Include=""rd.xml"" />
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
</ItemGroup>
</Project>";

Expand Down Expand Up @@ -185,7 +186,7 @@ private string GenerateProjectForLocalBuild(BuildPartition buildPartition, Artif
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).FullName}"" />
</ItemGroup>
<ItemGroup>
<RdXmlFile Include=""rd.xml"" />
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
</ItemGroup>
</Project>";

Expand All @@ -203,6 +204,23 @@ private string GetTrimmingSettings()
return sb.ToString();
}

public IEnumerable<string> GetRdXmlFiles(Type benchmarkTarget, ILogger logger)
{
var projectFile = GetProjectFilePath(benchmarkTarget, logger);
var projectFileFolder = projectFile.DirectoryName;
yield return GeneratedRdXmlFileName;
var rdXml = Path.Combine(projectFileFolder, "rd.xml");
if (File.Exists(rdXml))
{
yield return rdXml;
}

foreach (var item in Directory.GetFiles(projectFileFolder, "*.rd.xml"))
{
yield return item;
}
Comment on lines +209 to +221
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like this could be simplified if we search for *rd.xm files:

Suggested change
var projectFile = GetProjectFilePath(benchmarkTarget, logger);
var projectFileFolder = projectFile.DirectoryName;
yield return GeneratedRdXmlFileName;
var rdXml = Path.Combine(projectFileFolder, "rd.xml");
if (File.Exists(rdXml))
{
yield return rdXml;
}
foreach (var item in Directory.GetFiles(projectFileFolder, "*.rd.xml"))
{
yield return item;
}
yield return GeneratedRdXmlFileName;
var projectFileFolder = GetProjectFilePath(benchmarkTarget, logger).DirectoryName;
foreach (var rdFile in Directory.GetFiles(projectFileFolder, "*rd.xml"))
{
yield return rdFile;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if somebody have library which ends with rd? or just XML files. For example Thunderbird.xml, that would be captured.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid that neither *.rd.xml and *rd.xml are good filters, as users can call their files without rd prefix like nativeaot_rules.xml. But since it's a project with BenchmarkDotNet benchmarks we could just tell them that all that we support is rd.xml. @kant2002 what do you think?

@MichalStrehovsky what is your opinion on that? Are NativeAOT using names other than rd.xml for their RdXmlFile files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my experience projects in the wild was using either just rd.xml or I recentrly start push for separate files per library, to at least simplify mundane work. Naming convention which I propose is exaclly nuget_package.rd.xml. Also seems to be .NET Native Rd.xml also has approximately same convention, so that's why I choose that pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*.rd.xml is the convention that most people are sticking with. I don't recall ever seeing an rd.xml file without that extension.

}

/// <summary>
/// mandatory to make it possible to call GC.GetAllocatedBytesForCurrentThread() using reflection (not part of .NET Standard)
/// </summary>
Expand All @@ -226,7 +244,7 @@ private void GenerateReflectionFile(ArtifactsPaths artifactsPaths)

string directoryName = Path.GetDirectoryName(artifactsPaths.ProjectFilePath);
if (directoryName != null)
File.WriteAllText(Path.Combine(directoryName, "rd.xml"), content);
File.WriteAllText(Path.Combine(directoryName, GeneratedRdXmlFileName), content);
else
throw new InvalidOperationException($"Can't get directory of projectFilePath ('{artifactsPaths.ProjectFilePath}')");
}
Expand Down