diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
| commit | 7958276c9f0d230053520ba20f2a00f5ecda18e4 (patch) | |
| tree | 596f5f71ad597ed951bae98de818cb37f171a18d /scripts/run.sh | |
| parent | fs: /bin alias for the system volume (diff) | |
| download | rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.tar.gz rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.zip | |
scripts: rebuild the dev loop around build.sh/run.sh
`make` did not parse at all (missing separator at line 139), so every
make target was dead. The folder also carried three overlapping
launchers (boot.sh, qemu.sh, boot-image.sh) plus a fourth partial one
in the Makefile, `cargo build --package rsdos` copy-pasted eight times,
the QEMU invocation copy-pasted per script, and the test helpers
(fail/wait_log/wait_qemu_exit/qemu_hmp) duplicated in five tests.
New layout:
- scripts/lib.sh: single config (image, OVMF, mem/smp), the one cargo
invocation (build_all), the one QEMU shape (qemu_args), and the test
harness (test_boot, wait_log, wait_qemu_exit, qemu_hmp, sendkeys)
- scripts/build.sh: kernel + every bins/* in one pass
- scripts/mksystem.sh: freshness-aware image build that now stages
every bins/*.efi into /bin/cli|gui (they were never copied before)
- scripts/run.sh: build + stage + boot in one command; --headless,
--debug (GDB stub), --monitor (HMP socket), --fresh, --mem/--smp/
--bios/--image; on Wayland it auto-selects XWayland plus
grab-on-hover so the mouse can be captured (Ctrl+Alt+G toggles)
- scripts/tests/: the five automated tests on the shared harness
- deleted: boot.sh, qemu.sh, boot-image.sh, lib-boot-args.sh,
build-image-release.sh, build-bootloader.sh (rsboot chain dropped)
The Makefile is now a thin wrapper: make run, make test, make system,
make inspect, make help. Two-command flow: ./scripts/build.sh then
./scripts/run.sh (run.sh alone also works).
Stale test assumptions fixed so the suite is green again: test-gfx
waited for "gfx: check" while the shell prints "gfx check: PASS";
test-mouse/test-msg hardcoded msgrecv = task 3 (wm-input took slot 3 —
ids are parsed from the log now); the queue-full probe targeted task 0,
whose exec pump drains its own queue as completion codes (moved to the
cursor task, which never recvs).
Verified in QEMU: make test -> test-disk, test-gfx, test-mouse,
test-msg, test-fault all PASS.
Diffstat (limited to '')
| -rwxr-xr-x | scripts/run.sh | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..4b6f481 --- /dev/null +++ b/scripts/run.sh | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/run.sh — build, stage and boot the system image in QEMU. | ||
| 4 | # | ||
| 5 | # Usage: | ||
| 6 | # ./scripts/run.sh build + stage + boot (window + serial) | ||
| 7 | # ./scripts/run.sh --headless serial console only, no window | ||
| 8 | # ./scripts/run.sh --debug GDB stub on :1234, CPU starts paused | ||
| 9 | # (attach: gdb -x scripts/debug-kernel.py) | ||
| 10 | # ./scripts/run.sh --monitor HMP monitor socket for sendkeys.py / | ||
| 11 | # test-focus.py (default path below) | ||
| 12 | # ./scripts/run.sh --fresh re-create the system image first | ||
| 13 | # (wipes runtime data on the image) | ||
| 14 | # ./scripts/run.sh --mem 512M guest memory (default 256M) | ||
| 15 | # ./scripts/run.sh --smp 2 guest CPUs (default 1) | ||
| 16 | # ./scripts/run.sh --bios FILE OVMF firmware (default: system path) | ||
| 17 | # ./scripts/run.sh --image FILE system image (default: /tmp/system.img) | ||
| 18 | # ./scripts/run.sh --grab confine the pointer: GTK runs as an X11 | ||
| 19 | # (XWayland) client and grabs on hover | ||
| 20 | # ./scripts/run.sh --no-grab Wayland-native window, no pointer grab | ||
| 21 | # | ||
| 22 | # Mouse: Wayland forbids global pointer grabs, so a Wayland-native window | ||
| 23 | # cannot confine the cursor (QEMU's grab silently does nothing). | ||
| 24 | # In a Wayland session with XWayland, run.sh defaults to --grab; | ||
| 25 | # Ctrl+Alt+G toggles the grab in either mode. | ||
| 26 | # | ||
| 27 | # Environment (same names the other scripts honour): TARGET, PROFILE, | ||
| 28 | # SYSTEM_IMG, OVMF, QEMU, MEM, SMP. | ||
| 29 | # | ||
| 30 | # Two-command flow: ./scripts/build.sh && ./scripts/run.sh | ||
| 31 | # One-command flow: ./scripts/run.sh (builds what is missing) | ||
| 32 | # | ||
| 33 | # Monitor socket: /tmp/rsdos-monitor.sock | ||
| 34 | # | ||
| 35 | set -euo pipefail | ||
| 36 | |||
| 37 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| 38 | |||
| 39 | usage() { | ||
| 40 | awk 'NR > 1 && /^#/ { sub(/^# ?/, ""); print; next } NR > 1 { exit }' "$0" | ||
| 41 | } | ||
| 42 | |||
| 43 | HEADLESS=0 | ||
| 44 | DEBUG=0 | ||
| 45 | FRESH=0 | ||
| 46 | MON=0 | ||
| 47 | MON_SOCK="/tmp/rsdos-monitor.sock" | ||
| 48 | GRAB="" # "" = auto: grab when a Wayland session has XWayland | ||
| 49 | |||
| 50 | while [ $# -gt 0 ]; do | ||
| 51 | case "$1" in | ||
| 52 | --headless | -H) HEADLESS=1 ;; | ||
| 53 | # GDB stub + keep whatever profile the env asked for (release is the | ||
| 54 | # default; PROFILE=debug ./scripts/run.sh --debug adds line symbols). | ||
| 55 | --debug | -d) DEBUG=1 ;; | ||
| 56 | --fresh) FRESH=1 ;; | ||
| 57 | --monitor) MON=1 ;; | ||
| 58 | --mem) shift; MEM="$1" ;; | ||
| 59 | --smp) shift; SMP="$1" ;; | ||
| 60 | --bios) shift; OVMF="$1" ;; | ||
| 61 | --image | -i) shift; SYSTEM_IMG="$1" ;; | ||
| 62 | --grab) GRAB=1 ;; | ||
| 63 | --no-grab) GRAB=0 ;; | ||
| 64 | --help | -h) | ||
| 65 | usage | ||
| 66 | exit 0 | ||
| 67 | ;; | ||
| 68 | *) | ||
| 69 | echo "run.sh: unknown argument: $1" >&2 | ||
| 70 | usage >&2 | ||
| 71 | exit 1 | ||
| 72 | ;; | ||
| 73 | esac | ||
| 74 | shift | ||
| 75 | done | ||
| 76 | |||
| 77 | # shellcheck source=lib.sh | ||
| 78 | source "$SCRIPT_DIR/lib.sh" # reads MEM/SMP/OVMF/SYSTEM_IMG from the env | ||
| 79 | |||
| 80 | # build.sh is a separate process: it re-derives OUT_DIR/KERNEL from these, | ||
| 81 | # so whatever we resolved above (including a --mem/--bios override) wins | ||
| 82 | # there too. | ||
| 83 | export TARGET PROFILE QEMU MEM SMP OVMF SYSTEM_IMG | ||
| 84 | |||
| 85 | # ---- mouse grab (Wayland) -------------------------------------------------- | ||
| 86 | # Wayland forbids global pointer grabs, so a Wayland-native GTK window cannot | ||
| 87 | # confine the cursor — QEMU's grab silently does nothing there. XWayland can, | ||
| 88 | # so a Wayland session that has XWayland (DISPLAY set) defaults to GTK-on-X11 | ||
| 89 | # plus grab-on-hover. Ctrl+Alt+G toggles the grab; --no-grab keeps the | ||
| 90 | # Wayland-native window. | ||
| 91 | if [ -z "$GRAB" ]; then | ||
| 92 | if [ "${XDG_SESSION_TYPE:-}" = "wayland" ] && [ -n "${DISPLAY:-}" ]; then | ||
| 93 | GRAB=1 | ||
| 94 | else | ||
| 95 | GRAB=0 | ||
| 96 | fi | ||
| 97 | fi | ||
| 98 | [ "$HEADLESS" -eq 1 ] && GRAB=0 # no window, nothing to grab | ||
| 99 | if [ "$GRAB" -eq 1 ]; then | ||
| 100 | if [ -n "${DISPLAY:-}" ]; then | ||
| 101 | export GDK_BACKEND=x11 | ||
| 102 | else | ||
| 103 | echo "run.sh: --grab needs XWayland (DISPLAY is unset); not grabbing" >&2 | ||
| 104 | GRAB=0 | ||
| 105 | fi | ||
| 106 | fi | ||
| 107 | |||
| 108 | # ---- build + stage -------------------------------------------------------- | ||
| 109 | "$SCRIPT_DIR/build.sh" | ||
| 110 | if [ "$FRESH" -eq 1 ]; then | ||
| 111 | stage_image --force | ||
| 112 | else | ||
| 113 | stage_image | ||
| 114 | fi | ||
| 115 | |||
| 116 | # ---- boot ----------------------------------------------------------------- | ||
| 117 | mapfile -t QARGS < <(qemu_args) | ||
| 118 | if [ "$HEADLESS" -eq 1 ]; then | ||
| 119 | QARGS+=(-display none) | ||
| 120 | else | ||
| 121 | QARGS+=(-vga std) | ||
| 122 | if [ "$GRAB" -eq 1 ]; then | ||
| 123 | QARGS+=(-display gtk,grab-on-hover=on) | ||
| 124 | fi | ||
| 125 | fi | ||
| 126 | [ "$MON" -eq 1 ] && QARGS+=(-monitor "unix:$MON_SOCK,server,nowait") | ||
| 127 | [ "$DEBUG" -eq 1 ] && QARGS+=(-s -S) | ||
| 128 | QARGS+=(-serial stdio) | ||
| 129 | |||
| 130 | echo "" | ||
| 131 | echo "=== boot ===" | ||
| 132 | echo " image: $SYSTEM_IMG" | ||
| 133 | echo " ovmf: $OVMF" | ||
| 134 | echo " mem: $MEM smp: $SMP" | ||
| 135 | echo " mode: $([ "$HEADLESS" -eq 1 ] && echo headless || echo window) gdb: $([ "$DEBUG" -eq 1 ] && echo ':1234 (paused)' || echo off)" | ||
| 136 | if [ "$HEADLESS" -eq 0 ]; then | ||
| 137 | echo " mouse: $([ "$GRAB" -eq 1 ] && echo 'grab on hover (XWayland; Ctrl+Alt+G toggles)' || echo 'not grabbed (Wayland cannot confine the pointer)')" | ||
| 138 | fi | ||
| 139 | [ "$MON" -eq 1 ] && echo " monitor: unix:$MON_SOCK" | ||
| 140 | echo "" | ||
| 141 | |||
| 142 | exec "$QEMU" "${QARGS[@]}" | ||
