HashLink: fix the ability to double-click the .app file on macOS to run it

The HashLink executable expects hlboot.dat and libraries to be in the current working directory (it's not enough for them to be in the same directory as the executable). Make the .app file launch a shell script that 1) changes the current working directory 2) launches the HashLink executable
This commit is contained in:
Josh Tynjala
2022-07-13 10:01:06 -07:00
parent 06baca4396
commit fd0fc3da48
2 changed files with 18 additions and 0 deletions

View File

@@ -207,6 +207,20 @@ class MacPlatform extends PlatformTarget
if (noOutput) return;
HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, is64);
// HashLink looks for hlboot.dat and libraries in the current
// working directory, so the .app file won't work properly if it
// tries to run the HashLink executable directly.
// when the .app file is launched, we can tell it to run a shell
// script instead of the HashLink executable. the shell script will
// adjusts the working directory before running the HL executable.
// unlike other platforms, we want to use the original "hl" name
var hlExecutablePath = Path.combine(executableDirectory, "hl");
System.renameFile(executablePath, hlExecutablePath);
System.runCommand("", "chmod", ["755", hlExecutablePath]);
// then we can use the executable name for the shell script
System.copyFileTemplate(project.templatePaths, 'hl/mac-launch.sh', executablePath);
}
else if (targetType == "java")
{