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] Port the OptimizePropertyLists task to subclass XamarinTask. #21615

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions docs/build-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ The full path to the Metal compiler.

The default behavior is to use `xcrun metal`.

## PlutilPath

The full path to the `plutil` command-line tool.

The default behavior is to use `xcrun plutil`.

## StripPath

The full path to the `strip` command-line tool.
Expand Down
70 changes: 34 additions & 36 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/OptimizePropertyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,65 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

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

using Xamarin.Messaging.Build.Client;

// Disable until we get around to enable + fix any issues.
#nullable disable
#nullable enable

namespace Xamarin.MacDev.Tasks {
public class OptimizePropertyList : XamarinToolTask, ITaskCallback {
public class OptimizePropertyList : XamarinTask, ICancelableTask {
CancellationTokenSource? cancellationTokenSource;
#region Inputs

[Required]
public ITaskItem Input { get; set; }
public ITaskItem? Input { get; set; }

[Required]
[Output]
public ITaskItem Output { get; set; }
public ITaskItem? Output { get; set; }

#endregion
public string PlutilPath { get; set; } = string.Empty;

protected override string ToolName {
get { return "plutil"; }
}
#endregion

protected override string GenerateFullPathToTool ()
static string GetExecutable (List<string> arguments, string toolName, string toolPathOverride)
{
if (!string.IsNullOrEmpty (ToolPath))
return Path.Combine (ToolPath, ToolExe);

const string path = "/usr/bin/plutil";

return File.Exists (path) ? path : ToolExe;
if (string.IsNullOrEmpty (toolPathOverride)) {
arguments.Insert (0, toolName);
return "xcrun";
}
return toolPathOverride;
}

protected override string GenerateCommandLineCommands ()
List<string> GenerateCommandLineCommands ()
{
var args = new CommandLineBuilder ();
var args = new List<string> ();

args.AppendSwitch ("-convert");
args.AppendSwitch ("binary1");
args.AppendSwitch ("-o");
args.AppendFileNameIfNotNull (Output.ItemSpec);
args.AppendFileNameIfNotNull (Input.ItemSpec);
args.Add ("-convert");
args.Add ("binary1");
args.Add ("-o");
args.Add (Output!.ItemSpec);
args.Add (Input!.ItemSpec);

return args.ToString ();
}

protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
Log.LogMessage (messageImportance, "{0}", singleLine);
return args;
}

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

Directory.CreateDirectory (Path.GetDirectoryName (Output.ItemSpec));

return base.Execute ();
Directory.CreateDirectory (Path.GetDirectoryName (Output!.ItemSpec));
var args = GenerateCommandLineCommands ();
var executable = GetExecutable (args, "plutil", PlutilPath);
cancellationTokenSource = new CancellationTokenSource ();
ExecuteAsync (Log, executable, args, cancellationToken: cancellationTokenSource.Token).Wait ();
return !Log.HasLoggedErrors;
}

public bool ShouldCopyToBuildServer (Microsoft.Build.Framework.ITaskItem item) => false;
Expand All @@ -72,12 +69,13 @@ public override bool Execute ()

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => Enumerable.Empty<ITaskItem> ();

public override void Cancel ()
public void Cancel ()
{
base.Cancel ();

if (!string.IsNullOrEmpty (SessionId))
if (!string.IsNullOrEmpty (SessionId)) {
BuildConnection.CancelAsync (BuildEngine4).Wait ();
} else {
cancellationTokenSource?.Cancel ();
}
}
}
}
6 changes: 2 additions & 4 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<OptimizePropertyList
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
ToolExe="$(PlUtilExe)"
ToolPath="$(PlUtilPath)"
PlutilPath="$(PlutilPath)"
Input="%(_PropertyList.Identity)"
Output="$(DeviceSpecificIntermediateOutputPath)optimized\%(_PropertyList.LogicalName)">
</OptimizePropertyList>
Expand Down Expand Up @@ -1666,8 +1665,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<OptimizePropertyList
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
ToolExe="$(PlUtilExe)"
ToolPath="$(PlUtilPath)"
PlutilPath="$(PlutilPath)"
Input="%(_LocalizationFile.Identity)"
Output="$(DeviceSpecificIntermediateOutputPath)optimized\%(_LocalizationFile.LogicalName)">
</OptimizePropertyList>
Expand Down