Skip to content

Commit 77a9916

Browse files
committed
Fixed macOS bindist launcher asking for Rosetta
git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45911 379a1393-f5fb-40a0-bcee-ef074d9b53f7
1 parent 4c99c78 commit 77a9916

File tree

4 files changed

+125
-12
lines changed

4 files changed

+125
-12
lines changed

vice/src/arch/shared/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ AM_LDFLAGS = @VICE_LDFLAGS@
4444

4545
noinst_LIBRARIES = libarchdep.a
4646

47+
if MACOS_COMPILE
48+
# Build native wrapper executable used by macOS apps
49+
noinst_PROGRAMS = macOS-launcher
50+
macOS_launcher_SOURCES = macOS-launcher.c
51+
# Don't link this launcher app to the usual deps
52+
macOS-launcher$(EXEEXT): CPPFLAGS =
53+
macOS-launcher$(EXEEXT): CFLAGS =
54+
macOS-launcher$(EXEEXT): LDFLAGS =
55+
endif
56+
4757
libarchdep_a_SOURCES = \
4858
archdep_access.c \
4959
archdep_boot_path.c \
@@ -266,4 +276,9 @@ EXTRA_DIST = \
266276
uiactions.h \
267277
README-bindist.txt
268278

279+
if !MACOS_COMPILE
280+
# Distribute the native launcher source on non-macOS platforms
281+
EXTRA_DIST += macOS-launcher.c
282+
endif
283+
269284
# FIXME: the Extra MacOS script stuff should live elsewhere
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* macOS-launcher.c - Native wrapper for the macOS launcher bash script
3+
*
4+
* This file is part of VICE, the Versatile Commodore Emulator.
5+
* See README for copyright notice.
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20+
* 02111-1307 USA.
21+
*
22+
*/
23+
24+
#include <stdio.h>
25+
#include <stdlib.h>
26+
#include <unistd.h>
27+
#include <libgen.h>
28+
#include <limits.h>
29+
30+
int main(int argc, char *argv[])
31+
{
32+
/*
33+
* This exists to ensure that macOS doesn't think Rosetta 2 is needed
34+
* to run the bash script launcher. It simply finds the path to the
35+
* bash script (which is in the same directory as this executable) and
36+
* execs it with the same arguments.
37+
*/
38+
39+
char exe_path[PATH_MAX];
40+
char real_path[PATH_MAX];
41+
char script_path[PATH_MAX];
42+
char *exe_dirname;
43+
char *exe_filename;
44+
uint32_t size = sizeof(exe_path);
45+
46+
/* Get the path to this executable \*/
47+
if (_NSGetExecutablePath(exe_path, &size) != 0) {
48+
fprintf(stderr, "Error: Could not determine executable path\n");
49+
return 1;
50+
}
51+
52+
/* Resolve symlinks */
53+
if (realpath(exe_path, real_path) == NULL) {
54+
fprintf(stderr, "Error: Could not resolve executable path\n");
55+
return 1;
56+
}
57+
58+
/* Split into dirname and basename */
59+
exe_dirname = dirname(real_path);
60+
exe_filename = basename(real_path);
61+
62+
/* Build path to the bash script (same directory as this executable) */
63+
snprintf(script_path, sizeof(script_path), "%s/../Resources/%s.sh", exe_dirname, exe_filename);
64+
65+
/* Replace argv[0] with the script path */
66+
argv[0] = script_path;
67+
68+
/* Execute the bash script */
69+
execv(script_path, argv);
70+
71+
/* If we get here, execv failed */
72+
perror("Error executing launcher script");
73+
return 1;
74+
}

vice/src/arch/shared/macOS-launcher.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [[ "$1" == "--program" && -n "$2" ]]; then
4040
shift 2
4141
fi
4242

43-
ROOT_DIR="$(cd "$(dirname "$0")" && pwd -P)/../Resources"
43+
ROOT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
4444

4545
cd "$ROOT_DIR"
4646
source "./bin/common-runtime.sh"

vice/src/arch/shared/make-bindist_osx.sh

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ make_app_bundle() {
266266
rm -rf "$app_path"
267267

268268
# 2) Install launcher
269-
if [[ "$app_launcher" == *.applescript ]]; then
269+
if [[ "$app_launcher" == *.applescript ]]; then
270270
osacompile -o "$app_path" "$app_launcher"
271271
app_exe_filename=droplet
272272

@@ -284,14 +284,22 @@ make_app_bundle() {
284284
cp "$TOP_DIR/data/common/vice-${src_icon_name}_256.png" "$resources/VICE.iconset/icon_256x256.png"
285285
iconutil -c icns "$resources/VICE.iconset" -o "$resources/$icon_name"
286286
rm -rf "$resources/VICE.iconset"
287-
else
287+
elif [[ "$app_launcher" == *.sh ]]; then
288288
mkdir -p "$macos"
289-
cp "$app_launcher" "$macos/$app_name"
290-
chmod +x "$macos/$app_name"
291289

292-
# Install icon
290+
# A native wrapper is needed for macOS to not think it needs Rosetta
291+
cp src/arch/shared/macOS-launcher "$macos/$app_name"
292+
293+
# Move shell script to Resources to avoid code signing issues
293294
mkdir -p "$resources"
295+
cp "$app_launcher" "$resources/${app_name}.sh"
296+
chmod +x "$resources/${app_name}.sh"
297+
298+
# Install icon
294299
cp "$RUN_PATH/Resources/VICE.icns" "$resources/$icon_name"
300+
else
301+
>&2 echo "ERROR: Unknown launcher type: $app_launcher"
302+
exit 1
295303
fi
296304

297305
# 3) Minimal Info.plist
@@ -323,12 +331,11 @@ make_app_bundle() {
323331
<array>
324332
<dict>
325333
<key>CFBundleTypeName</key><string>VICE Files</string>
326-
<key>CFBundleTypeRole</key><string>Viewer</string> <!-- or Editor if you really want -->
334+
<key>CFBundleTypeRole</key><string>Viewer</string>
327335
<key>CFBundleTypeExtensions</key>
328336
<array>
329-
$(for ext in $DROP_EXTENSIONS; do printf ' <string>%s</string>\n' "$ext"; done)
337+
$(for ext in $DROP_EXTENSIONS; do printf ' <string>%s</string>\n' "$ext"; done)
330338
</array>
331-
<!-- optional: <key>LSHandlerRank</key><string>Default</string> -->
332339
</dict>
333340
</array>
334341
</dict>
@@ -513,7 +520,7 @@ elif [ "$UI_TYPE" = "GTK3" ]; then
513520
# Keep only the necessary GTK schemas
514521
TMPDIR=$(mktemp -d)
515522
mv "$APP_SHARE/glib-2.0/schemas/org.gtk.Settings."*.xml $TMPDIR/
516-
rm "$APP_SHARE/glib-2.0/schemas/"*.xml
523+
find "$APP_SHARE"/glib-2.0/schemas/ -name "*.xml" -exec rm {} \;
517524
mv $TMPDIR/* "$APP_SHARE/glib-2.0/schemas/"
518525
rmdir $TMPDIR
519526
glib-compile-schemas "$APP_SHARE/glib-2.0/schemas"
@@ -730,8 +737,25 @@ code_sign_file () {
730737
# Ad-hoc signing
731738
codesign --force --sign - -f "$1"
732739
else
733-
# Signing with provided identity
734-
codesign -s "$CODE_SIGN_ID" --timestamp --options runtime -f "$1"
740+
# Signing with provided identity. Can intermittently fail due to server allocated timestamps.
741+
local codesign_succeeded=false
742+
for in in $(seq 1 4)
743+
do
744+
if codesign -s "$CODE_SIGN_ID" --timestamp --options runtime -f "$1"
745+
then
746+
codesign_succeeded=true
747+
break
748+
else
749+
>&2 echo "Codesign failed, will retry"
750+
sleep 1
751+
fi
752+
done
753+
754+
if ! $codesign_succeeded
755+
then
756+
>&2 echo "Codesign failed, giving up"
757+
false
758+
fi
735759
fi
736760
}
737761

0 commit comments

Comments
 (0)