Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -89,6 +90,8 @@ bool ManifestIsUpToDate (string manifestFile)

bool RunAapt (string commandLine)
{
var stdout_completed = new ManualResetEvent (false);
var stderr_completed = new ManualResetEvent (false);
var psi = new ProcessStartInfo () {
FileName = GenerateFullPathToTool (),
Arguments = commandLine,
Expand All @@ -99,26 +102,37 @@ bool RunAapt (string commandLine)
WindowStyle = ProcessWindowStyle.Hidden,
};

var proc = new Process ();
proc.OutputDataReceived += (sender, e) => {
LogEventsFromTextOutput (e.Data, MessageImportance.Normal);
};
proc.ErrorDataReceived += (sender, e) => {
LogEventsFromTextOutput (e.Data, MessageImportance.Normal);
};
proc.StartInfo = psi;
proc.Start ();
proc.BeginOutputReadLine ();
proc.BeginErrorReadLine ();
Token.Register (() => {
try {
proc.Kill ();
} catch (Exception) {
}
});
LogDebugMessage ("Executing {0}", commandLine);
proc.WaitForExit ();
return proc.ExitCode == 0;
using (var proc = new Process ()) {
proc.OutputDataReceived += (sender, e) => {
if (e.Data != null)
LogEventsFromTextOutput (e.Data, MessageImportance.Normal);
else
stdout_completed.Set ();
};
proc.ErrorDataReceived += (sender, e) => {
if (e.Data != null)
LogEventsFromTextOutput (e.Data, MessageImportance.Normal);
else
stderr_completed.Set ();
};
proc.StartInfo = psi;
proc.Start ();
proc.BeginOutputReadLine ();
proc.BeginErrorReadLine ();
Token.Register (() => {
try {
proc.Kill ();
} catch (Exception) {
}
});
LogDebugMessage ("Executing {0}", commandLine);
proc.WaitForExit ();
if (psi.RedirectStandardError)
stderr_completed.WaitOne (TimeSpan.FromSeconds (30));
if (psi.RedirectStandardOutput)
stdout_completed.WaitOne (TimeSpan.FromSeconds (30));
return proc.ExitCode == 0;
}
}

bool ExecuteForAbi (string cmd, string currentResourceOutputFile)
Expand Down
38 changes: 28 additions & 10 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ IEnumerable<Config> GetAotConfigs ()

bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOptions, string assembly, CancellationToken token)
{
var stdout_completed = new ManualResetEvent (false);
var stderr_completed = new ManualResetEvent (false);
var psi = new ProcessStartInfo () {
FileName = aotCompiler,
Arguments = aotOptions + " \"" + assembly + "\"",
Expand All @@ -453,16 +455,32 @@ bool RunAotCompiler (string assembliesPath, string aotCompiler, string aotOption
LogDebugMessage ("[AOT] MONO_PATH=\"{0}\" MONO_ENV_OPTIONS=\"{1}\" {2} {3}",
psi.EnvironmentVariables ["MONO_PATH"], psi.EnvironmentVariables ["MONO_ENV_OPTIONS"], psi.FileName, psi.Arguments);

var proc = new Process ();
proc.OutputDataReceived += OnAotOutputData;
proc.ErrorDataReceived += OnAotErrorData;
proc.StartInfo = psi;
proc.Start ();
proc.BeginOutputReadLine ();
proc.BeginErrorReadLine ();
token.Register (() => { try { proc.Kill (); } catch (Exception) {} });
proc.WaitForExit ();
return proc.ExitCode == 0;
using (var proc = new Process ()) {
proc.OutputDataReceived += (s, e) => {
if (e.Data != null)
OnAotOutputData (s, e);
else
stdout_completed.Set ();
};
proc.ErrorDataReceived += (s, e) => {
if (e.Data != null)
OnAotErrorData (s, e);
else
stderr_completed.Set ();
};
proc.StartInfo = psi;
proc.Start ();
proc.BeginOutputReadLine ();
proc.BeginErrorReadLine ();
token.Register (() => { try { proc.Kill (); } catch (Exception) { } });
proc.WaitForExit ();
if (psi.RedirectStandardError)
stderr_completed.WaitOne (TimeSpan.FromSeconds (30));
if (psi.RedirectStandardOutput)
stdout_completed.WaitOne (TimeSpan.FromSeconds (30));
return proc.ExitCode == 0;
}
GC.Collect ();
}

void OnAotOutputData (object sender, DataReceivedEventArgs e)
Expand Down
Loading