Skip to content

Commit

Permalink
Fix the rakaly CLI binary not being made executable if its path conta…
Browse files Browse the repository at this point in the history
…ins a space (#1694) #patch
  • Loading branch information
IhateTrains authored Jan 10, 2024
1 parent d2bbe91 commit 333abeb
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions ImperatorToCK3/Helpers/RakalyCaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using commonItems;
using ImperatorToCK3.Exceptions;
using System;
using System.Diagnostics;
using System.IO;
Expand All @@ -8,17 +7,21 @@ namespace ImperatorToCK3.Helpers;

public static class RakalyCaller {
private const string RakalyVersion = "0.4.22";
private static readonly string RakalyExecutablePath;
private static readonly string RelativeRakalyPath;

static RakalyCaller() {
string currentDir = Directory.GetCurrentDirectory();
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-pc-windows-msvc/rakaly.exe";
RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-pc-windows-msvc/rakaly.exe";
if (OperatingSystem.IsMacOS()) {
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-apple-darwin/rakaly";
Exec($"chmod +x {currentDir}/{RakalyExecutablePath}");
RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-apple-darwin/rakaly";
} else if (OperatingSystem.IsLinux()) {
RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-unknown-linux-musl/rakaly";
Exec($"chmod +x {currentDir}/{RakalyExecutablePath}");
RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-unknown-linux-musl/rakaly";
}

if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
// Make sure the file is executable.
var rakalyPath = Path.Combine(currentDir, RelativeRakalyPath).AddQuotes();
Exec($"chmod +x {rakalyPath}");
}
}

Expand All @@ -28,7 +31,7 @@ public static string GetJson(string filePath) {

using Process process = new();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = RakalyExecutablePath;
process.StartInfo.FileName = RelativeRakalyPath;
process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
Expand All @@ -48,7 +51,7 @@ public static void MeltSave(string savePath) {

using Process process = new();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = RakalyExecutablePath;
process.StartInfo.FileName = RelativeRakalyPath;
process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
Expand Down Expand Up @@ -88,5 +91,10 @@ private static void Exec(string cmd) {

process.Start();
process.WaitForExit();

var stdOut = process.StandardOutput.ReadToEnd().Trim();
if (!string.IsNullOrEmpty(stdOut)) {
Logger.Debug("Exec output: " + stdOut);
}
}
}

0 comments on commit 333abeb

Please sign in to comment.