Skip to content

Commit

Permalink
Pass PublishDir property to dotnet.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Dec 14, 2024
1 parent abd3720 commit e20dd82
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/BenchmarkDotNet/Templates/MonoAOTLLVMCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>bin</OutputPath>
<TargetFramework>$TFM$</TargetFramework>
<MicrosoftNetCoreAppRuntimePackDir>$RUNTIMEPACK$</MicrosoftNetCoreAppRuntimePackDir>
<RuntimeIdentifier>$RUNTIMEIDENTIFIER$</RuntimeIdentifier>
Expand Down
7 changes: 3 additions & 4 deletions src/BenchmarkDotNet/Templates/WasmCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>bin</OutputPath>
<RuntimeConfig>Release</RuntimeConfig>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetFramework>$TFM$</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppDir>$(MSBuildThisFileDirectory)\bin\$TFM$\browser-wasm\publish</AppDir>
<AppDir>$(PublishDir)</AppDir>
<AssemblyName>$PROGRAMNAME$</AssemblyName>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
Expand Down Expand Up @@ -49,8 +48,8 @@

<Target Name="PrepareForWasmBuild" AfterTargets="Publish">
<ItemGroup>
<WasmAssembliesToBundle Include="$(TargetDir)publish\*.dll" Condition="'$(RunAOTCompilation)' != 'true'" />
<WasmAssembliesToBundle Include="$(TargetDir)publish\*.dll" Exclude="$(TargetDir)publish\KernelTraceControl.dll" Condition="'$(RunAOTCompilation)' == 'true'" />
<WasmAssembliesToBundle Include="$(PublishDir)*.dll" Condition="'$(RunAOTCompilation)' != 'true'" />
<WasmAssembliesToBundle Include="$(PublishDir)*.dll" Exclude="$(PublishDir)KernelTraceControl.dll" Condition="'$(RunAOTCompilation)' == 'true'" />
</ItemGroup>
</Target>

Expand Down
5 changes: 4 additions & 1 deletion src/BenchmarkDotNet/Toolchains/ArtifactsPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace BenchmarkDotNet.Toolchains
{
public class ArtifactsPaths
{
public static readonly ArtifactsPaths Empty = new ArtifactsPaths("", "", "", "", "", "", "", "", "", "", "", "");
public static readonly ArtifactsPaths Empty = new ArtifactsPaths("", "", "", "", "", "", "", "", "", "", "", "", "");

[PublicAPI] public string RootArtifactsFolderPath { get; }
[PublicAPI] public string BuildArtifactsDirectoryPath { get; }
[PublicAPI] public string PublishDirectoryPath { get; }
[PublicAPI] public string BinariesDirectoryPath { get; }
[PublicAPI] public string IntermediateDirectoryPath { get; }
[PublicAPI] public string ProgramCodePath { get; }
Expand All @@ -22,6 +23,7 @@ public class ArtifactsPaths
public ArtifactsPaths(
string rootArtifactsFolderPath,
string buildArtifactsDirectoryPath,
string publishDirectoryPath,
string binariesDirectoryPath,
string intermediateDirectoryPath,
string programCodePath,
Expand All @@ -35,6 +37,7 @@ public ArtifactsPaths(
{
RootArtifactsFolderPath = rootArtifactsFolderPath;
BuildArtifactsDirectoryPath = buildArtifactsDirectoryPath;
PublishDirectoryPath = publishDirectoryPath;
BinariesDirectoryPath = binariesDirectoryPath;
IntermediateDirectoryPath = intermediateDirectoryPath;
ProgramCodePath = programCodePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ internal static StringBuilder MaybeAppendOutputPaths(this StringBuilder stringBu
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
// OutputPath is legacy, per-project version of OutDir. We set both just in case. https://github.com/dotnet/msbuild/issues/87
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
.AppendArgument($"/p:PublishDir=\"{artifactsPaths.PublishDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
;
}
Expand Down
8 changes: 8 additions & 0 deletions src/BenchmarkDotNet/Toolchains/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public GenerateResult GenerateProject(BuildPartition buildPartition, ILogger log
/// </summary>
[PublicAPI] protected abstract string GetBuildArtifactsDirectoryPath(BuildPartition assemblyLocation, string programName);

/// <summary>
/// returns a path where the publish directory should be found after the build (usually \publish)
/// </summary>
[PublicAPI]
protected virtual string GetPublishDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
=> Path.Combine(buildArtifactsDirectoryPath, "publish");

/// <summary>
/// returns a path where executable should be found after the build (usually \bin)
/// </summary>
Expand Down Expand Up @@ -137,6 +144,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
return new ArtifactsPaths(
rootArtifactsFolderPath: rootArtifactsFolderPath,
buildArtifactsDirectoryPath: buildArtifactsDirectoryPath,
publishDirectoryPath: GetPublishDirectoryPath(buildArtifactsDirectoryPath, buildPartition.BuildConfiguration),
binariesDirectoryPath: binariesDirectoryPath,
intermediateDirectoryPath: GetIntermediateDirectoryPath(buildArtifactsDirectoryPath, buildPartition.BuildConfiguration),
programCodePath: Path.Combine(buildArtifactsDirectoryPath, $"{programName}{codeFileExtension}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public InProcessEmitArtifactsPath(
ArtifactsPaths baseArtifacts) : base(
baseArtifacts.RootArtifactsFolderPath,
baseArtifacts.BuildArtifactsDirectoryPath,
baseArtifacts.PublishDirectoryPath,
baseArtifacts.BinariesDirectoryPath,
baseArtifacts.IntermediateDirectoryPath,
baseArtifacts.ProgramCodePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
return new ArtifactsPaths(
rootArtifactsFolderPath: rootArtifactsFolderPath,
buildArtifactsDirectoryPath: buildArtifactsDirectoryPath,
publishDirectoryPath: null,
binariesDirectoryPath: binariesDirectoryPath,
intermediateDirectoryPath: null,
programCodePath: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
}

protected override string GetPublishDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
=> Path.Combine(GetBinariesDirectoryPath(buildArtifactsDirectoryPath, configuration), "publish");

protected override string GetExecutablePath(string binariesDirectoryPath, string programName)
=> OsDetector.IsWindows()
? Path.Combine(binariesDirectoryPath, "publish", $"{programName}.exe")
Expand Down

0 comments on commit e20dd82

Please sign in to comment.