diff --git a/docs/build-apps/build-properties.md b/docs/build-apps/build-properties.md index b405f6b4833b..1fb05b7c6e4a 100644 --- a/docs/build-apps/build-properties.md +++ b/docs/build-apps/build-properties.md @@ -94,3 +94,9 @@ The default behavior is to use `xcrun metal`. The full path to the `strip` command-line tool. The default behavior is to use `xcrun strip`. + +## ZipPath + +The full path to the `zip` command-line tool. + +The default behavior is to use `xcrun zip`. diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/Zip.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/Zip.cs index b03b289c6049..e8396be02c84 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/Zip.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/Zip.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -9,51 +11,49 @@ using Xamarin.Messaging.Build.Client; using Xamarin.Utils; -// Disable until we get around to enable + fix any issues. -#nullable disable +#nullable enable namespace Xamarin.MacDev.Tasks { - public class Zip : XamarinToolTask, ITaskCallback { + public class Zip : XamarinTask, ICancelableTask { + CancellationTokenSource? cancellationTokenSource; + #region Inputs [Output] [Required] - public ITaskItem OutputFile { get; set; } + public ITaskItem? OutputFile { get; set; } public bool Recursive { get; set; } [Required] - public ITaskItem [] Sources { get; set; } + public ITaskItem [] Sources { get; set; } = Array.Empty (); public bool Symlinks { get; set; } [Required] - public ITaskItem WorkingDirectory { get; set; } + public ITaskItem? WorkingDirectory { get; set; } - #endregion + public string ZipPath { get; set; } = string.Empty; - protected override string ToolName { - get { return "zip"; } - } + #endregion - protected override string GenerateFullPathToTool () + static string GetExecutable (List arguments, string toolName, string toolPathOverride) { - if (!string.IsNullOrEmpty (ToolPath)) - return Path.Combine (ToolPath, ToolExe); - - var path = Path.Combine ("/usr/bin", ToolExe); - - return File.Exists (path) ? path : ToolExe; + if (string.IsNullOrEmpty (toolPathOverride)) { + arguments.Insert (0, toolName); + return "xcrun"; + } + return toolPathOverride; } - protected override string GetWorkingDirectory () + string GetWorkingDirectory () { - return WorkingDirectory.GetMetadata ("FullPath"); + return WorkingDirectory!.GetMetadata ("FullPath"); } - protected override string GenerateCommandLineCommands () + List GenerateCommandLineCommands () { - var args = new CommandLineArgumentBuilder (); + var args = new List (); if (Recursive) args.Add ("-r"); @@ -61,21 +61,15 @@ protected override string GenerateCommandLineCommands () if (Symlinks) args.Add ("-y"); - args.AddQuoted (OutputFile.GetMetadata ("FullPath")); + args.Add (OutputFile!.GetMetadata ("FullPath")); - var root = WorkingDirectory.GetMetadata ("FullPath"); + var root = GetWorkingDirectory (); for (int i = 0; i < Sources.Length; i++) { var relative = PathUtils.AbsoluteToRelative (root, Sources [i].GetMetadata ("FullPath")); - args.AddQuoted (relative); + args.Add (relative); } - return args.ToString (); - } - - protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) - { - // TODO: do proper parsing of error messages and such - Log.LogMessage (messageImportance, "{0}", singleLine); + return args; } public override bool Execute () @@ -86,20 +80,25 @@ public override bool Execute () // Copy the zipped file back to Windows. if (rv) - taskRunner.GetFileAsync (this, OutputFile.ItemSpec).Wait (); + taskRunner.GetFileAsync (this, OutputFile!.ItemSpec).Wait (); return rv; } - return base.Execute (); + var args = GenerateCommandLineCommands (); + var executable = GetExecutable (args, "zip", ZipPath); + cancellationTokenSource = new CancellationTokenSource (); + ExecuteAsync (Log, executable, args, workingDirectory: GetWorkingDirectory (), cancellationToken: cancellationTokenSource.Token).Wait (); + return !Log.HasLoggedErrors; } - public override void Cancel () + public void Cancel () { - if (ShouldExecuteRemotely ()) + if (ShouldExecuteRemotely ()) { BuildConnection.CancelAsync (BuildEngine4).Wait (); - - base.Cancel (); + } else { + cancellationTokenSource?.Cancel (); + } } public bool ShouldCopyToBuildServer (ITaskItem item) => false; diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets index 21f7e6ff0ccd..0859ac813c67 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.ObjCBinding.targets @@ -117,8 +117,7 @@ Copyright (C) 2020 Microsoft. All rights reserved. - + @@ -109,7 +109,7 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved. - + @@ -166,7 +166,7 @@ Copyright (C) 2011-2013 Xamarin. All rights reserved. - + diff --git a/tests/common/shared-dotnet.csproj b/tests/common/shared-dotnet.csproj index f84dd0fb3c12..3758e3927ca0 100644 --- a/tests/common/shared-dotnet.csproj +++ b/tests/common/shared-dotnet.csproj @@ -117,8 +117,7 @@