Skip to content

Commit ca505ca

Browse files
authored
[Windows] Skip running tasks with no inputs (#23458)
This is a very minor perf improvements that could help when building remotely from Windows with slow connections (i.e., from Devbox). It skips running some tasks that not always have inputs to avoid the unnecessary network round tripping. Fixes #19600
2 parents 680630d + 664631a commit ca505ca

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

msbuild/Xamarin.Localization.MSBuild/MSBStrings.resx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,4 +1621,12 @@
16211621
{2} and {3}: the different LogicalName metadata
16221622
</comment>
16231623
</data>
1624+
1625+
<data name="M7159" xml:space="preserve">
1626+
<value>Skipping {0} - {1} is empty.</value>
1627+
<comment>
1628+
{0}: the name of the MSBuild task that's being skipped (Copy, GetFullPaths, FilterStaticFrameworks, etc.).
1629+
{1}: the name of the property that is empty (SourceFiles, Items, FrameworkToPublish, etc.).
1630+
</comment>
1631+
</data>
16241632
</root>

msbuild/Xamarin.MacDev.Tasks/MsBuildTasks/Copy.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
extern alias Microsoft_Build_Tasks_Core;
22

3-
using System;
4-
using System.IO;
53
using System.Linq;
64

75
using Microsoft.Build.Framework;
86

7+
using Xamarin.Localization.MSBuild;
98
using Xamarin.Messaging.Build.Client;
109

1110
namespace Microsoft.Build.Tasks {
1211
public class Copy : Microsoft_Build_Tasks_Core::Microsoft.Build.Tasks.Copy {
1312
public string SessionId { get; set; } = string.Empty;
1413
public override bool Execute ()
1514
{
15+
if (SourceFiles?.Any () != true) {
16+
Log.LogMessage (MessageImportance.Low, MSBStrings.M7159 /* Skipping {0} - {1} is empty. */, nameof (Copy), nameof (SourceFiles));
17+
return true;
18+
}
19+
1620
if (!this.ShouldExecuteRemotely (SessionId))
1721
return base.Execute ();
1822

msbuild/Xamarin.MacDev.Tasks/Tasks/FilterStaticFrameworks.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class FilterStaticFrameworks : XamarinTask, ITaskCallback {
2222

2323
public override bool Execute ()
2424
{
25+
if (FrameworkToPublish?.Any () != true) {
26+
Log.LogMessage (MessageImportance.Low, MSBStrings.M7159 /* Skipping {0} - {1} is empty. */, nameof (FilterStaticFrameworks), nameof (FrameworkToPublish));
27+
return true;
28+
}
29+
2530
if (ShouldExecuteRemotely ())
2631
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
2732

msbuild/Xamarin.MacDev.Tasks/Tasks/GetFileSystemEntries.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public class GetFileSystemEntries : XamarinTask, ICancelableTask, ITaskCallback
4343

4444
public override bool Execute ()
4545
{
46+
if (DirectoryPath?.Any () != true) {
47+
Log.LogMessage (MessageImportance.Low, MSBStrings.M7159 /* Skipping {0} - {1} is empty. */, nameof (GetFileSystemEntries), nameof (DirectoryPath));
48+
return true;
49+
}
50+
4651
if (ShouldExecuteRemotely ())
4752
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
4853

msbuild/Xamarin.MacDev.Tasks/Tasks/GetFullPaths.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.Build.Framework;
77
using Microsoft.Build.Utilities;
88

9-
using Xamarin.MacDev.Tasks;
9+
using Xamarin.Localization.MSBuild;
1010
using Xamarin.Messaging.Build.Client;
1111

1212
#nullable enable
@@ -23,6 +23,11 @@ public class GetFullPaths : XamarinTask, ICancelableTask, ITaskCallback {
2323

2424
public override bool Execute ()
2525
{
26+
if (Items?.Any () != true) {
27+
Log.LogMessage (MessageImportance.Low, MSBStrings.M7159 /* Skipping {0} - {1} is empty. */, nameof (GetFullPaths), nameof (Items));
28+
return true;
29+
}
30+
2631
if (ShouldExecuteRemotely ())
2732
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;
2833

0 commit comments

Comments
 (0)