#!/usr/bin/env bash # Reports how the WPT checkLayout score (docs/wpt-checklayout.md) changed from the merge # base with main to this checkout: totals before and after, and the pages that gained or # lost passing subtests. Report only: a score drop never fails this script, and nothing is # admitted from the score. It exits non-zero only when the report could not be made. # # bench/checklayout-diff.sh [base-ref] # base-ref defaults to: git merge-base HEAD main # # Run from a worktree root. Like bench/on-lane.sh it runs on the build lane when one answers # and here otherwise (WEBENGINE_ON_LANE set means it already is one); bench/verify.sh calls # it at the end of the gate and prints a failure as a note, never as a failed gate. # # Steps: the WPT checkout (oracle/suites/fetch-checklayout.sh, through the rig's mirror); # the baseline summary for the base commit, taken from docs/wpt-checklayout-results.json # when that file was written at the base commit, else from the cache, else by exporting the # base tree (git archive, no worktree registered), building its scorer and running it, and # keeping the summary in $WEBENGINE_CHECKLAYOUT_CACHE (default $HOME/.cache/webengine-checklayout) # keyed by commit and WPT commit; then the scorer built here, run with --against. set -euo pipefail BENCH_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WORKTREE="$(cd "$BENCH_DIR/.." && pwd)" if [ -z "${WEBENGINE_ON_LANE:-}" ]; then # The base is resolved here: the lane's own main can be behind this checkout's. exec "$BENCH_DIR/on-lane.sh" "$WORKTREE" bash bench/checklayout-diff.sh \ "$(git -C "$WORKTREE" rev-parse "${1:-$(git -C "$WORKTREE" merge-base HEAD main)}")" fi cd "$WORKTREE" BASE="$(git rev-parse "${1:-$(git merge-base HEAD main)}")" CACHE="${WEBENGINE_CHECKLAYOUT_CACHE:-$HOME/.cache/webengine-checklayout}" WPT="$WORKTREE/oracle/suites/checkouts/wpt-checklayout" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT "$WORKTREE/oracle/suites/fetch-checklayout.sh" "$WPT" WPT_COMMIT="$(git -C "$WPT" rev-parse HEAD)" # score [scorer args]: builds the scorer in and scores the WPT checkout. score() { local tree="$1" out="$2" shift 2 # Compiler warnings and the scorer's per-page HTML parser messages are kept out of the # report; they are shown only when a step fails. local log="$WORK/step.log" (cd "$tree" && cargo build --release --locked -q -p layout --bin wpt_checklayout 2>"$log") || { tail -n 40 "$log" >&2; return 1; } (cd "$tree" && "${CARGO_TARGET_DIR:-target}/release/wpt_checklayout" --wpt "$WPT" --summary "$out" "$@" 2>"$log") \ || { tail -n 40 "$log" >&2; return 1; } } mkdir -p "$CACHE" BASELINE="$CACHE/$BASE-$WPT_COMMIT.json" if [ -s "$BASELINE" ]; then echo "checklayout-diff: baseline for $BASE from the cache" >&2 elif git show "$BASE:docs/wpt-checklayout-results.json" >"$WORK/committed.json" 2>/dev/null \ && python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); sys.exit(not (d["engine_commit"]==sys.argv[2] and d["wpt_commit"]==sys.argv[3]))' \ "$WORK/committed.json" "$BASE" "$WPT_COMMIT"; then echo "checklayout-diff: baseline for $BASE is the committed docs/wpt-checklayout-results.json" >&2 cp "$WORK/committed.json" "$BASELINE" else echo "checklayout-diff: scoring the base commit $BASE" >&2 mkdir "$WORK/base" if ! git cat-file -e "$BASE:crates/layout/src/bin/wpt_checklayout.rs" 2>/dev/null; then echo "checklayout-diff: $BASE predates the checkLayout scorer, so there is no report" >&2 exit 1 fi # -m: extracted files get the current time, not the commit's, so cargo never takes an # older build of other sources as up to date. git archive "$BASE" | tar -x -m -C "$WORK/base" # The base tree builds into a target directory of its own: built into the caller's, the # scorer binary of one tree is taken for the other's, and the base is scored with the # wrong code. CARGO_TARGET_DIR="$CACHE/base-target" score "$WORK/base" "$WORK/base-summary.json" >/dev/null # An exported tree has no .git, so the scorer could not read its commit. python3 -c 'import json,sys; p=sys.argv[1]; d=json.load(open(p)); d["engine_commit"]=sys.argv[2]; json.dump(d,open(p,"w"),indent=2)' \ "$WORK/base-summary.json" "$BASE" mv "$WORK/base-summary.json" "$BASELINE" fi # The scorer prints its usual table, then the report; only the report is kept. score "$WORKTREE" "$WORK/head-summary.json" --against "$BASELINE" >"$WORK/out.txt" sed -n '/^checkLayout score, engine/,$p' "$WORK/out.txt"