From 855111f45102bbc5011c38af05d1be3d5700621d Mon Sep 17 00:00:00 2001 From: tannevaled Date: Sat, 21 Nov 2026 21:57:13 +0100 Subject: [PATCH] scripts: own every built binary, check mktemp, clean up on a signal The script items of #974, left after #968: - rspec/run.sh built parsesweep at /tmp/parsesweep, shared by every checkout on the machine, the same class #968 fixed for rbgo. Both binaries now go into one mktemp directory the run deletes; PARSESWEEP still overrides. - A failed mktemp -d now stops the run in all three scripts. rubyspec/run.sh has no `set -e`, so RBGO used to become /rbgo. - oracle.sh runs under /bin/sh, which may be dash, and dash runs no EXIT trap on a signal. INT and TERM now exit explicitly (130, 143), so the EXIT trap removes the directory on an interrupt as well. - oracle.sh checks its arguments before building, so a usage error answers at once (exit 2) instead of after a compile. Checked: oracle.sh with no arguments and with a bare -e exits 2 without building; `oracle.sh -e 'p [1, 2, 3].sum'` agrees with all four implementations; rspec/run.sh runs end to end (DSL pass=10 fail=0) and its build directory is gone afterwards. Co-Authored-By: Claude Opus 5.5 --- scripts/conformance/rspec/run.sh | 25 +++++++++++++++++-------- scripts/conformance/rubyspec/run.sh | 6 +++++- scripts/oracle.sh | 26 ++++++++++++++++++++------ 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/scripts/conformance/rspec/run.sh b/scripts/conformance/rspec/run.sh index 4cf70556..2d44f9ad 100755 --- a/scripts/conformance/rspec/run.sh +++ b/scripts/conformance/rspec/run.sh @@ -12,6 +12,7 @@ # # Env: # RBGO path to rbgo binary (default: built from ./cmd/rbgo EVERY run) +# PARSESWEEP path to parsesweep (default: built EVERY run, beside rbgo) # RUBY path to MRI ruby (default: first `ruby` on PATH) # CLONES dir holding rspec-* repos (default: /tmp/rspec-clones) set -u @@ -21,19 +22,27 @@ REPO_ROOT="$(cd "$HERE/../../.." && pwd)" RBGO="${RBGO:-}" RUBY="${RUBY:-$(command -v ruby || true)}" CLONES="${CLONES:-/tmp/rspec-clones}" -PARSESWEEP="${PARSESWEEP:-/tmp/parsesweep}" +PARSESWEEP="${PARSESWEEP:-}" echo "== build rbgo ==" -# #964: built EVERY run, into a directory this run owns and deletes. The old -# default reused any /tmp/rbgo already there, built by whichever checkout ran -# first; scripts/oracle.sh and apps/run.sh then picked that same file up. +# #964, #974: every binary this run builds goes into ONE directory it owns and +# deletes. The old defaults were /tmp/rbgo and /tmp/parsesweep, shared by every +# checkout on the machine, so a sweep could run another checkout's helper. A +# failed mktemp stops the run: an empty directory name would put the binaries +# at /rbgo. INT and TERM exit through the EXIT trap, so an interrupted run +# cleans up too. +BUILD_DIR="$(mktemp -d)" || { echo "mktemp -d failed" >&2; exit 1; } +trap 'rm -rf "$BUILD_DIR"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM if [ -z "$RBGO" ]; then - RBGO_DIR="$(mktemp -d)" - trap 'rm -rf "$RBGO_DIR"' EXIT - RBGO="$RBGO_DIR/rbgo" + RBGO="$BUILD_DIR/rbgo" (cd "$REPO_ROOT" && GOWORK=off go build -o "$RBGO" ./cmd/rbgo) || exit 1 fi -(cd "$REPO_ROOT" && GOWORK=off go build -o "$PARSESWEEP" ./scripts/conformance/rspec/parsesweep) || exit 1 +if [ -z "$PARSESWEEP" ]; then + PARSESWEEP="$BUILD_DIR/parsesweep" + (cd "$REPO_ROOT" && GOWORK=off go build -o "$PARSESWEEP" ./scripts/conformance/rspec/parsesweep) || exit 1 +fi echo "rbgo: $RBGO" go version -m "$RBGO" | grep -E 'vcs\.(revision|modified)' || echo " (no vcs stamp in $RBGO: built outside a git tree, or with -buildvcs=false)" diff --git a/scripts/conformance/rubyspec/run.sh b/scripts/conformance/rubyspec/run.sh index 7bd077a8..9ec6e15d 100755 --- a/scripts/conformance/rubyspec/run.sh +++ b/scripts/conformance/rubyspec/run.sh @@ -67,8 +67,12 @@ echo "== build rbgo ==" # line either way. The build cache makes a rebuild cheap; a stale binary # makes a whole sweep measure the wrong code. if [ -z "$RBGO" ]; then - RBGO_DIR="$(mktemp -d)" + # #974: no `set -e` here, so a failed mktemp must stop the run itself, or + # RBGO would become /rbgo. + RBGO_DIR="$(mktemp -d)" || { echo "mktemp -d failed" >&2; exit 1; } trap 'rm -rf "$RBGO_DIR"' EXIT # widened below once RESULTS exists + trap 'exit 130' INT + trap 'exit 143' TERM RBGO="$RBGO_DIR/rbgo" (cd "$REPO_ROOT" && GOWORK=off CGO_ENABLED=0 go build -o "$RBGO" ./cmd/rbgo) || exit 1 fi diff --git a/scripts/oracle.sh b/scripts/oracle.sh index ec2cf1a0..870c9cce 100755 --- a/scripts/oracle.sh +++ b/scripts/oracle.sh @@ -24,20 +24,34 @@ MRI=${MRI:-ruby} JRUBY=${JRUBY:-jruby} TRUFFLE=${TRUFFLE:-truffleruby} +usage() { + echo "usage: $0 (-e '' | -b | )" >&2 + exit 2 +} + +# The arguments are checked before anything is built (#974): a usage error +# answers at once instead of after a compile. +case "${1:-}" in +'') usage ;; +-e | -b | --batch) [ $# -ge 2 ] || usage ;; +esac + # #964: built EVERY run, into a directory this run owns and deletes. It used # to prefer any /tmp/rbgo already present — another checkout's interpreter. +# #974: /bin/sh may be dash, which runs no EXIT trap on a signal, so INT and +# TERM exit explicitly and the EXIT trap still removes the directory. if [ -z "$RBGO" ]; then - RBGO_DIR=$(mktemp -d) + RBGO_DIR=$(mktemp -d) || { + echo "mktemp -d failed" >&2 + exit 1 + } trap 'rm -rf "$RBGO_DIR"' EXIT + trap 'exit 130' INT + trap 'exit 143' TERM RBGO="$RBGO_DIR/rbgo" (cd "$here" && GOWORK=off go build -o "$RBGO" ./cmd/rbgo) || exit 1 fi -usage() { - echo "usage: $0 (-e '' | -b | )" >&2 - exit 2 -} - # run executes a reference binary, or notes that it is absent (so a missing # reference is skipped, not counted as a divergence). run() { # binary, args...