AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# Regenerate `test/transcripts/sd-p1/classification-before.txt` -- the measured3
# behaviour of `@text{}`/`@expr{}` under the PRE-SD-P1 parser.4
#5
# This exists as a script rather than as a command someone once ran because the6
# transcript is an INPUT to `test/gate-sd-p1.sh` arm 2, and a reviewer must be7
# able to re-derive it rather than trust it.8
#9
# THE TRAP IT EXISTS TO AVOID: `sigil -L <other>/src` invoked from THIS package's10
# root does NOT shadow this package's own `src/`. Driving a "before" run that way11
# silently measures the CURRENT parser and produces a transcript that looks12
# perfect and means nothing. The pristine tree is therefore extracted as a13
# STANDALONE PACKAGE and run from its own root, and this script emits the14
# marker `PRE_SD_P1_CONTROL_UNBOUND` only after positively confirming that the15
# tree it ran cannot resolve a binding that exists solely in the new parser.16
set -euo pipefail17
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"18
cd "$repo_dir"19
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"20
base="${SD_P1_BASE:-c41979c}"21
out="test/transcripts/sd-p1/classification-before.txt"23
test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }24
git rev-parse --verify "$base^{commit}" >/dev/null 2>&1 || {25
echo "base commit $base is not resolvable" >&2; exit 1; }27
pre="$repo_dir/build/sd-p1-pre"28
rm -rf "$pre"; mkdir -p "$pre" "$(dirname "$out")"29
# `book` and `test/fixtures` come along because the lowering dump names30
# manuscripts by repo-relative path and must read the pre-SD-P1 copies of them.31
git archive "$base" src package.sgl book test/fixtures | tar -x -C "$pre"32
cp test/sd-p1-classification-probe.sgl "$pre/probe.sgl"33
cp test/sd-p1-lowering-dump.sgl "$pre/dump.sgl"35
# `dev-redirects.sgl` is SIBLING-RELATIVE, so a package living under build/36
# cannot use it. Write an absolute-path equivalent.37
sibling="$(cd "$repo_dir/.." && pwd)"38
cat >"$pre/abs-redirects.sgl" <<EOF39
(redirects40
repos: (list41
(for-repo url: "codeberg:sigil/sigil"42
use: (from-path dir: "$sibling/sigil"))43
(for-repo url: "codeberg:sigil/sigil-sxml"44
use: (from-path dir: "$sibling/sigil-sxml"))))45
EOF47
cache=$(mktemp -d "$repo_dir/build/sd-p1-before-cache.XXXXXX")48
control_log="$cache/control.log"50
# THE INSTRUMENT CHECK, before any measurement is believed.51
set +e52
( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \53
"$sigil" -L src eval '(begin (import (sigil doc private parser)) (display sigil-doc-profile))' ) \54
>"$control_log" 2>&155
set -e56
if ! grep -q "unbound variable 'sigil-doc-profile'" "$control_log"; then57
echo "POSITIVE CONTROL FAILED: the tree under test resolved sigil-doc-profile," >&258
echo "so it is NOT the pre-SD-P1 parser. Refusing to write a before transcript." >&259
cat "$control_log" >&260
exit 161
fi63
probe_log="$cache/probe.log"64
( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \65
"$sigil" -L src eval -f probe.sgl ) >"$probe_log" 2>&166
# DERIVE the expected case count from the probe source rather than repeating67
# it here. A hardcoded count went stale the moment a case was added, and this68
# guard then failed a run whose probe had actually worked perfectly.69
cases=$(grep -c '^(report "' test/sd-p1-classification-probe.sgl)70
test "$cases" -ge 1 || { echo "could not count the probe's cases" >&2; exit 1; }71
grep -q "SD_P1_CLASSIFICATION_PROBE_COMPLETE $cases cases" "$probe_log" || {72
echo "the pre-SD-P1 probe did not run all $cases cases" >&2; cat "$probe_log" >&2; exit 1; }74
dump_log="$cache/lowering.log"75
( cd "$pre" && SIGIL_REDIRECTS="$pre/abs-redirects.sgl" XDG_CACHE_HOME="$cache" \76
"$sigil" -L src eval -f dump.sgl ) >"$dump_log" 2>&177
grep -q 'SD_P1_LOWERING_DUMP_COMPLETE 10 manuscripts' "$dump_log" || {78
echo "the pre-SD-P1 lowering dump did not cover all 10 manuscripts" >&279
tail -20 "$dump_log" >&2; exit 1; }80
cp "$dump_log" test/transcripts/sd-p1/lowering-before.txt81
echo "wrote test/transcripts/sd-p1/lowering-before.txt ($(wc -l <"$dump_log") lines)"83
{84
echo "# Measured behaviour of @text{}/@expr{} under the PRE-SD-P1 parser."85
echo "# Regenerate with test/sd-p1-before-transcript.sh"86
echo "#"87
echo "# base commit: $base"88
echo "# parser blob: $(git rev-parse "$base:src/sigil/doc/private/parser.sgl")"89
echo "# compiler: $("$sigil" --version 2>&1 | sed -e 's/\x1b\[[0-9;]*m//g')"90
echo "#"91
echo "# POSITIVE CONTROL -- the tree measured below could not resolve a binding"92
echo "# that exists only in the post-SD-P1 parser, so it really is the old one:"93
sed -e 's/^/# /' "$control_log"94
echo "PRE_SD_P1_CONTROL_UNBOUND"95
cat "$probe_log"96
} >"$out"98
echo "wrote $out"