louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#88 · main · 15 min 30 s
0Étoiles
0Forks
40Issues
| 1 | #!/usr/bin/env bash |
| 2 | # Does a refactor change what the compiler produces? Builds `louise` at a |
| 3 | # base revision and from the working tree, and compares, for every program |
| 4 | # in tests/run, tests/stress, tests/bench and the examples: |
| 5 | # - `louise check` output (diagnostics); |
| 6 | # - `louise core` and `louise core --no-opt` (the Core IR); |
| 7 | # - the generated C of `louise build`, in one C unit and in three |
| 8 | # (LOUISE_C_UNITS), without #line directives so paths don't matter. |
| 9 | # Prints each difference and exits 1 if there is one (issue gabla108/louise#226; the |
| 10 | # procedure docs/code-health.md asked of behaviour-preserving PRs). |
| 11 | # |
| 12 | # scripts/same-output.sh [BASE] # BASE: a git revision (default: HEAD) |
| 13 | # |
| 14 | # The base is built in a temporary worktree with its own target directory |
| 15 | # (target/same-output/base, kept between runs to build incrementally). |
| 16 | # Outputs go to target/same-output/{base,head}. |
| 17 | set -euo pipefail |
| 18 | cd "$(dirname "$0")/.." |
| 19 | # mold links, and the shared-host heavy lock for the two compiler builds. |
| 20 | source scripts/lib.sh |
| 21 | root=$PWD |
| 22 | base_rev=$(git rev-parse --verify "${1:-HEAD}^{commit}") |
| 23 | out="$root/target/same-output" |
| 24 | mkdir -p "$out" |
| 25 | |
| 26 | # Builds the compiler and its debug runtime archive, next to each other |
| 27 | # (where `louise build` looks for it). $1: source tree, $2: target dir. |
| 28 | build_louise() { |
| 29 | (cd "$1" && CARGO_TARGET_DIR="$2" heavy cargo build --quiet -p louise -p louise_rt) |
| 30 | } |
| 31 | |
| 32 | worktree="$out/base-src" |
| 33 | git worktree remove --force "$worktree" 2>/dev/null || true |
| 34 | git worktree add --quiet --detach "$worktree" "$base_rev" |
| 35 | trap 'git worktree remove --force "$worktree"' EXIT |
| 36 | echo "same-output: building the base ($(git rev-parse --short "$base_rev")) and the working tree" |
| 37 | build_louise "$worktree" "$out/base-target" |
| 38 | build_louise "$root" "$root/target" |
| 39 | |
| 40 | programs=() |
| 41 | for f in tests/run/*.lse tests/stress/*.lse tests/bench/*.lse; do programs+=("$f"); done |
| 42 | packages=(examples/http_demo examples/qsort) |
| 43 | |
| 44 | # Writes the outputs of the compiler $1 for the sources $3... under $2. |
| 45 | produce() { |
| 46 | local louise=$1 dest=$2 name src d units |
| 47 | shift 2 |
| 48 | mkdir -p "$dest" |
| 49 | for src in "$@"; do |
| 50 | name=${src//\//_} |
| 51 | d="$dest/$name" |
| 52 | mkdir -p "$d" |
| 53 | # Packages are named relative to their directory, files absolutely; |
| 54 | # the paths in diagnostics then match between the two trees. |
| 55 | if [ -d "$src" ]; then |
| 56 | (cd "$src" && "$louise" check . >"$d/check" 2>&1 || true) |
| 57 | (cd "$src" && "$louise" core . >"$d/core" 2>&1 || true) |
| 58 | (cd "$src" && "$louise" core --no-opt . >"$d/core-no-opt" 2>&1 || true) |
| 59 | else |
| 60 | (cd "$root" && "$louise" check "$src" >"$d/check" 2>&1 || true) |
| 61 | (cd "$root" && "$louise" core "$src" >"$d/core" 2>&1 || true) |
| 62 | (cd "$root" && "$louise" core --no-opt "$src" >"$d/core-no-opt" 2>&1 || true) |
| 63 | fi |
| 64 | for units in 1 3; do |
| 65 | local b="$d/c$units" |
| 66 | mkdir -p "$b" |
| 67 | if [ -d "$src" ]; then |
| 68 | # The package's build/ holds other builds' C too: only `prog`'s, |
| 69 | # written afresh, is compared. |
| 70 | rm -f "$src"/build/prog.c "$src"/build/prog.*.c |
| 71 | (cd "$src" && LOUISE_C_UNITS=$units LOUISE_NO_LINE_DIRECTIVES=1 \ |
| 72 | "$louise" build -o "$b/prog" . >"$b/log" 2>&1 || true) |
| 73 | cp "$src"/build/prog.c "$src"/build/prog.*.c "$b/" 2>/dev/null || true |
| 74 | else |
| 75 | (cd "$root" && LOUISE_C_UNITS=$units LOUISE_NO_LINE_DIRECTIVES=1 \ |
| 76 | "$louise" build -o "$b/prog" "$src" >"$b/log" 2>&1 || true) |
| 77 | cp "$b"/build/*.c "$b/" 2>/dev/null || true |
| 78 | fi |
| 79 | # Keep the C and the log only: executables and caches are large. |
| 80 | rm -rf "$b/build" "$b/prog" |
| 81 | done |
| 82 | done |
| 83 | } |
| 84 | |
| 85 | rm -rf "$out/base" "$out/head" |
| 86 | # Single files build into their own directories, so both sides run at |
| 87 | # once; a package builds in its own build/, so those take turns. |
| 88 | produce "$out/base-target/debug/louise" "$out/base" "${programs[@]}" & |
| 89 | produce "$root/target/debug/louise" "$out/head" "${programs[@]}" & |
| 90 | wait |
| 91 | produce "$out/base-target/debug/louise" "$out/base" "${packages[@]}" |
| 92 | produce "$root/target/debug/louise" "$out/head" "${packages[@]}" |
| 93 | |
| 94 | if diff -r "$out/base" "$out/head" >"$out/diff" 2>&1; then |
| 95 | echo "same-output: no differences (${#programs[@]} programs, ${#packages[@]} packages)" |
| 96 | else |
| 97 | echo "same-output: differences ($out/diff):" |
| 98 | diff -rq "$out/base" "$out/head" | sed "s|$out/||g" |
| 99 | exit 1 |
| 100 | fi |