Improved the Rust compilation by showing the live output

This commit is contained in:
Thorsten Sommer 2025-04-14 15:25:27 +02:00
parent 70610f6e20
commit ca07b0734e
No known key found for this signature in database
GPG Key ID: B0B7E2FC074BF1F5

View File

@ -5,6 +5,7 @@ using Build.Tools;
namespace Build.Commands; namespace Build.Commands;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedType.Global // ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
@ -166,10 +167,10 @@ public sealed partial class UpdateMetadataCommands
// //
Console.WriteLine("=============================="); Console.WriteLine("==============================");
Console.Write("- Start building the Rust runtime ..."); Console.WriteLine("- Start building the Rust runtime ...");
var pathRuntime = Environment.GetRustRuntimeDirectory(); var pathRuntime = Environment.GetRustRuntimeDirectory();
var rustBuildOutput = await this.ReadCommandOutput(pathRuntime, "cargo", "tauri build --bundles none"); var rustBuildOutput = await this.ReadCommandOutput(pathRuntime, "cargo", "tauri build --bundles none", true);
var rustBuildOutputLines = rustBuildOutput.Split([global::System.Environment.NewLine], StringSplitOptions.RemoveEmptyEntries); var rustBuildOutputLines = rustBuildOutput.Split([global::System.Environment.NewLine], StringSplitOptions.RemoveEmptyEntries);
var foundRustIssue = false; var foundRustIssue = false;
foreach (var buildOutputLine in rustBuildOutputLines) foreach (var buildOutputLine in rustBuildOutputLines)
@ -192,7 +193,8 @@ public sealed partial class UpdateMetadataCommands
Console.WriteLine(); Console.WriteLine();
else else
{ {
Console.WriteLine(" completed successfully."); Console.WriteLine();
Console.WriteLine("- Compilation completed successfully.");
Console.WriteLine(); Console.WriteLine();
} }
} }
@ -457,7 +459,7 @@ public sealed partial class UpdateMetadataCommands
return matches; return matches;
} }
private async Task<string> ReadCommandOutput(string workingDirectory, string program, string command) private async Task<string> ReadCommandOutput(string workingDirectory, string program, string command, bool showLiveOutput = false)
{ {
var processInfo = new ProcessStartInfo var processInfo = new ProcessStartInfo
{ {
@ -467,21 +469,38 @@ public sealed partial class UpdateMetadataCommands
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = true,
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true,
}; };
var sb = new StringBuilder();
using var process = new Process(); using var process = new Process();
process.StartInfo = processInfo; process.StartInfo = processInfo;
process.Start(); process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.OutputDataReceived += (_, args) =>
{
if(!string.IsNullOrWhiteSpace(args.Data))
{
if(showLiveOutput)
Console.WriteLine(args.Data);
sb.AppendLine(args.Data);
}
};
process.ErrorDataReceived += (_, args) =>
{
if(!string.IsNullOrWhiteSpace(args.Data))
{
if(showLiveOutput)
Console.WriteLine(args.Data);
sb.AppendLine(args.Data);
}
};
var output = await process.StandardOutput.ReadToEndAsync();
var error = await process.StandardError.ReadToEndAsync();
await process.WaitForExitAsync(); await process.WaitForExitAsync();
return sb.ToString();
return $"""
{output}
{error}
""";
} }
private async Task<int> IncreaseBuildNumber() private async Task<int> IncreaseBuildNumber()