|
| 1 | +using System.IO; |
| 2 | +using System.Text; |
| 3 | +using System.Xml; |
| 4 | +using BenchmarkDotNet.Detectors; |
| 5 | +using BenchmarkDotNet.Extensions; |
| 6 | +using BenchmarkDotNet.Helpers; |
| 7 | +using BenchmarkDotNet.Loggers; |
| 8 | +using BenchmarkDotNet.Running; |
| 9 | +using BenchmarkDotNet.Toolchains.CsProj; |
| 10 | +using BenchmarkDotNet.Toolchains.DotNetCli; |
| 11 | + |
| 12 | +namespace BenchmarkDotNet.Toolchains.R2R |
| 13 | +{ |
| 14 | + public class R2RGenerator : CsProjGenerator |
| 15 | + { |
| 16 | + private readonly string CustomRuntimePack; |
| 17 | + private readonly string Crossgen2Pack; |
| 18 | + |
| 19 | + public R2RGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, string customRuntimePack, string crossgen2Pack) |
| 20 | + : base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion: null) |
| 21 | + { |
| 22 | + CustomRuntimePack = customRuntimePack; |
| 23 | + Crossgen2Pack = crossgen2Pack; |
| 24 | + BenchmarkRunCallType = Code.CodeGenBenchmarkRunCallType.Direct; |
| 25 | + } |
| 26 | + |
| 27 | + protected override void GenerateProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) |
| 28 | + { |
| 29 | + BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase; |
| 30 | + var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger); |
| 31 | + |
| 32 | + var xmlDoc = new XmlDocument(); |
| 33 | + xmlDoc.Load(projectFile.FullName); |
| 34 | + var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile); |
| 35 | + |
| 36 | + string content = new StringBuilder(ResourceHelper.LoadTemplate("R2RCsProj.txt")) |
| 37 | + .Replace("$PLATFORM$", buildPartition.Platform.ToConfig()) |
| 38 | + .Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath)) |
| 39 | + .Replace("$CSPROJPATH$", projectFile.FullName) |
| 40 | + .Replace("$TFM$", TargetFrameworkMoniker) |
| 41 | + .Replace("$PROGRAMNAME$", artifactsPaths.ProgramName) |
| 42 | + .Replace("$COPIEDSETTINGS$", customProperties) |
| 43 | + .Replace("$SDKNAME$", sdkName) |
| 44 | + .Replace("$RUNTIMEPACK$", CustomRuntimePack) |
| 45 | + .Replace("$CROSSGEN2PACK$", Crossgen2Pack) |
| 46 | + .Replace("$RUNTIMEIDENTIFIER$", CustomDotNetCliToolchainBuilder.GetPortableRuntimeIdentifier()) |
| 47 | + .ToString(); |
| 48 | + |
| 49 | + File.WriteAllText(artifactsPaths.ProjectFilePath, content); |
| 50 | + |
| 51 | + GatherReferences(buildPartition, artifactsPaths, logger); |
| 52 | + } |
| 53 | + |
| 54 | + protected override string GetExecutableExtension() => OsDetector.ExecutableExtension; |
| 55 | + |
| 56 | + protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration) |
| 57 | + => Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker, CustomDotNetCliToolchainBuilder.GetPortableRuntimeIdentifier(), "publish"); |
| 58 | + } |
| 59 | +} |
0 commit comments