Skip to content

Commit

Permalink
Revert "Use a build traversal project template instead of copying csp…
Browse files Browse the repository at this point in the history
…roj template."

This reverts commit f1bc9fa.
  • Loading branch information
timcassell committed Jan 2, 2025
1 parent f1bc9fa commit 9202503
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 49 deletions.
9 changes: 0 additions & 9 deletions src/BenchmarkDotNet/Templates/BuildTraversalProj.txt

This file was deleted.

6 changes: 3 additions & 3 deletions src/BenchmarkDotNet/Toolchains/ArtifactsPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ArtifactsPaths
[PublicAPI] public string ProgramCodePath { get; }
[PublicAPI] public string AppConfigPath { get; }
[PublicAPI] public string NuGetConfigPath { get; }
[PublicAPI] public string BuildTraversalProjectFilePath { get; }
[PublicAPI] public string BuildForReferencesProjectFilePath { get; }
[PublicAPI] public string ProjectFilePath { get; }
[PublicAPI] public string BuildScriptFilePath { get; }
[PublicAPI] public string ExecutablePath { get; }
Expand All @@ -28,7 +28,7 @@ public ArtifactsPaths(
string programCodePath,
string appConfigPath,
string nuGetConfigPath,
string buildTraversalProjectFilePath,
string buildForReferencesProjectFilePath,
string projectFilePath,
string buildScriptFilePath,
string executablePath,
Expand All @@ -42,7 +42,7 @@ public ArtifactsPaths(
ProgramCodePath = programCodePath;
AppConfigPath = appConfigPath;
NuGetConfigPath = nuGetConfigPath;
BuildTraversalProjectFilePath = buildTraversalProjectFilePath;
BuildForReferencesProjectFilePath = buildForReferencesProjectFilePath;
ProjectFilePath = projectFilePath;
BuildScriptFilePath = buildScriptFilePath;
ExecutablePath = executablePath;
Expand Down
44 changes: 22 additions & 22 deletions src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override string GetProjectFilePath(string buildArtifactsDirectoryPath)
=> Path.Combine(buildArtifactsDirectoryPath, "BenchmarkDotNet.Autogenerated.csproj");

protected override string GetProjectFilePathForReferences(string buildArtifactsDirectoryPath)
=> Path.Combine(buildArtifactsDirectoryPath, "BuildTraversal.buildproj");
=> Path.Combine(buildArtifactsDirectoryPath, "BenchmarkDotNet.Autogenerated.ForReferences.csproj");

protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker);
Expand All @@ -71,8 +71,8 @@ protected override string GetIntermediateDirectoryPath(string buildArtifactsDire
=> Path.Combine(buildArtifactsDirectoryPath, "obj", configuration, TargetFrameworkMoniker);

[SuppressMessage("ReSharper", "StringLiteralTypo")] // R# complains about $variables$
private string LoadCsProj(string template, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
=> new StringBuilder(ResourceHelper.LoadTemplate(template))
private string LoadCsProj(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
=> new StringBuilder(ResourceHelper.LoadTemplate("CsProj.txt"))
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
.Replace("$CSPROJPATH$", projectFile)
Expand All @@ -88,35 +88,35 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
{
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger);

GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);

var xmlDoc = new XmlDocument();
xmlDoc.Load(projectFile.FullName);
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);

var content = new StringBuilder(ResourceHelper.LoadTemplate("CsProj.txt"))
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
.Replace("$CSPROJPATH$", projectFile.FullName)
.Replace("$TFM$", TargetFrameworkMoniker)
.Replace("$PROGRAMNAME$", artifactsPaths.ProgramName)
.Replace("$RUNTIMESETTINGS$", GetRuntimeSettings(buildPartition.RepresentativeBenchmarkCase.Job.Environment.Gc, buildPartition.Resolver))
.Replace("$COPIEDSETTINGS$", customProperties)
.Replace("$CONFIGURATIONNAME$", buildPartition.BuildConfiguration)
.Replace("$SDKNAME$", sdkName)
.ToString();
GenerateBuildForReferencesProject(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);

var content = LoadCsProj(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);

File.WriteAllText(artifactsPaths.ProjectFilePath, content);
}

protected void GenerateBuildTraversalProject(ArtifactsPaths artifactsPaths, string projectFilePath)
protected void GenerateBuildForReferencesProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
{
var content = new StringBuilder(ResourceHelper.LoadTemplate("BuildTraversalProj.txt"))
.Replace("$CSPROJPATH$", projectFilePath)
.Replace("$TFM$", TargetFrameworkMoniker)
.ToString();
var content = LoadCsProj(buildPartition, artifactsPaths, projectFile, customProperties, sdkName);

// We don't include the generated .notcs file when building the reference dlls, only in the final build.
var xmlDoc = new XmlDocument();
xmlDoc.Load(new StringReader(content));
XmlElement projectElement = xmlDoc.DocumentElement;
projectElement.RemoveChild(projectElement.SelectSingleNode("ItemGroup/Compile").ParentNode);

var startupObjectElement = projectElement.SelectSingleNode("PropertyGroup/StartupObject");
startupObjectElement.ParentNode.RemoveChild(startupObjectElement);

// We need to change the output type to library since we're only compiling for dlls.
var outputTypeElement = projectElement.SelectSingleNode("PropertyGroup/OutputType");
outputTypeElement.InnerText = "Library";

File.WriteAllText(artifactsPaths.BuildTraversalProjectFilePath, content);
xmlDoc.Save(artifactsPaths.BuildForReferencesProjectFilePath);
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DotNetCliBuilder(string targetFrameworkMoniker, string? customDotNetCliPa
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
{
var cliCommand = new DotNetCliCommand(
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
CustomDotNetCliPath,
string.Empty,
generateResult,
Expand Down Expand Up @@ -75,6 +75,11 @@ internal static void GatherReferences(ArtifactsPaths artifactsPaths)
foreach (var assemblyFile in Directory.GetFiles(artifactsPaths.BinariesDirectoryPath, "*.dll"))
{
var assemblyName = Path.GetFileNameWithoutExtension(assemblyFile);
// The dummy csproj was used to build the original project, but it also outputs a dll for itself which we need to ignore because it's not valid.
if (assemblyName == artifactsPaths.ProgramName)
{
continue;
}
var referenceElement = xmlDoc.CreateElement("Reference");
itemGroup.AppendChild(referenceElement);
referenceElement.SetAttribute("Include", assemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ protected override void CopyAllRequiredFiles(ArtifactsPaths artifactsPaths)
protected override void GenerateBuildScript(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
{
var content = new StringBuilder(300)
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DotNetCliPublisher(
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
{
var cliCommand = new DotNetCliCommand(
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
CustomDotNetCliPath,
ExtraArguments,
generateResult,
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
appConfigPath: $"{executablePath}.config",
nuGetConfigPath: Path.Combine(buildArtifactsDirectoryPath, "NuGet.config"),
projectFilePath: GetProjectFilePath(buildArtifactsDirectoryPath),
buildTraversalProjectFilePath: GetProjectFilePathForReferences(buildArtifactsDirectoryPath),
buildForReferencesProjectFilePath: GetProjectFilePathForReferences(buildArtifactsDirectoryPath),
buildScriptFilePath: Path.Combine(buildArtifactsDirectoryPath, $"{programName}{OsDetector.ScriptFileExtension}"),
executablePath: executablePath,
programName: programName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public InProcessEmitArtifactsPath(
baseArtifacts.AppConfigPath,
baseArtifacts.NuGetConfigPath,
baseArtifacts.ProjectFilePath,
baseArtifacts.BuildTraversalProjectFilePath,
baseArtifacts.BuildForReferencesProjectFilePath,
baseArtifacts.BuildScriptFilePath,
baseArtifacts.ExecutablePath,
baseArtifacts.ProgramName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
appConfigPath: null,
nuGetConfigPath: null,
projectFilePath: null,
buildTraversalProjectFilePath: null,
buildForReferencesProjectFilePath: null,
buildScriptFilePath: null,
executablePath: executablePath,
programName: programName,
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Toolchains/Mono/MonoPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MonoPublisher(string customDotNetCliPath)
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
{
var cliCommand = new DotNetCliCommand(
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
CustomDotNetCliPath,
string.Empty,
generateResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase;
var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger);

GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);

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

var xmlDoc = new XmlDocument();
xmlDoc.Load(projectFile.FullName);
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);

GenerateBuildForReferencesProject(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);

string content = new StringBuilder(ResourceHelper.LoadTemplate("MonoAOTLLVMCsProj.txt"))
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarkDotNet/Toolchains/MonoWasm/WasmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ protected void GenerateProjectFile(BuildPartition buildPartition, ArtifactsPaths
BenchmarkCase benchmark = buildPartition.RepresentativeBenchmarkCase;
var projectFile = GetProjectFilePath(benchmark.Descriptor.Type, logger);

GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);

WasmRuntime runtime = (WasmRuntime) buildPartition.Runtime;

var xmlDoc = new XmlDocument();
xmlDoc.Load(projectFile.FullName);
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);

GenerateBuildForReferencesProject(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);

string content = new StringBuilder(ResourceHelper.LoadTemplate("WasmCsProj.txt"))
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
Expand Down
10 changes: 7 additions & 3 deletions src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ protected override void GenerateBuildScript(BuildPartition buildPartition, Artif
string extraArguments = NativeAotToolchain.GetExtraArguments(runtimeIdentifier);

var content = new StringBuilder(300)
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath, extraArguments)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetPublishCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath, extraArguments)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath, extraArguments)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetPublishCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath, extraArguments)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath, extraArguments)}")
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetPublishCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath, extraArguments)}")
.ToString();
Expand Down Expand Up @@ -116,7 +116,11 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
{
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger);

GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);
var xmlDoc = new XmlDocument();
xmlDoc.Load(projectFile.FullName);
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);

GenerateBuildForReferencesProject(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);

File.WriteAllText(artifactsPaths.ProjectFilePath, GenerateProjectForNuGetBuild(buildPartition, artifactsPaths, logger));
GenerateReflectionFile(artifactsPaths);
Expand Down

0 comments on commit 9202503

Please sign in to comment.