diff --git a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/AlToolTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/AlToolTaskBase.cs index d9776eb28166..f4eb6dce6b1f 100644 --- a/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/AlToolTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks.Core/Tasks/AlToolTaskBase.cs @@ -3,12 +3,14 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; +using System.Text; namespace Xamarin.MacDev.Tasks { public abstract class ALToolTaskBase : ToolTask { string sdkDevPath; + StringBuilder toolOutput; public string SessionId { get; set; } @@ -40,6 +42,17 @@ string DevicePlatformBinDir { get { return Path.Combine (SdkDevPath, "usr", "bin"); } } + public override bool Execute () + { + toolOutput = new StringBuilder (); + + base.Execute (); + + LogErrorsFromOutput (toolOutput.ToString ()); + + return !HasLoggedErrors; + } + protected override string GenerateFullPathToTool () { if (!string.IsNullOrEmpty (ToolPath)) @@ -70,6 +83,7 @@ protected override string GenerateCommandLineCommands () protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) { + toolOutput.Append (singleLine); Log.LogMessage (messageImportance, "{0}", singleLine); } @@ -82,5 +96,28 @@ string GetFileTypeValue () default: throw new NotSupportedException ($"Provided file type '{FileType}' is not supported by altool"); } } + + void LogErrorsFromOutput (string output) + { + try { + if (string.IsNullOrEmpty (output)) + return; + + var plist = PObject.FromString (output) as PDictionary; + var errors = PObject.Create (PObjectType.Array) as PArray; + var message = PObject.Create (PObjectType.String) as PString; + + if ((plist?.TryGetValue ("product-errors", out errors) == true)) { + foreach (var error in errors) { + var dict = error as PDictionary; + if (dict?.TryGetValue ("message", out message) == true) { + Log.LogError (ToolName, null, null, null, 0, 0, 0, 0, "{0}", message.Value); + } + } + } + } catch (Exception ex) { + Log.LogWarning ($"Failed to parse altool output: {ex.Message}. \nOutput: {output}"); + } + } } } \ No newline at end of file