headless.sh and headless-wayland.sh set XDG_STATE_HOME to the run's state directory as they set the other XDG directories: the Slint app (the slint-720p30 case) keeps its log files there, and its runs had written them to the desktop's ~/.local/state/voelin/logs. measure.sh waits for the Slint app's window (up to 60 s; it took more than 20 s to appear on a busy machine, past the fixed 8 s the case waited) and then measures it for the case's full length. The video README gives the static cases and the Wayland run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.9 KiB
Bash
Executable File
74 lines
2.9 KiB
Bash
Executable File
#!/bin/sh
|
|
# Run a command on a private headless X display: Xvfb, a window manager
|
|
# (openbox: fullscreen, activation and close requests need one) and a
|
|
# private D-Bus session bus, so nothing reaches the desktop the command is
|
|
# started from (its Wayland or X display, its session bus, its portals).
|
|
#
|
|
# spikes/gpui/headless.sh [-d DISPLAY_NUMBER] [-s WIDTHxHEIGHT] [-n] -- COMMAND...
|
|
#
|
|
# -d: the display number (default 91); -s: the screen size (default
|
|
# 3840x2160); -n: no window manager. Run it inside shell.sh (Xvfb, openbox
|
|
# and dbus come from there). The display, the window manager's and the
|
|
# command's state live in $SPIKE_STATE (default: .scratch/gpui-spikes-state
|
|
# of the checkout, which git ignores).
|
|
set -eu
|
|
number=91 size=3840x2160 wm=1
|
|
while [ $# -gt 0 ]; do
|
|
case $1 in
|
|
-d) number=$2; shift 2 ;;
|
|
-s) size=$2; shift 2 ;;
|
|
-n) wm=0; shift ;;
|
|
--) shift; break ;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
[ $# -gt 0 ] || { echo "headless.sh: no command" >&2; exit 2; }
|
|
root=$(cd "$(dirname "$0")/../.." && pwd)
|
|
SPIKE_STATE=${SPIKE_STATE:-$root/.scratch/gpui-spikes-state}
|
|
mkdir -p "$SPIKE_STATE/runtime" "$SPIKE_STATE/config" "$SPIKE_STATE/data" "$SPIKE_STATE/cache" "$SPIKE_STATE/state"
|
|
chmod 700 "$SPIKE_STATE/runtime"
|
|
if [ -e "/tmp/.X11-unix/X$number" ]; then
|
|
echo "headless.sh: display :$number is taken" >&2
|
|
exit 1
|
|
fi
|
|
Xvfb ":$number" -screen 0 "${size}x24" -nolisten tcp -noreset >"$SPIKE_STATE/xvfb-$number.log" 2>&1 &
|
|
xvfb=$!
|
|
trap 'kill $wm_pid $xvfb 2>/dev/null; wait $xvfb 2>/dev/null || true' EXIT INT TERM
|
|
wm_pid=
|
|
i=0
|
|
until [ -e "/tmp/.X11-unix/X$number" ]; do
|
|
i=$((i + 1))
|
|
[ $i -lt 100 ] || { echo "headless.sh: Xvfb did not start" >&2; exit 1; }
|
|
sleep 0.1
|
|
done
|
|
# Never the desktop's display, bus or portals.
|
|
unset WAYLAND_DISPLAY WAYLAND_SOCKET XDG_SESSION_TYPE DBUS_SESSION_BUS_ADDRESS
|
|
export DISPLAY=":$number"
|
|
export XDG_RUNTIME_DIR="$SPIKE_STATE/runtime" XDG_CONFIG_HOME="$SPIKE_STATE/config"
|
|
export XDG_DATA_HOME="$SPIKE_STATE/data" XDG_CACHE_HOME="$SPIKE_STATE/cache"
|
|
# The Slint app keeps its logs in XDG_STATE_HOME: never the desktop's.
|
|
export XDG_STATE_HOME="$SPIKE_STATE/state"
|
|
export GPUI_X11_SCALE_FACTOR=${GPUI_X11_SCALE_FACTOR:-1}
|
|
if [ $wm = 1 ]; then
|
|
openbox --sm-disable >"$SPIKE_STATE/openbox-$number.log" 2>&1 &
|
|
wm_pid=$!
|
|
sleep 0.5
|
|
fi
|
|
# A session bus of its own that starts no services: the desktop's portals
|
|
# (and their backends, which look for a compositor) stay out of the run.
|
|
cat >"$SPIKE_STATE/dbus-session.conf" <<CONF
|
|
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
|
|
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
|
<busconfig>
|
|
<type>session</type>
|
|
<listen>unix:path=$SPIKE_STATE/runtime/bus</listen>
|
|
<auth>EXTERNAL</auth>
|
|
<policy context="default">
|
|
<allow send_destination="*" eavesdrop="true"/>
|
|
<allow eavesdrop="true"/>
|
|
<allow own="*"/>
|
|
</policy>
|
|
</busconfig>
|
|
CONF
|
|
dbus-run-session --config-file="$SPIKE_STATE/dbus-session.conf" -- "$@"
|