Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

nightly: run from clones outside Documents (a launchd agent cannot read them), match windows by owner pid

Gauthier Piarretteb9d77feb10ef
diff --git a/Scripts/install-nightly.sh b/Scripts/install-nightly.sh
index 6e533f6..cda8a6d 100755
--- a/Scripts/install-nightly.sh
+++ b/Scripts/install-nightly.sh
@@ -1,14 +1,45 @@
#!/bin/zsh
# Installs (or with --remove, removes) the launchd agent that runs the launcher nightly at
-# 03:30 on this Mac, with the display kept awake for the run. Logs land in private/nightly/.
-# The loop is deliberately light (one session per launcher, sign-in window only), see
-# Scripts/launcher-nightly.sh. Usage: Scripts/install-nightly.sh [--remove]
+# 03:30 on this Mac, with the display kept awake for the run. The loop is deliberately light
+# (one session per launcher, sign-in window only), see Scripts/launcher-nightly.sh.
+#
+# The agent does not run from this checkout. A launchd agent cannot read ~/Documents or
+# ~/Desktop (TCC answers "Operation not permitted" to every open, which showed up as zsh's
+# "can't open input file", exit 127, on the first scheduled run), while ~/Library and the rest
+# of the home are readable. So the agent keeps its own clones under ~/.highball-nightly, resets
+# them to origin/main, builds there and runs the nightly from there: it measures what is pushed,
+# not the working tree. Result: ~/.highball-nightly/latest.json, logs in ~/.highball-nightly/log,
+# per-launcher files in ~/.highball-nightly/highball/private/launcher-nightly.
+# Usage: Scripts/install-nightly.sh [--remove]
set -eu
LABEL=com.highball.launcher-nightly
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
+NIGHTLY="$HOME/.highball-nightly"
REPO="$(cd "$(dirname "$0")/.." && pwd)"
-if [ "${1:-}" = --remove ]; then launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true; rm -f "$PLIST"; echo "removed $LABEL"; exit 0; fi
-mkdir -p "$HOME/Library/LaunchAgents" "$REPO/private/nightly"
+if [ "${1:-}" = --remove ]; then launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true; rm -f "$PLIST"; echo "removed $LABEL (clones under $NIGHTLY kept)"; exit 0; fi
+APP_URL=$(git -C "$REPO" remote get-url origin 2>/dev/null || echo https://github.com/gauthierpiarrette/highball.git)
+DB_URL=$(git -C "$REPO/../highball-db" remote get-url origin 2>/dev/null || echo https://github.com/gauthierpiarrette/highball-db.git)
+mkdir -p "$HOME/Library/LaunchAgents" "$NIGHTLY/log"
+cat > "$NIGHTLY/run.sh" <<RUN
+#!/bin/zsh
+# Written by Scripts/install-nightly.sh (Highball). Resets the clones here to origin/main,
+# builds, and runs Scripts/launcher-nightly.sh from the app clone; arguments go to the nightly
+# (for instance --only steam). See install-nightly.sh for why this lives outside ~/Documents.
+set -u
+cd "$NIGHTLY" || exit 1
+sync_repo() { # <url> <dir>: clone once, then follow origin/main
+ if [ -d "\$2/.git" ]; then git -C "\$2" fetch -q origin && git -C "\$2" reset -q --hard origin/main
+ else git clone -q "\$1" "\$2"; fi
+}
+sync_repo "$APP_URL" highball && sync_repo "$DB_URL" highball-db || { echo "nightly: clone failed"; exit 1; }
+cd highball || exit 1
+echo "nightly: app \$(git rev-parse --short HEAD), db \$(git -C ../highball-db rev-parse --short HEAD), \$(date '+%F %T')"
+swift build > build.log 2>&1 || { tail -5 build.log; echo "nightly: build failed"; exit 1; }
+Scripts/build-winlist.sh
+Scripts/launcher-nightly.sh "\$@"
+cp private/launcher-nightly/latest.json "$NIGHTLY/latest.json" 2>/dev/null
+RUN
+chmod +x "$NIGHTLY/run.sh"
cat > "$PLIST" <<PL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -17,14 +48,14 @@ cat > "$PLIST" <<PL
<key>ProgramArguments</key><array>
<string>/usr/bin/caffeinate</string><string>-dis</string>
<string>/bin/zsh</string><string>-lc</string>
- <string>cd "$REPO" &amp;&amp; swift build >/dev/null 2>&amp;1; Scripts/launcher-nightly.sh</string>
+ <string>$NIGHTLY/run.sh</string>
</array>
<key>StartCalendarInterval</key><dict><key>Hour</key><integer>3</integer><key>Minute</key><integer>30</integer></dict>
- <key>StandardOutPath</key><string>$REPO/private/nightly/launcher-nightly.log</string>
- <key>StandardErrorPath</key><string>$REPO/private/nightly/launcher-nightly.err</string>
+ <key>StandardOutPath</key><string>$NIGHTLY/log/launcher-nightly.log</string>
+ <key>StandardErrorPath</key><string>$NIGHTLY/log/launcher-nightly.err</string>
<key>RunAtLoad</key><false/>
</dict></plist>
PL
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
launchctl bootstrap "gui/$(id -u)" "$PLIST"
-echo "installed $LABEL (03:30 daily): $PLIST"
+echo "installed $LABEL (03:30 daily) running from $NIGHTLY: $PLIST"
diff --git a/Scripts/launcher-nightly.sh b/Scripts/launcher-nightly.sh
index a1e6253..56ad76b 100755
--- a/Scripts/launcher-nightly.sh
+++ b/Scripts/launcher-nightly.sh
@@ -6,10 +6,12 @@
#
# Per launcher it records: whether the recipe applied (blocked recipes are expected-fail and
# recorded as such), the installer's exit, crash lines in the launch log, whether a window with
-# the launcher's title appeared, how much of it drew (only when the screen is unlocked; a locked
-# session records "locked", never a verdict), and the process-environment invariant
-# (`highball bottle ps --expect`). Writes private/launcher-nightly/latest.json and one line per
-# launcher on stdout. Usage: Scripts/launcher-nightly.sh [--only <id>...]
+# owned by one of the environment's processes appeared, how much of it drew (only when the screen
+# is unlocked and this process may capture it; a locked session records "locked", a process
+# without Screen Recording access "no-screen-access", never a verdict), and the process-environment
+# invariant (`highball bottle ps --expect`). Writes private/launcher-nightly/latest.json and one
+# line per launcher on stdout. Scheduled by Scripts/install-nightly.sh, which runs it from a clone
+# under ~/.highball-nightly. Usage: Scripts/launcher-nightly.sh [--only <id>...]
set -u
HB=${HB:-.build/debug/highball}
DB=${DB:-../highball-db/recipes/launchers}
@@ -46,21 +48,30 @@ PY
($HB run "$b" "$pinname" > "$OUT/$id-launch.log" 2>&1 &)
sleep "$wait_s"
crash=$(grep -cE 'int3|Unhandled exception|page fault' "$OUT/$id-launch.log")
+ # An empty process list is a failure, not a pass: the launcher exited or never started, and
+ # an invariant over nothing proves nothing.
+ $HB bottle ps "$b" --expect > "$OUT/$id-ps.txt" 2>&1 && env_ok=true || env_ok=false
+ pids=$(awk -F'\t' '$1 ~ /^[0-9]+$/ {print $1}' "$OUT/$id-ps.txt" | paste -sd'|' -)
win="none"; lit="n/a"
- if [ -n "$winlist" ]; then
- # Scripts/winlist prints "<id> pid=<n> wine |<title>| x,y wxh layer=<l> on=<bool>".
- row=$($winlist 2>/dev/null | grep -E "pid=[0-9]+[[:space:]]+wine[[:space:]]" | grep -i "$winre" | head -1); [ -n "$row" ] && win="yes"
- if [ "$win" = yes ] && [ "$locked" = false ]; then
+ if [ -n "$winlist" ] && [ -n "$pids" ]; then
+ # Scripts/winlist prints "<id> pid=<n> wine |<title>| x,y wxh layer=<l> on=<bool>". The window
+ # is matched by its owner's pid, one of this environment's processes, never by title: titles
+ # need Screen Recording access, which a launchd agent does not have (winlist then reports
+ # screen-access=false on stderr, and a capture would be blank).
+ rows=$($winlist 2>"$OUT/$id-winlist.err" | grep -E "pid=($pids)[[:space:]]+wine[[:space:]]")
+ row=$(echo "$rows" | grep "on=true" | head -1); [ -z "$row" ] && row=$(echo "$rows" | head -1)
+ [ -n "$row" ] && win="yes"
+ access=$(grep -o 'screen-access=[a-z]*' "$OUT/$id-winlist.err" | cut -d= -f2)
+ if [ "$locked" = true ]; then lit="locked"
+ elif [ "$access" = false ]; then lit="no-screen-access"
+ elif [ "$win" = yes ]; then
wid=$(echo "$row" | awk '{print $1}')
screencapture -l "$wid" -o -x "$OUT/$id.png" 2>/dev/null && lit=$(python3 -c "
from PIL import Image; im=Image.open('$OUT/$id.png').convert('RGBA'); px=list(im.getdata()); n=len(px)
print('%.2f'%(sum(1 for q in px if q[3]>200 and (q[0]+q[1]+q[2])>90)/n))" 2>/dev/null || echo "n/a")
- elif [ "$locked" = true ]; then lit="locked"; fi
+ fi
fi
- # An empty process list is a failure, not a pass: the launcher exited or never started, and
- # an invariant over nothing proves nothing.
- $HB bottle ps "$b" --expect > "$OUT/$id-ps.txt" 2>&1 && env_ok=true || env_ok=false
- if ! grep -q " program " "$OUT/$id-ps.txt"; then env_ok=false; win="none"; echo "[$id] no program running 90 s after launch (see $OUT/$id-launch.log)"; fi
+ if ! grep -q " program " "$OUT/$id-ps.txt"; then env_ok=false; win="none"; echo "[$id] no program running $wait_s s after launch (see $OUT/$id-launch.log)"; fi
$HB bottle kill "$b" >/dev/null 2>&1; $HB bottle delete "$b" >/dev/null 2>&1
echo "[$id] installed, crash lines $crash, window $win, lit $lit, env invariant $env_ok ($(( $(date +%s) - t0 ))s)"
results+=("{\"id\":\"$id\",\"result\":\"ran\",\"crashLines\":$crash,\"window\":\"$win\",\"lit\":\"$lit\",\"envInvariant\":$env_ok}")
diff --git a/Scripts/winlist.swift b/Scripts/winlist.swift
index 64c7cdc..b319484 100644
--- a/Scripts/winlist.swift
+++ b/Scripts/winlist.swift
@@ -1,5 +1,9 @@
import CoreGraphics
import Foundation
+// Window titles and captures need Screen Recording access. Say on stderr whether this process
+// has it, so a script run without it (a launchd agent, for instance) can tell blank titles and
+// blank captures from missing windows.
+FileHandle.standardError.write("screen-access=\(CGPreflightScreenCaptureAccess())\n".data(using: .utf8)!)
let opts: CGWindowListOption = [.optionAll, .excludeDesktopElements]
let list = CGWindowListCopyWindowInfo(opts, kCGNullWindowID) as? [[String: Any]] ?? []
let filter = CommandLine.arguments.count > 1 ? CommandLine.arguments[1].lowercased() : ""