AtlatestRepositorysigil-doc
1
#!/usr/bin/env bash2
# SD-P7 pristine control: run the FULL suite against the tree as it was before3
# this phase, with the identical command and environment, so any failure can be4
# attributed rather than argued about.5
#6
# TWO TRAPS THIS AVOIDS, both recorded by SD-P1:7
#8
# 1. `sigil -L <dir>` DOES NOT SHADOW THE PACKAGE'S OWN `src/`. Extracting an9
# old tree somewhere and adding it to the load path from THIS package root10
# runs the CURRENT code and produces a "before" transcript measured against11
# the after. The extracted tree is therefore run FROM ITS OWN package root.12
# 2. `dev-redirects.sgl` is sibling-relative, so a detached package needs an13
# ABSOLUTE-path redirects file written for it.14
#15
# And the positive control that makes the result mean anything: the pristine16
# tree must NOT be able to resolve a binding only this phase's code has. If17
# `make-content-profile` is bound in there, the extraction did not work and the18
# run is measuring the wrong tree.19
set -euo pipefail20
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"21
cd "$repo_dir"22
sigil="${SIGIL_D1_COMPILER:-$repo_dir/../task-sigil-language-readers/build/dev/bin/sigil}"23
sigil_sxml_root="${SIGIL_SXML_ROOT:-$repo_dir/../sigil-sxml}"24
base_sha="${1:-$(grep '^base-sha: ' test/transcripts/sd-p7/construction-before.txt | sed 's/^base-sha: //')}"26
test -x "$sigil" || { echo "dev compiler not found at $sigil" >&2; exit 1; }27
git cat-file -e "$base_sha^{commit}" || { echo "no such commit: $base_sha" >&2; exit 1; }29
work=$(mktemp -d /tmp/sd-p7-pristine.XXXXXX)30
trap 'echo "pristine tree left at $work for inspection"' EXIT31
git archive "$base_sha" | tar -x -C "$work"32
test -f "$work/package.sgl" || { echo "extraction produced no package root" >&2; exit 1; }34
cat > "$work/absolute-redirects.sgl" <<EOF35
(redirects36
repos: (list37
(for-repo url: "codeberg:sigil/sigil"38
use: (from-path dir: "$(cd "$repo_dir/../sigil" && pwd)"))39
(for-repo url: "codeberg:sigil/sigil-sxml"40
use: (from-path dir: "$(cd "$sigil_sxml_root" && pwd)"))))41
EOF43
export SIGIL_REDIRECTS="$work/absolute-redirects.sgl"44
export XDG_CACHE_HOME="$work/cache"45
mkdir -p "$XDG_CACHE_HOME"47
echo "=== PRISTINE CONTROL: base $base_sha, extracted to $work"48
cd "$work"50
# POSITIVE CONTROL ON THE EXTRACTION ITSELF, before any result is believed.51
control=$("$sigil" -L src eval '(begin (import (sigil doc)) (display make-content-profile))' 2>&1 || true)52
case "$control" in53
*"unbound"*|*"not exported"*|*"no binding"*)54
echo "PRISTINE_CONTROL_OK: the extracted tree does not know make-content-profile" ;;55
*)56
echo "PRISTINE_CONTROL_FAILED: the extracted tree resolved make-content-profile" >&257
echo " -> this run is measuring the CURRENT code, not the pristine tree" >&258
echo " -> $control" >&259
exit 1 ;;60
esac62
status=063
"$sigil" -L "$sigil_sxml_root/src" -L src -L test -L book test 2>&1 \64
| sed 's/\x1b\[[0-9;]*m//g' || status=$?65
echo "PRISTINE_CONTROL_COMPLETE status=$status"