Skip to content

Commit

Permalink
[msbuild] Make the GetFileSystemEntries task capable of copying files…
Browse files Browse the repository at this point in the history
… to the Mac. (#18324)

Make the GetFileSystemEntries task capable of copying files to the Mac, and
enable this new behavior when inspecting references for binding resources.

Otherwise the task might not find anything, if the files aren't copied to the
Mac (this happens if the files originate from NuGets instead of referenced
projects).

Ref:

* https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1808448 (third attempt)
* #18308
* dotnet/maui#15042
  • Loading branch information
rolfbjarne authored May 25, 2023
1 parent 87bba7b commit 95f6c35
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,7 @@ global using nfloat = global::System.Runtime.InteropServices.NFloat%3B
Pattern="*"
Recursive="true"
IncludeDirectories="false"
CopyFromWindows="true"
>
<Output TaskParameter="Entries" ItemName="_BindingPackagesFromReferencedAssemblies" />
</GetFileSystemEntries>
Expand Down
41 changes: 40 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks/Tasks/GetFileSystemEntries.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using Xamarin.Messaging.Build.Client;

namespace Xamarin.MacDev.Tasks {
public class GetFileSystemEntries : GetFileSystemEntriesTaskBase, ICancelableTask {
public class GetFileSystemEntries : GetFileSystemEntriesTaskBase, ICancelableTask, ITaskCallback {
public override bool Execute ()
{
if (ShouldExecuteRemotely ())
Expand All @@ -16,6 +23,38 @@ public void Cancel ()
if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (BuildEngine4).Wait ();
}

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
{
if (!CopyFromWindows)
return Enumerable.Empty<ITaskItem> ();

// TaskRunner doesn't know how to copy directories to Mac, so list each file.
var rv = new List<string> ();
foreach (var path in DirectoryPath) {
var spec = path.ItemSpec;
if (!Directory.Exists (spec))
continue;

var files = Directory.GetFiles (spec, "*", SearchOption.AllDirectories);
foreach (var file in files) {
// Only copy non-empty files, so that we don't end up
// copying an empty file that happens to be an output file
// from a previous target (and thus overwriting that file
// on Windows).
var finfo = new FileInfo (file);
if (!finfo.Exists || finfo.Length == 0)
continue;
rv.Add (file);
}
}

return rv.Select (f => new TaskItem (f));
}

public bool ShouldCopyToBuildServer (ITaskItem item) => true;

public bool ShouldCreateOutputFile (ITaskItem item) => false;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public abstract class GetFileSystemEntriesTaskBase : XamarinTask {

[Required]
public bool IncludeDirectories { get; set; }

// If the input directory should be copied from Windows to the Mac in
// a remote build.
public bool CopyFromWindows { get; set; }
#endregion

#region Outputs
Expand Down

6 comments on commit 95f6c35

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.