| Paint the same screens into a terminal ab83b42 nandi 17d ago | 1 | #!/bin/sh |
| 2 | #_( |
| 3 | exec "$(dirname "$0")/bb" "$0" "$@" |
| 4 | ) |
| 5 | |
| 6 | ;; frq's screens in a terminal, from this working tree. |
| 7 | ;; |
| 8 | ;; tui.bb [--headless] [--cols=N] [--rows=N] |
| 9 | ;; |
| 10 | ;; run.bb with the other backend under it. Two things differ, and both are |
| 11 | ;; because the terminal backend is not in a jolt-native release yet: |
| 12 | ;; |
| 13 | ;; * `libjolttui.so` comes out of a jolt-native checkout's target directory |
| 14 | ;; rather than out of a pinned archive, and is linked into build/lib beside |
| 15 | ;; the two that are pinned. Point JOLT_NATIVE at that checkout, or leave it |
| 16 | ;; beside this one. |
| 17 | ;; * `glimmer-tui` — the jolt half of that backend, and the namespace |
| 18 | ;; `frq.tui` requires — is resolved from the same checkout with -Sdeps, |
| 19 | ;; which is what lets this work from a worktree, where the relative path in |
| 20 | ;; deps.edn's `:tui` alias does not point where it does from a clone. The |
| 21 | ;; alias is not used here for that reason: its coordinate for the same |
| 22 | ;; library wins over the one -Sdeps merges in, so this passes `-m` itself |
| 23 | ;; and leaves `jolt -M:tui` to the checkouts the alias is right for. |
| 24 | ;; |
| 25 | ;; When the backend ships in a release, both of those become pins like every |
| 26 | ;; other, and this script becomes run.bb with a different alias. |
| 27 | (require '[babashka.fs :as fs] |
| 28 | '[babashka.process :as p]) |
| 29 | |
| 30 | (def root (str (fs/canonicalize (fs/path (fs/parent *file*) "..")))) |
| 31 | (def lib (fs/path root "build" "lib")) |
| 32 | |
| 33 | (def jolt |
| 34 | (let [pin (fs/path root "scripts" "jolt")] |
| 35 | (if (and (fs/exists? pin) (fs/which "dotslash")) (str pin) "jolt"))) |
| 36 | |
| 37 | (defn die [& msg] |
| 38 | (binding [*out* *err*] (println (apply str msg))) |
| 39 | (System/exit 1)) |
| 40 | |
| 41 | ;; The checkout the terminal backend lives in. A worktree of it counts — what |
| 42 | ;; is wanted is a directory holding `jolt/glimmer-tui` and a built libjolttui. |
| 43 | (def jolt-native |
| 44 | (let [given (System/getenv "JOLT_NATIVE") |
| 45 | guess (fs/path root ".." "jolt-native") |
| 46 | dir (cond |
| 47 | given (fs/path given) |
| 48 | (fs/exists? guess) guess |
| 49 | :else nil)] |
| 50 | (when-not dir |
| 51 | (die "no jolt-native checkout: set JOLT_NATIVE, or put one beside this tree")) |
| 52 | (str (fs/canonicalize dir)))) |
| 53 | |
| 54 | (def glimmer-tui (fs/path jolt-native "jolt" "glimmer-tui")) |
| 55 | |
| 56 | (when-not (fs/exists? glimmer-tui) |
| 57 | (die glimmer-tui " is not there — this wants the branch that carries the " |
| 58 | "terminal backend (crates/jolt-tui and jolt/glimmer-tui)")) |
| 59 | |
| 60 | ;; cargo's release build first, then its debug one, then what buck2 left: any |
| 61 | ;; of the three is the library, and which one a person has is their business. |
| 62 | (def jolttui |
| 63 | (or (first (for [c ["target/release/libjolttui.so" |
| 64 | "target/debug/libjolttui.so"] |
| 65 | :let [p (fs/path jolt-native c)] |
| 66 | :when (fs/exists? p)] |
| 67 | p)) |
| 68 | (first (sort-by (comp - fs/file-time->millis fs/last-modified-time) |
| 69 | (fs/glob (fs/path jolt-native "buck-out") |
| 70 | "**/libjolttui.so"))) |
| 71 | (die "no libjolttui.so under " jolt-native |
| 72 | " — build it: cargo build --release -p jolt-tui"))) |
| 73 | |
| 74 | ;; The two pinned libraries, into build/lib. |
| 75 | (p/shell (str (fs/path root "scripts" "lib.bb"))) |
| 76 | |
| 77 | ;; And the unpinned third, linked rather than copied for the same reason the |
| 78 | ;; others are: a rebuild reaches a running tree without anything here going |
| 79 | ;; stale. |
| 80 | (let [dest (fs/path lib "libjolttui.so")] |
| 81 | (fs/create-dirs lib) |
| 82 | (fs/delete-if-exists dest) |
| 83 | (fs/create-sym-link dest (str (fs/canonicalize jolttui)))) |
| 84 | |
| 85 | (System/exit |
| 86 | (:exit @(apply p/process |
| 87 | {:inherit true |
| 88 | :dir root |
| 89 | :extra-env {"LD_LIBRARY_PATH" |
| 90 | (str lib (when-let [p (System/getenv "LD_LIBRARY_PATH")] |
| 91 | (str ":" p)))}} |
| 92 | jolt |
| 93 | "-Sdeps" (str "{:deps {nandi/glimmer-tui {:local/root \"" |
| 94 | glimmer-tui "\"}}}") |
| 95 | "-m" "frq.tui" *command-line-args*))) |