forked from xamarin/xamarin-macios
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable nullability and fix code accordingly. * Augment it to be able to take multiple files to strip at the same time. * Strip in parallel. * Execute using xcrun (ref: xamarin#3931) * Pass the full path to the executable file to strip, to make command lines easier to copy-paste. * Remove test that is now outdated. We have other tests that run strip anyways, so this shouldn't be a problem.
- Loading branch information
1 parent
0897150
commit 72bbc02
Showing
5 changed files
with
46 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 34 additions & 31 deletions
65
msbuild/Xamarin.MacDev.Tasks.Core/Tasks/SymbolStripTaskBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,67 @@ | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
using Parallel = System.Threading.Tasks.Parallel; | ||
using ParallelOptions = System.Threading.Tasks.ParallelOptions; | ||
|
||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
|
||
#nullable enable | ||
|
||
namespace Xamarin.MacDev.Tasks | ||
{ | ||
public abstract class SymbolStripTaskBase : XamarinToolTask | ||
public abstract class SymbolStripTaskBase : XamarinTask | ||
{ | ||
#region Inputs | ||
|
||
[Required] | ||
public string Executable { get; set; } | ||
public ITaskItem[] Executable { get; set; } = Array.Empty<ITaskItem> (); | ||
|
||
public string SymbolFile { get; set; } | ||
// This can also be specified as metadata on the Executable item (as 'SymbolFile') | ||
public string SymbolFile { get; set; } = string.Empty; | ||
|
||
[Required] | ||
// This can also be specified as metadata on the Executable item (as 'IsFramework') | ||
public bool IsFramework { get; set; } | ||
|
||
#endregion | ||
|
||
protected override string ToolName { | ||
get { return "strip"; } | ||
} | ||
|
||
protected override string GenerateFullPathToTool () | ||
bool GetIsFramework (ITaskItem item) | ||
{ | ||
if (!string.IsNullOrEmpty (ToolPath)) | ||
return Path.Combine (ToolPath, ToolExe); | ||
|
||
var path = Path.Combine (AppleSdkSettings.DeveloperRoot, "Toolchains", "XcodeDefault.xctoolchain", "usr", "bin", ToolExe); | ||
|
||
return File.Exists (path) ? path : ToolExe; | ||
var value = GetNonEmptyStringOrFallback (item, "IsFramework", IsFramework ? "true" : "false", required: true); | ||
return string.Equals (value, "true", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
protected override string GenerateCommandLineCommands () | ||
void ExecuteStrip (ITaskItem item) | ||
{ | ||
var args = new CommandLineBuilder (); | ||
var args = new List<string> (); | ||
|
||
if (!string.IsNullOrEmpty (SymbolFile)) { | ||
args.AppendSwitch ("-i"); | ||
args.AppendSwitch ("-s"); | ||
args.AppendFileNameIfNotNull (SymbolFile); | ||
args.Add ("strip"); | ||
|
||
var symbolFile = GetNonEmptyStringOrFallback (item, "SymbolFile", SymbolFile); | ||
if (!string.IsNullOrEmpty (symbolFile)) { | ||
args.Add ("-i"); | ||
args.Add ("-s"); | ||
args.Add (symbolFile); | ||
} | ||
|
||
if (IsFramework) { | ||
if (GetIsFramework (item)) { | ||
// Only remove debug symbols from frameworks. | ||
args.AppendSwitch ("-S"); | ||
args.AppendSwitch ("-x"); | ||
args.Add ("-S"); | ||
args.Add ("-x"); | ||
} | ||
|
||
args.AppendFileNameIfNotNull (Executable); | ||
args.Add (Path.GetFullPath (item.ItemSpec)); | ||
|
||
return args.ToString (); | ||
ExecuteAsync ("xcrun", args).Wait (); | ||
} | ||
|
||
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) | ||
public override bool Execute () | ||
{ | ||
// TODO: do proper parsing of error messages and such | ||
Log.LogMessage (messageImportance, "{0}", singleLine); | ||
Parallel.ForEach (Executable, new ParallelOptions { MaxDegreeOfParallelism = Math.Max (Environment.ProcessorCount / 2, 1) }, (item) => { | ||
ExecuteStrip (item); | ||
}); | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/SymbolStripTaskTests.cs
This file was deleted.
Oops, something went wrong.