From fd0fc3da48335bd60e15696aeb7781e6d9d22703 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Wed, 13 Jul 2022 10:01:06 -0700 Subject: [PATCH] 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 --- templates/hl/mac-launch.sh | 4 ++++ tools/platforms/MacPlatform.hx | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 templates/hl/mac-launch.sh diff --git a/templates/hl/mac-launch.sh b/templates/hl/mac-launch.sh new file mode 100644 index 000000000..7f3b77fca --- /dev/null +++ b/templates/hl/mac-launch.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +# HashLink needs a specific working directory to find hlboot.dat and libraries +cd "$(dirname "$0")" +exec ./hl \ No newline at end of file diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 8829ac3ad..4f80be65a 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -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") {