From 616d6544adbfa651e7817132ef0eaa38f8906fca Mon Sep 17 00:00:00 2001 From: Emanuel Fernandez Dell'Oca Date: Fri, 23 Aug 2019 12:38:08 -0300 Subject: [PATCH] [msbuild] Improve altool task by logging execution errors (#6815) * [msbuild] Improve altool task by logging execution errors The altool task was just logging the XML output produced by the tool execution but was not logging any build error neither failing in that case. * [msbuild] Log the altool output when failing to parse it --- .../Tasks/AlToolTaskBase.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) 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