Skip to content

Commit

Permalink
[msbuild] Improve altool task by logging execution errors (#6815)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
emaf authored and rolfbjarne committed Aug 23, 2019
1 parent d859cea commit 616d654
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks.Core/Tasks/AlToolTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -70,6 +83,7 @@ protected override string GenerateCommandLineCommands ()

protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
toolOutput.Append (singleLine);
Log.LogMessage (messageImportance, "{0}", singleLine);
}

Expand All @@ -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}");
}
}
}
}

1 comment on commit 616d654

@xamarin-release-manager
Copy link
Collaborator

Choose a reason for hiding this comment

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

Build was (probably) aborted

🔥 Jenkins job (on internal Jenkins) failed in stage(s) 'Build' 🔥 : hudson.AbortException: script returned exit code 2

🔥 Build failed 🔥

Please sign in to comment.