Use hard links for macOS app bundles

Avoid needing to get executable path from MainModule, which broke the game when run with the dotnet command instead of the bin's apphost. Fixes tests.
This commit is contained in:
PJB3005
2025-12-31 18:46:46 +01:00
parent c25f6c5e98
commit dd41a7ce44
2 changed files with 17 additions and 18 deletions

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Robust.Shared.Utility;
namespace Robust.Shared.ContentPack
@@ -17,20 +15,9 @@ namespace Robust.Shared.ContentPack
/// </summary>
internal static string GetExecutableDirectory()
{
// TODO: remove this shitty hack, either through making it less hardcoded into shared,
// or by making our file structure less spaghetti somehow.
string location;
if (Process.GetCurrentProcess().MainModule is { } mod)
{
location = mod.FileName;
}
else
{
// Fallback in case the above doesn't work ig?
var assembly = typeof(PathHelpers).Assembly;
location = assembly.Location;
}
// Fallback in case the above doesn't work ig?
var assembly = typeof(PathHelpers).Assembly;
var location = assembly.Location;
if (location == string.Empty)
{
// See https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.location?view=net-5.0#remarks

View File

@@ -98,9 +98,21 @@ def symlink_files(src_dir: str, dest_dir: str, relative: str):
if not symlinkable_re.match(file):
continue
src_path = p(src_dir, file)
dest_symlink = p(dest_dir, file)
if not os.path.islink(dest_symlink):
os.symlink(f"../../../{relative}{file}", dest_symlink)
if os.path.isdir(src_path):
# Symlink directories
if not os.path.islink(dest_symlink):
os.symlink(f"../../../{relative}{file}", dest_symlink)
else:
# Hardlink files
# (so that .NET doesn't report the real file path for assembly locations)
try:
os.remove(dest_symlink)
except FileNotFoundError:
pass # Fine
os.link(src_path, dest_symlink)
main()