Debian Codegraph @

.github/workflows/scripts/ffosxbuild.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -e -o pipefail
4 SCRIPT_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5 INVOKE_BASE="$(pwd)"
6
7 APPDIR=$(realpath $1)
8 HASH=${2:0:7}
9 PYTHON="$3"
10
11 if [ -z "$APPDIR" ]; then
12 echo "Usage: `basename $0` appdir hash"
13 echo " appdir is the location to the FontForge.app that cmake generated"
14 echo " hash is the version hash of this build"
15 echo
16 echo " This script does not support overwriting an existing bundle."
17 exit 1
18 fi
19
20 builddate=`date +%Y-%m-%d`
21
22 if [ -z "$LDDX" ]; then
23 LDDX="$SCRIPT_BASE/lddx"
24 if [ ! -f "$LDDX" ]; then
25 LDDX="$INVOKE_BASE/lddx"
26 if [ ! -f "$LDDX" ]; then
27 echo "Fetching lddx..."
28 curl -L https://github.com/jtanx/lddx/releases/download/v0.1.0/lddx-0.1.0.tar.xz | tar -Jxf - -C "$INVOKE_BASE"
29 fi
30 fi
31 fi
32
33 # Now we bundle the Python libraries
34 echo "Bundling Python libraries..."
35
36 PY_DLLS_PATH=`$PYTHON "$GITHUB_WORKSPACE/repo/pyhook/get_pyhook_install_dir.py" "" "APPLE"`
37
38 PYLIB=$(otool -L $APPDIR/Contents/Resources/opt/local/bin/fontforge | grep -i python | sed -e 's/ \(.*\)//')
39 PYVER=$(echo $PYLIB | rev | cut -d/ -f2 | rev)
40 PYTHON=python$PYVER
41 pycruft=$(realpath $(dirname $PYLIB)/../../..)
42
43 echo "pycruft: $pycruft"
44 mkdir -p $APPDIR/Contents/Frameworks
45 cp -a $pycruft/Python.framework $APPDIR/Contents/Frameworks
46 pushd $APPDIR/Contents/Frameworks/Python.framework/Versions/$PYVER/lib/$PYTHON/
47 rm site-packages || rm -rf site-packages
48 ln -s ../../../../../../Resources/opt/local/$PY_DLLS_PATH
49 popd
50
51 pushd $APPDIR/Contents/Resources/opt/local/$PY_DLLS_PATH
52 cp -Rn "$pycruft/Python.framework/Versions/$PYVER/lib/$PYTHON/site-packages/" .
53 popd
54
55 find "$APPDIR/Contents/Frameworks/Python.framework" -type f -name '*.pyc' | xargs rm -rf
56
57 pushd $APPDIR/Contents/Resources/opt/local
58 echo "Collecting and patching dependent libraries..."
59 $LDDX --overwrite --modify-special-paths --recursive --ignore-prefix /opt/X11 --collect lib \
60 bin/ $APPDIR/Contents/Frameworks/Python.framework/ lib/
61 popd
62
63 mkdir -p $APPDIR/Contents/MacOS
64 ln -s ../Frameworks/Python.framework/Versions/$PYVER/bin/$PYTHON "$APPDIR/Contents/MacOS/FFPython"
65
66 # --- Code signing -----------------------------------------------------------
67 # This MUST run after lddx: its install_name_tool rewrites above invalidate the
68 # linker's ad-hoc signatures on the collected dylibs/modules. On Apple Silicon
69 # every Mach-O must carry a valid signature to load, so we re-sign everything.
70 #
71 # Defaults to ad-hoc ("-"), which makes the bundle launchable on arm64 with the
72 # usual Gatekeeper bypass (right-click -> Open). To produce a hardened-runtime,
73 # notarizable bundle instead, set CODESIGN_IDENTITY to a real
74 # "Developer ID Application: Name (TEAMID)" identity (see #5112); CI sets this
75 # automatically when signing secrets are present.
76 IDENTITY="${CODESIGN_IDENTITY:--}"
77 ENTITLEMENTS="${CODESIGN_ENTITLEMENTS:-$SCRIPT_BASE/../../../osx/entitlements.plist}"
78
79 if [ "$IDENTITY" = "-" ]; then
80 echo "Ad-hoc signing the bundle..."
81 LIB_SIGN=(--force --timestamp=none --sign -)
82 APP_SIGN=(--force --timestamp=none --sign -)
83 else
84 echo "Signing the bundle with identity: $IDENTITY"
85 # Hardened runtime + secure timestamp are required for notarization.
86 # Entitlements (incl. disable-library-validation, so the embedded Python
87 # interpreter can load third-party C extensions) go on the main app only.
88 LIB_SIGN=(--force --options runtime --timestamp --sign "$IDENTITY")
89 APP_SIGN=(--force --options runtime --timestamp --sign "$IDENTITY" --entitlements "$ENTITLEMENTS")
90 fi
91
92 # 1. Sign every nested Mach-O (dylibs, Python .so modules, helper executables).
93 # -type f skips the symlinks created above.
94 echo "Signing nested Mach-O files..."
95 find "$APPDIR" -type f | while read -r f; do
96 if file "$f" | grep -q "Mach-O"; then
97 codesign "${LIB_SIGN[@]}" "$f"
98 fi
99 done
100
101 # 2. Sign the embedded Python framework version.
102 codesign "${LIB_SIGN[@]}" "$APPDIR/Contents/Frameworks/Python.framework/Versions/$PYVER"
103
104 # 3. Sign the app bundle itself last (main executable receives entitlements).
105 codesign "${APP_SIGN[@]}" "$APPDIR"
106
107 # Verify integrity. Do NOT use spctl here: it rejects ad-hoc signatures by
108 # design and would fail CI spuriously. notarytool (when enabled) is the real
109 # Gatekeeper-level check.
110 codesign --verify --strict --verbose=2 "$APPDIR"
111 # ---------------------------------------------------------------------------
112
113 # Package it up
114 if [ ! -z "$CI" ]; then
115 echo "Creating the dmg..."
116 if [[ "$PYVER" < "3" ]]; then
117 dmgname=FontForge-$builddate-${HASH:0:7}-$PYTHON.app.dmg
118 else
119 dmgname=FontForge-$builddate-${HASH:0:7}.app.dmg
120 fi
121
122 hdiutil create -size 800m \
123 -volname FontForge \
124 -srcfolder $APPDIR \
125 -ov -format UDBZ \
126 $dmgname
127 fi