Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Add support to the ResolveNativeReferences task to execute remotely. Fixes #19027. #19047

Merged
merged 2 commits into from Sep 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Expand Up @@ -13,6 +13,7 @@
using Xamarin.Bundler;
using Xamarin.MacDev.Tasks;
using Xamarin.Localization.MSBuild;
using Xamarin.Messaging.Build.Client;
using Xamarin.Utils;

#nullable enable
Expand All @@ -38,7 +39,7 @@ namespace Xamarin.MacDev.Tasks {
// and a zip may contain symlinks for a different platform (and thus won't be needed). Example: an xcframework
// with a framework for macOS will likely have symlinks, but that shouldn't prevent the xcframework from being
// consumed in a build for iOS.
public abstract class ResolveNativeReferencesBase : XamarinTask {
public class ResolveNativeReferences : XamarinTask, ITaskCallback {
#region Inputs

[Required]
Expand Down Expand Up @@ -99,6 +100,14 @@ string GetIntermediateDecompressionDir (string item)
}

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

return ExecuteLocally ();
}

bool ExecuteLocally ()
{
var native_frameworks = new List<ITaskItem> ();
var createdFiles = new List<string> ();
Expand Down Expand Up @@ -497,5 +506,24 @@ internal static bool TryResolveXCFramework (TaskLoggingHelper log, PDictionary p
log.LogError (MSBStrings.E0175 /* No matching framework found inside '{0}'. SupportedPlatform: '{0}', SupportedPlatformVariant: '{1}', SupportedArchitectures: '{2}'. */, xcframeworkPath, platformName, variant, architectures);
return false;
}

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

public bool ShouldCopyToBuildServer (ITaskItem item) => true;

public bool ShouldCreateOutputFile (ITaskItem item)
{
// Don't copy any files 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;
}

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => Enumerable.Empty<ITaskItem> ();
}
}
Expand Up @@ -40,7 +40,7 @@ public void Xcode12_x (string targetFrameworkMoniker, bool isSimulator, string a
// 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.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result");
Assert.That (frameworkPath, Is.EqualTo (expected), "frameworkPath");
}
Expand All @@ -53,7 +53,7 @@ public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string
{
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Resources", "xcf-prexcode12.plist");
var plist = PDictionary.FromFile (path);
var result = ResolveNativeReferencesBase.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", targetFrameworkMoniker, isSimulator, architecture, out var frameworkPath);
Assert.AreEqual (result, !string.IsNullOrEmpty (expected), "result");
Assert.That (frameworkPath, Is.EqualTo (expected), "frameworkPath");
}
Expand All @@ -62,7 +62,7 @@ public void PreXcode12 (string targetFrameworkMoniker, bool isSimulator, string
public void BadInfoPlist ()
{
var plist = new PDictionary ();
var result = ResolveNativeReferencesBase.TryResolveXCFramework (log, plist, "N/A", TargetFramework.DotNet_iOS_String, false, "x86_64", out var frameworkPath);
var result = ResolveNativeReferences.TryResolveXCFramework (log, plist, "N/A", TargetFramework.DotNet_iOS_String, false, "x86_64", out var frameworkPath);
Assert.IsFalse (result, "Invalid Info.plist");
}
}
Expand Down