Skip to content

Commit

Permalink
[release/7.0.3xx] [msbuild] Add support to the ResolveNativeReference…
Browse files Browse the repository at this point in the history
…s task to execute remotely. Fixes xamarin#19027.

It looks like ResolveNativeReferences was always intended to execute remotely
from Windows (when used in the _ExpandNativeReferences target, the task is
given a session id, and only called when IsMacEnabled=true), but the task
itself never implemented the code to execute remotely.

Weirdly enough this was never an issue, because the task never did something
that had to be done on a Mac.

That is, until recently, when the task learned to decompress zip files, by
executing /usr/bin/unzip.

Obviously this doesn't work on Windows, so fix it by adding support for the
task to execute remotely.

Fixes xamarin#19027.

Backport of xamarin#19047.
  • Loading branch information
rolfbjarne committed Sep 19, 2023
1 parent c70a2f5 commit 33c5c96
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
4 changes: 0 additions & 4 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/ResolveNativeReferences.cs

This file was deleted.

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

using Microsoft.Build.Framework;
Expand All @@ -10,12 +11,13 @@
using Xamarin.MacDev;
using Xamarin.MacDev.Tasks;
using Xamarin.Localization.MSBuild;
using Xamarin.Messaging.Build.Client;

#nullable enable

namespace Xamarin.MacDev.Tasks {

public abstract class ResolveNativeReferencesBase : XamarinTask {
public class ResolveNativeReferences : XamarinTask, ITaskCallback {
#region Inputs

[Required]
Expand Down Expand Up @@ -57,6 +59,14 @@ public abstract class ResolveNativeReferencesBase : XamarinTask {
}

public override bool Execute ()
{
if (ShouldExecuteRemotely ())
return new TaskRunner (SessionId, BuildEngine4).RunAsync (this).Result;

return ExecuteLocally ();
}

bool ExecuteLocally ()
{
var native_frameworks = new List<ITaskItem> ();

Expand Down Expand Up @@ -270,5 +280,28 @@ void ProcessSidecar (ITaskItem r, string resources, List<ITaskItem> native_frame
}
return String.Empty;
}

public void Cancel ()
{
if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (BuildEngine4).Wait ();
}

public bool ShouldCopyToBuildServer (ITaskItem item) => true;

public bool ShouldCreateOutputFile (ITaskItem item)
{
if (NativeFrameworks is not null && Array.IndexOf (NativeFrameworks, item) >= 0) {
// Don't copy any resolved frameworks back to Windows, because
// 1. They're not used in Inputs/Outputs, so the lack of them won't affect anything
// 2. They may be directories, and as such we'd have to expand them to (potentially numerous and large) files to copy them (uselessly) to Windows.
// 3. They may contain symlinks, which may not work correctly on Windows.
return false;
}

return true;
}

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => Enumerable.Empty<ITaskItem> ();
}
}
Expand Up @@ -30,7 +30,7 @@ public void Xcode12_x (string platform, string variant, string architecture, str
// on Xcode 12.2+ you get arm64 for all (iOS, tvOS and watchOS) simulators
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-xcode12.2.plist");
var plist = PDictionary.FromFile (path);
var result = ResolveNativeReferencesBase.ResolveXCFramework (plist, platform, variant, architecture);
var result = ResolveNativeReferences.ResolveXCFramework (plist, platform, variant, architecture);
Assert.That (result, Is.EqualTo (expected), expected);
}

Expand All @@ -42,15 +42,15 @@ public void PreXcode12 (string platform, string variant, string architecture, st
{
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist");
var plist = PDictionary.FromFile (path);
var result = ResolveNativeReferencesBase.ResolveXCFramework (plist, platform, variant, architecture);
var result = ResolveNativeReferences.ResolveXCFramework (plist, platform, variant, architecture);
Assert.That (result, Is.EqualTo (expected), expected);
}

[Test]
public void BadInfoPlist ()
{
var plist = new PDictionary ();
var result = ResolveNativeReferencesBase.ResolveXCFramework (plist, "iOS", null, "x86_64");
var result = ResolveNativeReferences.ResolveXCFramework (plist, "iOS", null, "x86_64");
Assert.Null (result, "Invalid Info.plist");
}
}
Expand Down

0 comments on commit 33c5c96

Please sign in to comment.