#!/usr/bin/env bash # Build Routine.app and a drag-to-install Routine-.dmg, on a Mac, from a checkout. # UNTESTED ON A MAC so far: see docs/building-the-mac-app.md (what to run, what to send back). # # scripts/build-mac-app.sh → dist/Routine.app and dist/Routine-.dmg # # Needs: macOS 13+, curl, an internet connection. No Xcode, no Homebrew, no admin password: like # install-mac.sh it fetches uv, which fetches its own Python and the pinned packages, all under # build/mac/. PyInstaller freezes the app (Python and Qt inside the bundle), the bundle is signed # ad hoc (codesign -s -: no Apple developer account, so not notarized: macOS asks once before the # first open, see the doc), and the .dmg holds the app beside a shortcut to /Applications. # The app is for the build machine's kind of Mac: built on Apple silicon it runs on Apple silicon. # # BUILD_TEST=1 lets the PyInstaller part run off a Mac (to test the freezing; no .app, no .dmg). set -euo pipefail REPO="$(cd "$(dirname "$0")/.." && pwd)" UV_VERSION="0.10.4" PYTHON_VERSION="3.13" PINS=(PySide6-Essentials==6.11.0 pyinstaller==6.22.3) OUT="$REPO/dist" WORK="$REPO/build/mac" die() { printf 'build-mac-app: %s\n' "$*" >&2; exit 1; } MAC=0 [ "$(uname -s)" = Darwin ] && MAC=1 [ "$MAC" = 1 ] || [ "${BUILD_TEST:-}" = 1 ] || die "run this on a Mac (BUILD_TEST=1 to try the freezing elsewhere)" VERSION="$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "$REPO/routine/__init__.py")" [ -n "$VERSION" ] || die "no __version__ in routine/__init__.py" rm -rf "$WORK/work" "$WORK/dist" "$WORK/dmg" mkdir -p "$WORK" "$OUT" # ── uv → Python → PySide6 + PyInstaller, all under build/mac ── export UV_PYTHON_INSTALL_DIR="$WORK/python" UV_CACHE_DIR="$WORK/cache" UV_PYTHON_PREFERENCE=only-managed UV_NO_CONFIG=1 UV="${ROUTINE_UV:-$WORK/uv/uv}" if [ ! -x "$UV" ]; then echo "Downloading uv $UV_VERSION …" curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" | env UV_UNMANAGED_INSTALL="$WORK/uv" INSTALLER_NO_MODIFY_PATH=1 sh >/dev/null || die "couldn't download uv" fi [ -x "$WORK/venv/bin/python" ] || "$UV" venv --quiet --python "$PYTHON_VERSION" "$WORK/venv" "$UV" pip install --quiet --python "$WORK/venv/bin/python" "${PINS[@]}" PY="$WORK/venv/bin/python" # ── freeze ── echo "Freezing Routine $VERSION …" ICON=() [ "$MAC" = 1 ] && ICON=(--icon "$REPO/shared/icon.icns" --osx-bundle-identifier me.teafry.routine) (cd "$REPO" && "$PY" -m PyInstaller --noconfirm --clean --log-level WARN --windowed --name Routine \ "${ICON[@]}" \ --add-data "$REPO/shared:shared" \ --exclude-module PyQt6 --exclude-module PyQt5 --exclude-module tkinter \ --paths "$REPO" \ --distpath "$WORK/dist" --workpath "$WORK/work" --specpath "$WORK" \ "$REPO/routine/__main__.py") if [ "$MAC" != 1 ]; then echo "BUILD_TEST: frozen into $WORK/dist/Routine (no .app or .dmg off a Mac)." exit 0 fi APP="$WORK/dist/Routine.app" [ -d "$APP" ] || die "PyInstaller made no Routine.app" PLIST="$APP/Contents/Info.plist" plutil -replace CFBundleName -string Routine "$PLIST" plutil -replace CFBundleDisplayName -string Routine "$PLIST" plutil -replace CFBundleShortVersionString -string "$VERSION" "$PLIST" plutil -replace CFBundleVersion -string "$VERSION" "$PLIST" plutil -replace LSMinimumSystemVersion -string 13.0 "$PLIST" plutil -replace NSHighResolutionCapable -bool true "$PLIST" plutil -replace LSApplicationCategoryType -string public.app-category.productivity "$PLIST" echo "Signing (ad hoc) …" codesign --force --deep --sign - "$APP" codesign --verify --deep --strict "$APP" || die "the signature doesn't verify" echo "Making the .dmg …" STAGE="$WORK/dmg" mkdir -p "$STAGE" cp -R "$APP" "$STAGE/" ln -s /Applications "$STAGE/Applications" DMG="$OUT/Routine-$VERSION.dmg" rm -f "$DMG" hdiutil create -quiet -volname "Routine $VERSION" -srcfolder "$STAGE" -ov -format UDZO "$DMG" rm -rf "$OUT/Routine.app" cp -R "$APP" "$OUT/" echo echo "Done: $DMG ($(du -h "$DMG" | cut -f1)), for $(uname -m) Macs." echo "Try it: open the .dmg, drag Routine to Applications, open it from there."