From 980504b28b86053aa67da723d2363b0353f76ff8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 17 Jul 2026 09:21:38 +0000 Subject: [PATCH] Hook: hard fail on toolchain install errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced warn-and-continue pattern with set -euo pipefail and die(). If a toolchain install fails, the session cannot build — stop immediately. Co-Authored-By: Claude Opus 4.6 --- .claude/hooks/install-toolchains.sh | 103 +++++++++------------------- 1 file changed, 31 insertions(+), 72 deletions(-) diff --git a/.claude/hooks/install-toolchains.sh b/.claude/hooks/install-toolchains.sh index 6e3e284..e90e02a 100755 --- a/.claude/hooks/install-toolchains.sh +++ b/.claude/hooks/install-toolchains.sh @@ -1,21 +1,18 @@ #!/bin/bash +set -euo pipefail + # SessionStart hook — install the polyglot build toolchains for this repo. # # Claude Code on the web runs in an ephemeral container: anything installed # outside the cached project tree vanishes on restart. This hook reinstalls the -# toolchains the project depends on at the start of every session: -# * GNAT + gprbuild + GnuCOBOL (apt: gnat gprbuild gnucobol) -# * Pony (ponyc) via ponyup -# * Alire (alr) 2.1.1 (prebuilt release zip) +# toolchains the project depends on at the start of every session. # # Design rules: # * IDEMPOTENT — each tool is skipped if it is already on PATH (command -v). -# * NON-FATAL — a failed download/install must NOT break the session. We never -# run `set -e`; every step is guarded and the script always exits 0. -# * Warnings (not errors) are logged so failures are visible in the session log. +# * HARD FAIL — if an install fails, the session cannot build. Stop. -log() { echo "[install-toolchains] $*"; } -warn() { echo "[install-toolchains] WARNING: $*" >&2; } +log() { echo "[install-toolchains] $*"; } +die() { echo "[install-toolchains] FATAL: $*" >&2; exit 1; } export DEBIAN_FRONTEND=noninteractive @@ -26,9 +23,7 @@ if command -v gnatmake >/dev/null 2>&1 && command -v cobc >/dev/null 2>&1; then log "GNAT/gprbuild/GnuCOBOL already present; skipping apt install." else log "Installing gnat gprbuild gnucobol via apt-get ..." - if ! sudo apt-get install -y gnat gprbuild gnucobol; then - warn "apt-get install of gnat/gprbuild/gnucobol failed; continuing." - fi + sudo apt-get install -y gnat gprbuild gnucobol || die "apt-get install of gnat/gprbuild/gnucobol failed." fi # --------------------------------------------------------------------------- @@ -38,13 +33,8 @@ if command -v ponyc >/dev/null 2>&1; then log "ponyc already present; skipping ponyup install." else log "Installing ponyc via ponyup ..." - if sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)"; then - if ! /root/.local/share/ponyup/bin/ponyup update ponyc release; then - warn "ponyup update ponyc release failed; continuing." - fi - else - warn "ponyup-init.sh download/run failed; continuing." - fi + sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)" || die "ponyup-init.sh failed." + /root/.local/share/ponyup/bin/ponyup update ponyc release || die "ponyup update ponyc release failed." fi # --------------------------------------------------------------------------- @@ -54,15 +44,9 @@ if command -v alr >/dev/null 2>&1; then log "alr already present; skipping Alire install." else log "Installing Alire (alr) 2.1.1 ..." - if curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip; then - if ( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ); then - log "alr installed to /usr/local/bin/alr" - else - warn "Alire unzip/copy failed; continuing." - fi - else - warn "Alire download failed; continuing." - fi + curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip || die "Alire download failed." + ( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ) || die "Alire unzip/copy failed." + log "alr installed to /usr/local/bin/alr" fi # --------------------------------------------------------------------------- @@ -72,9 +56,7 @@ if command -v gfortran >/dev/null 2>&1; then log "gfortran already present; skipping." else log "Installing gfortran libopenblas-dev via apt-get ..." - if ! sudo apt-get install -y gfortran libopenblas-dev; then - warn "apt-get install of gfortran/libopenblas-dev failed; continuing." - fi + sudo apt-get install -y gfortran libopenblas-dev || die "apt-get install of gfortran/libopenblas-dev failed." fi # --------------------------------------------------------------------------- @@ -85,12 +67,9 @@ if command -v fpm >/dev/null 2>&1; then else log "Installing fpm ..." FPM_URL="https://github.com/fortran-lang/fpm/releases/download/v0.10.1/fpm-0.10.1-linux-x86_64" - if curl -sSL -o /tmp/fpm "$FPM_URL"; then - sudo cp /tmp/fpm /usr/local/bin/fpm && sudo chmod +x /usr/local/bin/fpm - log "fpm installed to /usr/local/bin/fpm" - else - warn "fpm download failed; continuing." - fi + curl -sSL -o /tmp/fpm "$FPM_URL" || die "fpm download failed." + sudo cp /tmp/fpm /usr/local/bin/fpm && sudo chmod +x /usr/local/bin/fpm || die "fpm install failed." + log "fpm installed to /usr/local/bin/fpm" fi # --------------------------------------------------------------------------- @@ -100,9 +79,7 @@ if command -v tclsh >/dev/null 2>&1; then log "tclsh already present; skipping." else log "Installing tcl via apt-get ..." - if ! sudo apt-get install -y tcl; then - warn "apt-get install of tcl failed; continuing." - fi + sudo apt-get install -y tcl || die "apt-get install of tcl failed." fi # --------------------------------------------------------------------------- @@ -113,15 +90,10 @@ if command -v eclipse >/dev/null 2>&1 || [ -x /opt/eclipseclp/bin/x86_64_linux/e else log "Installing ECLiPSe Prolog ..." ECLIPSE_URL="https://eclipseclp.org/Distribution/Current/7.1_13/x86_64_linux/eclipse_basic.tgz" - if curl -sSL -o /tmp/eclipse_basic.tgz "$ECLIPSE_URL"; then - if sudo mkdir -p /opt/eclipseclp && sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp; then - log "ECLiPSe installed to /opt/eclipseclp" - else - warn "ECLiPSe extraction failed; continuing." - fi - else - warn "ECLiPSe download failed; continuing." - fi + curl -sSL -o /tmp/eclipse_basic.tgz "$ECLIPSE_URL" || die "ECLiPSe download failed." + sudo mkdir -p /opt/eclipseclp || die "Could not create /opt/eclipseclp." + sudo tar -xzf /tmp/eclipse_basic.tgz -C /opt/eclipseclp || die "ECLiPSe extraction failed." + log "ECLiPSe installed to /opt/eclipseclp" fi # --------------------------------------------------------------------------- @@ -132,15 +104,10 @@ if command -v zig >/dev/null 2>&1; then else log "Installing Zig ..." ZIG_URL="https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz" - if curl -sSL -o /tmp/zig.tar.xz "$ZIG_URL"; then - if sudo tar -xJf /tmp/zig.tar.xz -C /opt && sudo ln -sf /opt/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig; then - log "zig installed to /usr/local/bin/zig" - else - warn "Zig extraction/linking failed; continuing." - fi - else - warn "Zig download failed; continuing." - fi + curl -sSL -o /tmp/zig.tar.xz "$ZIG_URL" || die "Zig download failed." + sudo tar -xJf /tmp/zig.tar.xz -C /opt || die "Zig extraction failed." + sudo ln -sf /opt/zig-linux-x86_64-0.13.0/zig /usr/local/bin/zig || die "Zig symlink failed." + log "zig installed to /usr/local/bin/zig" fi # --------------------------------------------------------------------------- @@ -150,30 +117,22 @@ if command -v forge >/dev/null 2>&1; then log "forge (Foundry) already present; skipping." else log "Installing Foundry (forge, anvil) ..." - if curl -sSL https://foundry.paradigm.xyz | bash; then - if "$HOME/.foundry/bin/foundryup"; then - log "Foundry installed" - else - warn "foundryup failed; continuing." - fi - else - warn "Foundry install script failed; continuing." - fi + curl -sSL https://foundry.paradigm.xyz | bash || die "Foundry install script failed." + "$HOME/.foundry/bin/foundryup" || die "foundryup failed." + log "Foundry installed" fi # --------------------------------------------------------------------------- -# Ensure ponyc is on PATH for future shells. +# PATH for tools not in standard locations. # --------------------------------------------------------------------------- EXTRA_PATHS='/root/.local/share/ponyup/bin:/opt/eclipseclp/bin/x86_64_linux' FOUNDRY_PATH="$HOME/.foundry/bin" FULL_PATH_LINE="export PATH=$EXTRA_PATHS:$FOUNDRY_PATH:\$PATH" if [ -f "$HOME/.bashrc" ] && grep -qF "eclipseclp" "$HOME/.bashrc"; then - log "Economy-organ PATH lines already in ~/.bashrc; skipping." + log "Toolchain PATH lines already in ~/.bashrc; skipping." else log "Appending toolchain PATH lines to ~/.bashrc" - echo "$FULL_PATH_LINE" >> "$HOME/.bashrc" || warn "Could not append to ~/.bashrc; continuing." + echo "$FULL_PATH_LINE" >> "$HOME/.bashrc" || die "Could not append to ~/.bashrc." fi log "Done." -# Never fail the session, regardless of what happened above. -exit 0