Fix jemacs-qt GUI crash on launch (make-time/sleep type mismatch)
ober
fd3273f3541275b41e83e740744f73f18418b848
--- a/Makefile +++ b/Makefile @@ -225,6 +225,7 @@ vendor-deps: @sh scripts/patch-jerboa-std-compat.sh "$(abspath $(JERBOA)/lib)" @sh scripts/patch-jerboa-shell-compat.sh "$(CURDIR)" @scripts/patch-jerboa-aws-compat.sh "$(CURDIR)" + @sh scripts/patch-jerboa-qt-compat.sh "$(CURDIR)" @echo "=== Vendor complete ===" # Fast-forward existing vendored git checkouts to current upstream HEAD. new file mode 100755 --- /dev/null +++ b/scripts/patch-jerboa-qt-compat.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# patch-jerboa-qt-compat.sh [REPO_ROOT] +# +# Fix (jerboa-qt qt)'s event-loop sleep for Chez. qt-app-exec! does +# (sleep (make-time 'time-duration 50000000 0)) +# but the transpiled library excepts make-time from (chezscheme) and imports it +# from (jerboa prelude), whose SRFI-19 make-time builds a `dt-raw` record. Chez's +# native `sleep` only accepts a Chez `time` record and rejects dt-raw with +# "... is not a time record of type time-duration" +# crashing the GUI on the first event-loop iteration. +# +# Move make-time back to Chez's: drop it from the (except (chezscheme) ...) list +# (so the Chez primitive is visible) and add it to the (except (jerboa prelude) +# ...) list (so the dt-raw one no longer shadows it). string-split/string-join +# stay excepted from the prelude exactly as before. Idempotent. +# +# Patches the transpiled .sls (the build input — jerboa-qt's lib/ is used as-is, +# not re-transpiled). Run from vendor-deps. +set -eu + +repo="${1:-.}" +qtsls="$repo/vendor/jerboa-qt/lib/jerboa-qt/qt.sls" + +[ -f "$qtsls" ] || exit 0 +# Already patched? +if grep -q '(except (jerboa prelude) string-split string-join make-time)' "$qtsls"; then + exit 0 +fi +# Only patch the known committed form (make-time excepted from chezscheme + +# string-split/string-join excepted from prelude). +if grep -q 'make-date make-time meta atom?' "$qtsls" \ + && grep -q '(except (jerboa prelude) string-split string-join)' "$qtsls"; then + sed -i \ + -e 's/make-date make-time meta atom?/make-date meta atom?/' \ + -e 's/(except (jerboa prelude) string-split string-join)/(except (jerboa prelude) string-split string-join make-time)/' \ + "$qtsls" + echo "patch-jerboa-qt-compat: qt-app-exec! sleep now uses Chez make-time" +else + echo "patch-jerboa-qt-compat: qt.sls not in expected form; left unchanged" >&2 +fi