Skip to content
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
17 changes: 12 additions & 5 deletions msbuild/Xamarin.iOS.Tasks/Tasks/MTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied ()
if (NativeReferences == null)
yield break;

foreach (var nativeRef in NativeReferences
.Where (x => Directory.Exists (x.ItemSpec))
.Select (x => x.ItemSpec))
foreach (var item in GetItemsFromNativeReference (nativeRef))
yield return item;
foreach (var nativeRef in NativeReferences) {
var path = nativeRef.ItemSpec;
// look for frameworks, if the library is part of one then bring all related files
var dir = Path.GetDirectoryName (path);
if ((Path.GetExtension (dir) == ".framework") && Directory.Exists (dir)) {
foreach (var item in GetItemsFromNativeReference (dir)) {
// don't return the native library itself (it's the original input, not something additional)
if (item.ItemSpec != path)
yield return item;
}
}
}
}

public override void Cancel ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Build.Utilities;

Expand All @@ -9,7 +10,7 @@

namespace Xamarin.iOS.Tasks
{
class CustomMTouchTask : MTouchTaskBase
class CustomMTouchTask : MTouch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetAdditionalItemsToBeCopied I modified (and added tests to) is not part of MTouchTaskBase, only from theMTouch subclass.

@emaf will correct me if needed :)

*Base tasks generally have all the logic required for running on the Mac.

The version running on Windows subclass them to add the behaviour required to remote the execution.

The version running on Mac also subclass *Base but it's empty (on purpose). That makes the msbuild target files identical (same names for tasks).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, but there are no more empty subclasses now :). Because of .NET6 we "unified" both task implementations (Windows and Mac) on this repo, but what Sebastien said is still valid:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you so much @spouliot and @emaf for those very detailed responses! Makes more sense now!

{
public CustomMTouchTask ()
{
Expand Down Expand Up @@ -298,6 +299,54 @@ public void ReferenceFrameworkFileResolution_WhenResolutionFails(string targetFr
}
}

[Test]
public void NativeReference_None ()
{
// non-framework native references do not have to copy anything else (back to Windows)

Task.NativeReferences = null;
var items = Task.GetAdditionalItemsToBeCopied ().ToArray ();
Assert.That (items.Count (), Is.EqualTo (0), "null");

Task.NativeReferences = new TaskItem [] { };
items = Task.GetAdditionalItemsToBeCopied ().ToArray ();
Assert.That (items.Count (), Is.EqualTo (0), "none");

var temp = Cache.CreateTemporaryDirectory ();
var native_lib = Path.Combine (temp, "libFoo");
File.WriteAllText (native_lib, "fake lib");
Task.NativeReferences = new [] { new TaskItem (native_lib) };
items = Task.GetAdditionalItemsToBeCopied ().ToArray ();
Assert.That (items.Count (), Is.EqualTo (0), "non-framework path");
}

[Test]
public void NativeReference_Framework ()
{
var temp = Cache.CreateTemporaryDirectory ();
var fx = Path.Combine (temp, "project", "Universal.xcframework", "macos-arm64_x86_64", "Universal.framework");
Directory.CreateDirectory (fx);

var native_lib = Path.Combine (fx, "Universal");
File.WriteAllText (native_lib, "fake lib");

// other files
File.WriteAllText (Path.Combine (fx, "Info.plist"), "fake info.plist");
var headers = Path.Combine (fx, "Headers");
Directory.CreateDirectory (headers);
File.WriteAllText (Path.Combine (headers, "Universal.h"), "fake headers");
var signature = Path.Combine (fx, "_CodeSignature");
Directory.CreateDirectory (signature);
File.WriteAllText (Path.Combine (signature, "CodeResources"), "fake resources");

// a native reference to a framework needs to bring (all of) the framework files (back to Windows)

Task.NativeReferences = new [] { new TaskItem (native_lib) };
var items = Task.GetAdditionalItemsToBeCopied ().ToArray ();
// 3 additional files (as we do not duplicate the TaskItem for the native library itself)
Assert.That (items.Count (), Is.EqualTo (3), "framework files");
}

class TempSdk : IDisposable
{
MonoTouchSdk sdk;
Expand Down