Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NodeReuse property to DotNetMSBuildSettings #4194

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Cake.Common.Tests.Fixtures.Tools;
using Cake.Common.Tests.Fixtures.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.MSBuild;
Expand Down Expand Up @@ -801,6 +802,20 @@ public void Should_Add_Host_Arguments()
// Then
Assert.Equal("--diagnostics msbuild", result.Args);
}

[Fact]
public void Should_Use_Node_Reuse_If_Specified()
{
// Given
var fixture = new DotNetMSBuildBuilderFixture();
fixture.Settings.NodeReuse = true;

// When
var result = fixture.Run();

// Then
Assert.Equal("msbuild /nodeReuse:true", result.Args);
}
}

public class TheConsoleLoggerSettingsProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,37 @@ public void Should_Return_The_Same_Configuration()
}
}

public sealed class TheNodeReuseMethod
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Should_Set_Node_Reuse(bool reuse)
{
// Given
var settings = new DotNetMSBuildSettings();

// When
settings.SetNodeReuse(reuse);

// Then
Assert.Equal(reuse, settings.NodeReuse);
}

[Fact]
public void Should_Return_The_Same_Configuration()
{
// Given
var settings = new DotNetMSBuildSettings();

// When
var result = settings.SetNodeReuse(true);

// Then
Assert.Equal(settings, result);
}
}

public sealed class TheSetConfigurationMethod
{
private const string Configuration = "TheConfiguration";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,18 @@ public void Should_Be_Empty_By_Default()
Assert.Empty(settings.DistributedLoggers);
}
}

public sealed class TheNodeReuseProperty
{
[Fact]
public void Should_Be_Null_By_Default()
{
// Given
var settings = new DotNetMSBuildSettings();

// Then
Assert.Null(settings.NodeReuse);
}
}
}
}
7 changes: 7 additions & 0 deletions src/Cake.Common/Tools/DotNet/MSBuild/DotNetMSBuildSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ public string PackageReleaseNotes
/// </summary>
public IList<string> WarningCodesAsMessage { get; }

/// <summary>
/// Gets or sets a value indicating whether or not node reuse is used.
/// When you’re doing multiple builds in a row, this helps reduce your total build time,
/// by avoiding the start up costs of each MSBuild child node.
/// </summary>
public bool? NodeReuse { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="DotNetMSBuildSettings"/> class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@ public static DotNetMSBuildSettings TreatAllWarningsAs(this DotNetMSBuildSetting
return settings;
}

/// <summary>
/// Sets whether or not node reuse should be enabled.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="reuse"><c>true</c> if node reuse should be enabled; otherwise <c>false</c>.</param>
/// <returns>The same <see cref="DotNetMSBuildSettings"/> instance so that multiple calls can be chained.</returns>
public static DotNetMSBuildSettings SetNodeReuse(this DotNetMSBuildSettings settings, bool reuse)
{
EnsureSettings(settings);

settings.NodeReuse = reuse;
return settings;
}

/// <summary>
/// Sets the configuration.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public static void AppendMSBuildSettings(this ProcessArgumentBuilder builder, Do
msBuilder.AppendMSBuildSwitch("property", $"ContinuousIntegrationBuild={continuousIntegrationBuild}");
}

// Re-use of MSBuild nodes?
if (settings.NodeReuse.HasValue)
{
msBuilder.Append(string.Concat("/nodeReuse:", settings.NodeReuse.Value ? "true" : "false"));
}

builder.AppendRange(
invokeArgumentCustomization
? settings.ArgumentCustomization?.Invoke(msBuilder) ?? msBuilder
Expand Down
Loading