Skip to content

Commit

Permalink
Merge pull request #550 from WildernessLabs/mshapiro/trim_hang_fix
Browse files Browse the repository at this point in the history
Fix trim hanging and incorrect status results.
  • Loading branch information
adrianstevens authored Apr 11, 2024
2 parents 74d3f14 + c84f127 commit 5d6749d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Source/v2/Meadow.Linker/Linker/ILLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace Meadow.Linker
Expand Down Expand Up @@ -56,30 +57,27 @@ public async Task RunILLink(

using (var process = new Process())
{
var output = new StringBuilder();

process.StartInfo.WorkingDirectory = Directory.GetDirectoryRoot(illinkerDllPath);
process.StartInfo.FileName = "dotnet";
process.StartInfo.Arguments = monolinker_args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (sender, args) => output.AppendLine(args.Data);
process.ErrorDataReceived += (sender, args) => output.AppendLine(args.Data);
process.Start();

// To avoid deadlocks, read the output stream first and then wait
string stdOutReaderResult;
using (StreamReader stdOutReader = process.StandardOutput)
{
stdOutReaderResult = await stdOutReader.ReadToEndAsync();

_logger?.Log(LogLevel.Debug, "StandardOutput Contains: " + stdOutReaderResult);
}
process.BeginErrorReadLine();
process.BeginOutputReadLine();

await Task.Run(() => process.WaitForExit());

if (process.ExitCode != 0)
{
_logger?.Log(LogLevel.Debug, $"Trimming failed - ILLinker execution error!\nProcess Info: {process.StartInfo.FileName} {process.StartInfo.Arguments} \nExit Code: {process.ExitCode}");
throw new Exception("Trimming failed");
throw new Exception($"Trimming failed{Environment.NewLine}{output}");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/v2/Meadow.Linker/Linker/MeadowLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private async Task<IEnumerable<string>> TrimMeadowApp(
catch (Exception ex)
{
_logger?.LogError(ex, "Error trimming Meadow app");
throw;
}

return Directory.EnumerateFiles(postlink_dir);
Expand Down

0 comments on commit 5d6749d

Please sign in to comment.