Skip to content

Commit

Permalink
[msbuild] Improve the DSymUtil task. (#14344)
Browse files Browse the repository at this point in the history
* Enable nullability and fix code accordingly.
* Augment it to be able to take multiple files to run dsymutil on at the same time.
* Execute using xcrun (ref: #3931)
* Pass the full path to the executable file to dsymutil, to make command lines
  easier to copy-paste.
  • Loading branch information
rolfbjarne authored Mar 11, 2022
1 parent 84b1a87 commit 56829a2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 54 deletions.
70 changes: 31 additions & 39 deletions msbuild/Xamarin.MacDev.Tasks.Core/Tasks/DSymUtilTaskBase.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

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

#nullable enable

namespace Xamarin.MacDev.Tasks
{
public abstract class DSymUtilTaskBase : XamarinToolTask
public abstract class DSymUtilTaskBase : XamarinTask
{
#region Inputs

[Required]
public string DSymDir { get; set; }
// This can also be specified as metadata on the Executable item (as 'DSymDir')
public string DSymDir { get; set; } = string.Empty;

[Output]
[Required]
public ITaskItem Executable { get; set; }
public ITaskItem [] Executable { get; set; } = Array.Empty<ITaskItem> ();

#endregion

#region Outputs

// This property is required for XVS to work properly, even though it's not used for anything in the targets.
[Output]
public ITaskItem[] DsymContentFiles { get; set; }
public ITaskItem[] DsymContentFiles { get; set; } = Array.Empty<ITaskItem> ();

#endregion

protected override string ToolName {
get { return "dsymutil"; }
}

public override bool Execute ()
{
var result = base.Execute ();
var contentFiles = new List<ITaskItem> ();

var contentsDir = Path.Combine (DSymDir, "Contents");
if (Directory.Exists(contentsDir))
DsymContentFiles = Directory.EnumerateFiles (contentsDir).Select (x => new TaskItem (x)).ToArray ();
// We're not executing multiple dsymutil processes in parallel, because
// we're asking dsymutil to do parallel processing (we're passing '-num-threads 4' to dsymutil)
foreach (var item in Executable) {
ExecuteDSymUtil (item, contentFiles);
}

return result;
}
DsymContentFiles = contentFiles.ToArray ();

protected override string GenerateFullPathToTool ()
{
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;
return !Log.HasLoggedErrors;
}

protected override string GenerateCommandLineCommands ()
void ExecuteDSymUtil (ITaskItem item, List<ITaskItem> contentFiles)
{
var args = new CommandLineBuilder ();
var dSymDir = GetNonEmptyStringOrFallback (item, "DSymDir", DSymDir, required: true);

args.AppendSwitch ("-num-threads");
args.AppendSwitch ("4");
args.AppendSwitch ("-z");
args.AppendSwitch ("-o");
args.AppendFileNameIfNotNull (DSymDir);
args.AppendFileNameIfNotNull (Executable.ItemSpec);
var args = new List<string> ();

return args.ToString ();
}
args.Add ("dsymutil");
args.Add ("-num-threads");
args.Add ("4");
args.Add ("-z");
args.Add ("-o");
args.Add (dSymDir);

protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
if (singleLine.StartsWith ("warning:", StringComparison.Ordinal) && !singleLine.Contains ("unable to open object file: No such file or directory"))
Log.LogWarning (singleLine);
else
Log.LogMessage (messageImportance, singleLine);
args.Add (Path.GetFullPath (item.ItemSpec));
ExecuteAsync ("xcrun", args).Wait ();

var contentsDir = Path.Combine (dSymDir, "Contents");
if (Directory.Exists (contentsDir))
contentFiles.AddRange (Directory.EnumerateFiles (contentsDir).Select (x => new TaskItem (x)).ToArray ());
}
}
}
14 changes: 5 additions & 9 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/DSymUtil.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Build.Framework;
using Xamarin.Messaging.Build.Client;

#nullable enable

namespace Xamarin.MacDev.Tasks
{
public class DSymUtil : DSymUtilTaskBase, ITaskCallback
Expand All @@ -15,17 +19,9 @@ public override bool Execute ()
return base.Execute ();
}

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

if (ShouldExecuteRemotely ())
BuildConnection.CancelAsync (SessionId, BuildEngine4).Wait ();
}

public bool ShouldCopyToBuildServer (ITaskItem item) => false;

public bool ShouldCreateOutputFile (ITaskItem item) => item == Executable;
public bool ShouldCreateOutputFile (ITaskItem item) => Executable.Contains (item);

public IEnumerable<ITaskItem> GetAdditionalItemsToBeCopied () => Enumerable.Empty<ITaskItem> ();
}
Expand Down
7 changes: 1 addition & 6 deletions msbuild/Xamarin.Shared/Xamarin.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2307,8 +2307,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Condition="'$(IsMacEnabled)' == 'true' And '%(_AppExtensionDebugSymbolProperties.NoDSymUtil)' == 'false'"
DSymDir="$(AppBundleDir)\..\%(_AppExtensionDebugSymbolProperties.Identity).dSYM"
Executable="$(_AppExtensionRoot)PlugIns\%(_AppExtensionDebugSymbolProperties.Identity)\%(_AppExtensionDebugSymbolProperties.NativeExecutable)"
ToolExe="$(DSymUtilExe)"
ToolPath="$(DSymUtilPath)"
>
</DSymUtil>

Expand Down Expand Up @@ -2377,8 +2375,7 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Condition="'$(NoDSymUtil)' == 'false' and '%(_Frameworks._DestinationExists)' != 'true' "
DSymDir="%(_Frameworks._Destination)"
Executable="%(_Frameworks.Identity)"
ToolExe="$(DSymUtilExe)"
ToolPath="$(DSymUtilPath)">
>
</DSymUtil>

<!-- strip embedded frameworks -->
Expand Down Expand Up @@ -2453,8 +2450,6 @@ Copyright (C) 2018 Microsoft. All rights reserved.
Condition="'$(IsMacEnabled)' == 'true' And '$(NoDSymUtil)' == 'false' And '$(IsAppExtension)' == 'false'"
DSymDir="$(AppBundleDir).dSYM"
Executable="$(_NativeExecutable)"
ToolExe="$(DSymUtilExe)"
ToolPath="$(DSymUtilPath)"
>
</DSymUtil>

Expand Down

1 comment on commit 56829a2

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

10 tests failed, 224 tests passed.

Failed tests

  • [NUnit] Mono Mac OS X BCL tests group 1/Mac Full/Debug: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • [NUnit] Mono Mac OS X BCL tests group 2/Mac Full/Debug: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • [NUnit] Mono Mac OS X BCL tests group 3/Mac Full/Debug: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • Xtro/Legacy Xamarin: TimedOut
  • Xtro/.NET: TimedOut
  • mmptest/macOS/Debug: Failed (Execution failed with exit code 160)
  • MSBuild tests/Integration: Failed (Execution failed with exit code 19)
  • MTouch tests/NUnit: Failed (Execution failed with exit code 5)
  • Cecil-based tests/NUnit: Failed (Execution failed with exit code 24)
  • Generator tests/.NET: Failed (Execution failed with exit code 1)

Pipeline on Agent XAMMINI-053.Monterey'
[msbuild] Improve the DSymUtil task. (#14344)

Please sign in to comment.