Skip to content

Commit

Permalink
Merge pull request #4194 from Marusyk/rmarusyk/4144
Browse files Browse the repository at this point in the history
Add NodeReuse property to DotNetMSBuildSettings
  • Loading branch information
augustoproiete authored Sep 29, 2023
2 parents 6be6153 + 4ed7c72 commit 4682b35
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
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

0 comments on commit 4682b35

Please sign in to comment.