Files
secretsplash/Editor/ToolchainChecker.cs
Jan Racek 4aa4e49424 psst
2026-03-24 13:00:54 +01:00

85 lines
2.6 KiB
C#

using UnityEngine;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System;
/// <summary>
/// Utility that detects whether required build tools (MIPS cross-compiler,
/// GNU Make, GDB, etc.) are available on the host system by probing the
/// PATH via <c>where</c> (Windows) or <c>which</c> (Unix).
/// </summary>
namespace SplashEdit.EditorCode
{
public static class ToolchainChecker
{
private static readonly string[] mipsToolSuffixes = new[]
{
"addr2line", "ar", "as", "cpp", "elfedit", "g++", "gcc", "gcc-ar", "gcc-nm",
"gcc-ranlib", "gcov", "ld", "nm", "objcopy", "objdump", "ranlib", "readelf",
"size", "strings", "strip"
};
/// <summary>
/// Returns the full tool names to be checked, based on platform.
/// </summary>
public static string[] GetRequiredTools()
{
string prefix = Application.platform == RuntimePlatform.WindowsEditor
? "mipsel-none-elf-"
: "mipsel-linux-gnu-";
return mipsToolSuffixes.Select(s => prefix + s).ToArray();
}
/// <summary>
/// Checks for availability of any tool (either full name like "make" or "mipsel-*").
/// </summary>
public static bool IsToolAvailable(string toolName)
{
string command = Application.platform == RuntimePlatform.WindowsEditor ? "where" : "which";
try
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = toolName,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit();
if (!string.IsNullOrEmpty(output))
return true;
// Additional fallback for MIPS tools on Windows in local MIPS path
if (Application.platform == RuntimePlatform.WindowsEditor &&
toolName.StartsWith("mipsel-none-elf-"))
{
string localMipsBin = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"mips", "mips", "bin");
string fullPath = Path.Combine(localMipsBin, toolName + ".exe");
return File.Exists(fullPath);
}
return false;
}
catch
{
return false;
}
}
}
}