tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

100 lignes · 4292 octetsBrut · Historique
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 #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}.
17set -euo pipefail
18cd "$(dirname "$0")/.."
19# mold links, and the shared-host heavy lock for the two compiler builds.
20source scripts/lib.sh
21root=$PWD
22base_rev=$(git rev-parse --verify "${1:-HEAD}^{commit}")
23out="$root/target/same-output"
24mkdir -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.
28build_louise() {
29 (cd "$1" && CARGO_TARGET_DIR="$2" heavy cargo build --quiet -p louise -p louise_rt)
30}
31
32worktree="$out/base-src"
33git worktree remove --force "$worktree" 2>/dev/null || true
34git worktree add --quiet --detach "$worktree" "$base_rev"
35trap 'git worktree remove --force "$worktree"' EXIT
36echo "same-output: building the base ($(git rev-parse --short "$base_rev")) and the working tree"
37build_louise "$worktree" "$out/base-target"
38build_louise "$root" "$root/target"
39
40programs=()
41for f in tests/run/*.lse tests/stress/*.lse tests/bench/*.lse; do programs+=("$f"); done
42packages=(examples/http_demo examples/qsort)
43
44# Writes the outputs of the compiler $1 for the sources $3... under $2.
45produce() {
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
85rm -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.
88produce "$out/base-target/debug/louise" "$out/base" "${programs[@]}" &
89produce "$root/target/debug/louise" "$out/head" "${programs[@]}" &
90wait
91produce "$out/base-target/debug/louise" "$out/base" "${packages[@]}"
92produce "$root/target/debug/louise" "$out/head" "${packages[@]}"
93
94if diff -r "$out/base" "$out/head" >"$out/diff" 2>&1; then
95 echo "same-output: no differences (${#programs[@]} programs, ${#packages[@]} packages)"
96else
97 echo "same-output: differences ($out/diff):"
98 diff -rq "$out/base" "$out/head" | sed "s|$out/||g"
99 exit 1
100fi