oxedyne/fe2o3/fe2o3_austenite/tools/gate/skew.sh
7.4 KiB, 1 run, executable
created by r1870400018:66274, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #!/usr/bin/env bash |
| 2 | # Version skew, metrics only: one project compiled by typst.ts 0.14.2 (Daimond's compiler, in node) and by |
| 3 | # typst 0.15.1, and the two PDFs compared page by page (G3, `g_checks.py`). Generic: it takes the project |
| 4 | # as arguments and knows no book. |
| 5 | # |
| 6 | # skew.sh <root> <main> <fontdir> <typst-vendor> |
| 7 | # |
| 8 | # <root> the project root, which is typst's `--root` and the root of the typst.ts gather |
| 9 | # <main> the entry file, relative to <root> |
| 10 | # <fontdir> the project's font directory, relative to <root> or absolute |
| 11 | # <typst-vendor> Daimond's `www/vendor/typst` (the compiler and its `fonts/`) |
| 12 | # |
| 13 | # Environment: SKEW_TYPST (the typst binary, default /home/jason/bin/typst), SKEW_OUT (the scratch parent, |
| 14 | # default ~/.cache/austenite-o4-probe/out), SKEW_EXCLUDE (directories under <root> the typst.ts gather |
| 15 | # leaves out, space separated), SKEW_PACKAGES (a directory of packages for the typst.ts side only, as |
| 16 | # `tools/bench/lib/packages.mjs` describes: `<ns>/<name>/<version>/` or Daimond's `<version>.pack`, for |
| 17 | # instance `www/assets/typst/packs`). Typst 0.15.1 keeps resolving packages from its own cache. |
| 18 | # |
| 19 | # Two rows, each typst.ts against a different 0.15.1 run: |
| 20 | # a as each engine runs in its own setting: typst.ts with the vendor fonts and <fontdir>; 0.15.1 with |
| 21 | # `--font-path <fontdir>`, its own embedded fonts and the system's, the account's own hidden |
| 22 | # b the same font files for both: 0.15.1 with --ignore-system-fonts --ignore-embedded-fonts |
| 23 | # --font-path <vendor>/fonts --font-path <fontdir>; this row separates version skew from font skew |
| 24 | # |
| 25 | # [bio] by construction. Every PDF lives in a directory made under SKEW_OUT and removed on exit; the page |
| 26 | # text is read from a pipe inside g_checks.py and never written; the stderr of every program goes only |
| 27 | # through an awk filter that keeps counts or a closed vocabulary; and the whole of stdout passes a final |
| 28 | # whitelist, so the only lines that can appear are: |
| 29 | # |
| 30 | # skew: typstts gathered sources <n> assets <n> fonts <n> packages <n> missing <n> |
| 31 | # skew: typstts package preview <name> <version> <supplied|missing> (the public registry only) |
| 32 | # skew: typstts compile <ok|failed> |
| 33 | # skew: typstts error <bad-args|no-root|no-main|no-packages|bad-package|too-large|failed> |
| 34 | # skew: row <a|b> typst exit <n> |
| 35 | # skew: row <a|b> typst diagnostics error <n> warning <n> |
| 36 | # skew: row <a|b> pages typstts <n|none> typst <n|none> |
| 37 | # skew: row <a|b> differ <n> pages <none|ranges such as 3-5,9> |
| 38 | # skew: row <a|b> min-similarity <none|d.ddd> |
| 39 | # skew: row <a|b> verdict <same|differs|incomparable> |
| 40 | # skew: error <usage|no-root|scratch> |
| 41 | # skew: suppressed <n> (lines a program printed that the whitelist dropped) |
| 42 | set -u |
| 43 | |
| 44 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 45 | # shellcheck source=gate_lib.sh |
| 46 | . "$HERE/gate_lib.sh" |
| 47 | |
| 48 | main() { |
| 49 | if [ $# -ne 4 ]; then |
| 50 | echo "skew: error usage" |
| 51 | return 2 |
| 52 | fi |
| 53 | local R="$1" M="$2" F="$3" V="$4" |
| 54 | local TYPST="${SKEW_TYPST:-/home/jason/bin/typst}" |
| 55 | local BASE="${SKEW_OUT:-$HOME/.cache/austenite-o4-probe/out}" |
| 56 | local ROOT |
| 57 | ROOT="$(cd "$R" 2>/dev/null && pwd)" || { echo "skew: error no-root"; return 2; } |
| 58 | if [ ! -f "$V/typst_ts_web_compiler.mjs" ] || [ ! -d "$V/fonts" ]; then |
| 59 | echo "skew: error usage" |
| 60 | return 2 |
| 61 | fi |
| 62 | mkdir -p "$BASE" || { echo "skew: error scratch"; return 2; } |
| 63 | # Global, not local: the trap runs after this function has returned. |
| 64 | W="$(mktemp -d "$BASE/skew.XXXXXX")" || { echo "skew: error scratch"; return 2; } |
| 65 | trap 'rm -rf "${W:?}"' EXIT |
| 66 | GATE_SCRATCH="$W" |
| 67 | |
| 68 | local ex=() d |
| 69 | for d in ${SKEW_EXCLUDE:-}; do |
| 70 | ex+=(--exclude "$d") |
| 71 | done |
| 72 | if [ -n "${SKEW_PACKAGES:-}" ]; then |
| 73 | ex+=(--packages "$SKEW_PACKAGES") |
| 74 | fi |
| 75 | |
| 76 | # typst.ts, in node. |
| 77 | gate_cap node "$HERE/skew_ts.mjs" --root "$ROOT" --main "$M" --vendor "$V" --out "$W/ts.pdf" \ |
| 78 | --font-dir "$F" "${ex[@]}" 2>&1 | awk ' |
| 79 | /^typstts: gathered sources [0-9]+ assets [0-9]+ fonts [0-9]+ packages [0-9]+ missing [0-9]+$/ { sub(/^typstts: /, "typstts "); print "skew: " $0; next } |
| 80 | /^typstts: package preview [A-Za-z0-9_-]+ [0-9]+\.[0-9]+\.[0-9]+ (supplied|missing)$/ { sub(/^typstts: /, "typstts "); print "skew: " $0; next } |
| 81 | /^typstts: compile (ok|failed)$/ { sub(/^typstts: /, "typstts "); print "skew: " $0; next } |
| 82 | /^typstts: error (bad-args|no-root|no-main|no-packages|bad-package|too-large|failed)$/ { sub(/^typstts: /, "typstts "); print "skew: " $0; next } |
| 83 | { n++ } |
| 84 | END { if (n) printf "skew: suppressed %d\n", n }' |
| 85 | |
| 86 | # The two 0.15.1 runs, each from the project root so that a relative <fontdir> and <main> resolve as |
| 87 | # they do for `probe.sh`. |
| 88 | local te |
| 89 | ( cd "$ROOT" && gate_typst "$TYPST" compile --diagnostic-format short --root "$ROOT" \ |
| 90 | --font-path "$F" "$M" "$W/a.pdf" ) 2>&1 >/dev/null | row_diag a |
| 91 | te=${PIPESTATUS[0]} |
| 92 | echo "skew: row a typst exit $te" |
| 93 | ( cd "$ROOT" && gate_typst "$TYPST" compile --diagnostic-format short --root "$ROOT" \ |
| 94 | --ignore-system-fonts --ignore-embedded-fonts --font-path "$V/fonts" --font-path "$F" \ |
| 95 | "$M" "$W/b.pdf" ) 2>&1 >/dev/null | row_diag b |
| 96 | te=${PIPESTATUS[0]} |
| 97 | echo "skew: row b typst exit $te" |
| 98 | |
| 99 | row_cmp a "$W/ts.pdf" "$W/a.pdf" |
| 100 | row_cmp b "$W/ts.pdf" "$W/b.pdf" |
| 101 | return 0 |
| 102 | } |
| 103 | |
| 104 | # Counts typst's short-format diagnostics on stdin; prints only the two counts. |
| 105 | row_diag() { |
| 106 | awk -v row="$1" ' |
| 107 | /: error: / || /^error: / { e++; next } |
| 108 | /: warning: / || /^warning: / { w++; next } |
| 109 | END { printf "skew: row %s typst diagnostics error %d warning %d\n", row, e + 0, w + 0 }' |
| 110 | } |
| 111 | |
| 112 | pages_of() { |
| 113 | local n |
| 114 | n="$(pdfinfo "$1" 2>/dev/null | awk '/^Pages:/ { print $2 }')" |
| 115 | echo "${n:-none}" |
| 116 | } |
| 117 | |
| 118 | # row_cmp <a|b> <typst.ts pdf> <typst pdf> |
| 119 | row_cmp() { |
| 120 | echo "skew: row $1 pages typstts $(pages_of "$2") typst $(pages_of "$3")" |
| 121 | if [ ! -s "$2" ] || [ ! -s "$3" ]; then |
| 122 | echo "skew: row $1 verdict incomparable" |
| 123 | return |
| 124 | fi |
| 125 | python3 "$HERE/g_checks.py" compare "$2" "$3" 2>/dev/null | awk -v row="$1" ' |
| 126 | /^g3 pages / { next } |
| 127 | /^g3 differ [0-9]+ pages (none|[0-9]+(-[0-9]+)?(,[0-9]+(-[0-9]+)?)*)$/ { sub(/^g3 /, ""); print "skew: row " row " " $0; next } |
| 128 | /^g3 min-similarity (none|[0-9]\.[0-9][0-9][0-9])$/ { sub(/^g3 /, ""); print "skew: row " row " " $0; next } |
| 129 | /^g3 verdict (same|differs)$/ { sub(/^g3 /, ""); print "skew: row " row " " $0; next } |
| 130 | /^g3 error (unreadable|usage)$/ { print "skew: row " row " verdict incomparable"; next } |
| 131 | { n++ } |
| 132 | END { if (n) printf "skew: suppressed %d\n", n }' |
| 133 | } |
| 134 | |
| 135 | # The final whitelist, over everything main and its children wrote to either stream. |
| 136 | main "$@" 2>&1 | awk ' |
| 137 | /^skew: typstts gathered sources [0-9]+ assets [0-9]+ fonts [0-9]+ packages [0-9]+ missing [0-9]+$/ { print; next } |
| 138 | /^skew: typstts package preview [A-Za-z0-9_-]+ [0-9]+\.[0-9]+\.[0-9]+ (supplied|missing)$/ { print; next } |
| 139 | /^skew: typstts compile (ok|failed)$/ { print; next } |
| 140 | /^skew: typstts error (bad-args|no-root|no-main|no-packages|bad-package|too-large|failed)$/ { print; next } |
| 141 | /^skew: row [ab] typst exit [0-9]+$/ { print; next } |
| 142 | /^skew: row [ab] typst diagnostics error [0-9]+ warning [0-9]+$/ { print; next } |
| 143 | /^skew: row [ab] pages typstts (none|[0-9]+) typst (none|[0-9]+)$/ { print; next } |
| 144 | /^skew: row [ab] differ [0-9]+ pages (none|[0-9]+(-[0-9]+)?(,[0-9]+(-[0-9]+)?)*)$/ { print; next } |
| 145 | /^skew: row [ab] min-similarity (none|[0-9]\.[0-9][0-9][0-9])$/ { print; next } |
| 146 | /^skew: row [ab] verdict (same|differs|incomparable)$/ { print; next } |
| 147 | /^skew: error (usage|no-root|scratch)$/ { print; next } |
| 148 | /^skew: suppressed [0-9]+$/ { print; next } |
| 149 | { n++ } |
| 150 | END { if (n) printf "skew: suppressed %d\n", n }' |
| 151 | exit "${PIPESTATUS[0]}" |