From 70b61c1b184ac312cc13f303d605b433434b5cf6 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 5 Nov 2024 16:04:38 +0100 Subject: [PATCH] [msbuild] Make it possible to override the path to the 'strip' tool. (#21581) --- docs/build-apps/build-properties.md | 6 ++++++ .../Xamarin.MacDev.Tasks/Tasks/SymbolStrip.cs | 16 +++++++++++++--- msbuild/Xamarin.Shared/Xamarin.Shared.targets | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/build-apps/build-properties.md b/docs/build-apps/build-properties.md index 2f0a9f8358f4..b405f6b4833b 100644 --- a/docs/build-apps/build-properties.md +++ b/docs/build-apps/build-properties.md @@ -88,3 +88,9 @@ The default behavior is to use `xcrun metallib`. The full path to the Metal compiler. The default behavior is to use `xcrun metal`. + +## StripPath + +The full path to the `strip` command-line tool. + +The default behavior is to use `xcrun strip`. diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/SymbolStrip.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/SymbolStrip.cs index d61a4d296d92..e994659270ab 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/SymbolStrip.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/SymbolStrip.cs @@ -18,6 +18,8 @@ public class SymbolStrip : XamarinParallelTask, ITaskCallback { [Required] public ITaskItem [] Executable { get; set; } = Array.Empty (); + public string StripPath { get; set; } = string.Empty; + // This can also be specified as metadata on the Executable item (as 'SymbolFile') public string SymbolFile { get; set; } = string.Empty; @@ -31,11 +33,19 @@ bool GetIsFramework (ITaskItem item) return string.Equals (value, "Framework", StringComparison.OrdinalIgnoreCase); } + static string GetExecutable (List arguments, string toolName, string toolPathOverride) + { + if (string.IsNullOrEmpty (toolPathOverride)) { + arguments.Insert (0, toolName); + return "xcrun"; + } + return toolPathOverride; + } + void ExecuteStrip (ITaskItem item) { var args = new List (); - - args.Add ("strip"); + var executable = GetExecutable (args, "strip", StripPath); var symbolFile = GetNonEmptyStringOrFallback (item, "SymbolFile", SymbolFile); if (!string.IsNullOrEmpty (symbolFile)) { @@ -52,7 +62,7 @@ void ExecuteStrip (ITaskItem item) args.Add (Path.GetFullPath (item.ItemSpec)); - ExecuteAsync ("xcrun", args).Wait (); + ExecuteAsync (executable, args).Wait (); } public override bool Execute () diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index 957b0314b859..25fc2af375c8 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -2926,6 +2926,7 @@ Copyright (C) 2018 Microsoft. All rights reserved. Executable="$(_AppContainerDir)%(_NativeStripItems.Identity)" Kind="%(_NativeStripItems.Kind)" MaxDegreeOfParallelism="$(SymbolStripMaxDegreeOfParallelism)" + StripPath="$(StripPath)" SymbolFile="%(_NativeStripItems.SymbolFile)" />