-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile-macos.sh
More file actions
executable file
·117 lines (100 loc) · 4.13 KB
/
Copy pathcompile-macos.sh
File metadata and controls
executable file
·117 lines (100 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# compile-macos.sh - compiles sitemap-tracker into a standalone macOS binary
# with Nuitka, with a bundled Chromium browser.
#
# Output: dist/sitemap-tracker/sitemap-tracker + browsers/, and
# dist/sitemap-tracker-vX.Y.Z-macos-<arch>.tar.gz ready to hand out.
#
# Build machine needs the Xcode Command Line Tools (clang): xcode-select --install
#
# Nuitka ad-hoc signs the binary automatically. On download, macOS quarantines
# it - the recipient clears it once: xattr -dr com.apple.quarantine sitemap-tracker
# No .app bundle (this is a TUI). The arch (arm64/x86_64) is host-bound.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
entry="$root/src/sitemap_tracker/__main__.py"
init_py="$root/src/sitemap_tracker/__init__.py"
out_dir="$root/dist"
dist_dir="$out_dir/sitemap-tracker"
arch="$(uname -m)" # arm64 (Apple Silicon) oder x86_64 (Intel)
if ! command -v clang >/dev/null 2>&1; then
echo "Fehlt: clang - bitte Xcode Command Line Tools installieren: xcode-select --install" >&2
exit 1
fi
# venv mit dem Lockfile abgleichen - VOR der python-Ermittlung, damit .venv
# auch bei einem frischen Checkout (z.B. CI) existiert.
if command -v uv >/dev/null 2>&1; then
echo "Syncing venv (uv sync --inexact)..."
uv sync --inexact --project "$root"
fi
if [ -x "$root/.venv/bin/python" ]; then
python="$root/.venv/bin/python"
else
python="python3"
fi
# Chromium pruefen/aktualisieren (idempotent - laedt nur bei Bedarf)
echo "Checking Playwright Chromium..."
"$python" -m playwright install chromium
# portables sed - 'grep -oP' gibt es auf dem BSD-grep von macOS nicht
version="$(sed -n 's/^__version__ *= *"\([^"]*\)".*/\1/p' "$init_py")"
if [ -z "$version" ]; then
echo "Konnte __version__ nicht aus $init_py lesen" >&2
exit 1
fi
echo "Compiling sitemap-tracker v$version ($arch) with Nuitka..."
rm -rf "$dist_dir"
started=$(date +%s)
# Den Playwright-Node-Treiber NICHT explizit einschliessen - das macht Nuitkas
# eingebautes playwright-Plugin. Ein zusaetzliches --include-package-data=
# playwright kollidiert mit dem Plugin ("data file
# 'playwright/driver/node' conflicts with exe").
nuitka_args=(
--standalone
--assume-yes-for-downloads
--remove-output
--include-package=sitemap_tracker
--include-package-data=sitemap_tracker
--output-dir="$out_dir"
--output-filename=sitemap-tracker
)
# App-Icon einbetten. Natives .icns verwenden - ein PNG braeuchte hier sonst
# das Zusatzpaket imageio (Nuitka: "Need to install 'imageio' ...").
icon_icns="$root/assets/icon.icns"
if [ -f "$icon_icns" ]; then
nuitka_args+=(--macos-app-icon="$icon_icns")
else
echo "Hinweis: $icon_icns fehlt - Binary wird ohne Icon gebaut."
fi
# Nuitka als Build-Tool sicherstellen (kein Dev-Dep, wird ad-hoc installiert).
# 'uv sync' ohne --inexact entfernt es wieder, daher: nach jedem Sync pruefen.
if ! "$python" -m nuitka --version >/dev/null 2>&1; then
echo "Nuitka fehlt im venv - installiere..."
uv pip install nuitka || { echo "Nuitka-Installation fehlgeschlagen" >&2; exit 1; }
fi
"$python" -m nuitka "${nuitka_args[@]}" "$entry"
if [ -d "$out_dir/__main__.dist" ]; then
mv "$out_dir/__main__.dist" "$dist_dir"
fi
# Nur die neueste Headless-Shell mitbuendeln (~265 MB). Alle Use-Cases laufen
# headless (Azure-Pipeline + Standalone-Terminal-TUI) - das volle Chromium
# (~407 MB) wird nie gebraucht. --no-headless faellt auf System-Chrome zurueck.
echo "Bundling Chromium headless shell..."
browsers_dir="$dist_dir/browsers"
mkdir -p "$browsers_dir"
cache="${HOME}/Library/Caches/ms-playwright"
latest="$(ls -d "$cache/chromium_headless_shell-"* 2>/dev/null | sort -V | tail -1)"
if [ ! -d "$latest" ]; then
echo "Kein chromium_headless_shell im Playwright-Cache gefunden" >&2
exit 1
fi
cp -r "$latest" "$browsers_dir/"
elapsed=$(( $(date +%s) - started ))
size_mb=$(du -sm "$dist_dir" | cut -f1)
tarball="$out_dir/sitemap-tracker-v$version-macos-$arch.tar.gz"
rm -f "$tarball"
tar -czf "$tarball" -C "$out_dir" sitemap-tracker
tar_mb=$(du -sm "$tarball" | cut -f1)
echo ""
echo "Done in ${elapsed}s"
echo " dist folder : $dist_dir (${size_mb} MB)"
echo " tarball : $tarball (${tar_mb} MB)"