Skip to content

Commit 56556ab

Browse files
authored
Add support for Rd.xml file around project file (#1976)
For now added either `rd.xml` or files which ends with `.rd.xml` Rename `rd.xml` supplied by BDN to `bdn_generated.rd.xml`
1 parent 5f0db4f commit 56556ab

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace BenchmarkDotNet.Toolchains.NativeAot
2020
public class Generator : CsProjGenerator
2121
{
2222
internal const string NativeAotNuGetFeed = "nativeAotNuGetFeed";
23+
internal const string GeneratedRdXmlFileName = "bdn_generated.rd.xml";
2324

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

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

@@ -203,6 +204,23 @@ private string GetTrimmingSettings()
203204
return sb.ToString();
204205
}
205206

207+
public IEnumerable<string> GetRdXmlFiles(Type benchmarkTarget, ILogger logger)
208+
{
209+
var projectFile = GetProjectFilePath(benchmarkTarget, logger);
210+
var projectFileFolder = projectFile.DirectoryName;
211+
yield return GeneratedRdXmlFileName;
212+
var rdXml = Path.Combine(projectFileFolder, "rd.xml");
213+
if (File.Exists(rdXml))
214+
{
215+
yield return rdXml;
216+
}
217+
218+
foreach (var item in Directory.GetFiles(projectFileFolder, "*.rd.xml"))
219+
{
220+
yield return item;
221+
}
222+
}
223+
206224
/// <summary>
207225
/// mandatory to make it possible to call GC.GetAllocatedBytesForCurrentThread() using reflection (not part of .NET Standard)
208226
/// </summary>
@@ -226,7 +244,7 @@ private void GenerateReflectionFile(ArtifactsPaths artifactsPaths)
226244

227245
string directoryName = Path.GetDirectoryName(artifactsPaths.ProjectFilePath);
228246
if (directoryName != null)
229-
File.WriteAllText(Path.Combine(directoryName, "rd.xml"), content);
247+
File.WriteAllText(Path.Combine(directoryName, GeneratedRdXmlFileName), content);
230248
else
231249
throw new InvalidOperationException($"Can't get directory of projectFilePath ('{artifactsPaths.ProjectFilePath}')");
232250
}

0 commit comments

Comments
 (0)