build(Makefile): capture pre-commit output to log files (#22978)

pre-commit was noisy: every sub-target dumped full stdout/stderr to the
terminal, burying failures in pages of compiler output and lint details.

Teach timed-shell.sh a quiet mode via MAKE_LOGDIR: when set, recipe
output is redirected to per-target log files and a one-line status is
printed instead. When unset, behavior is unchanged (with a refreshed
output format).

Makefile changes:

- pre-commit creates a tmpdir, passes MAKE_LOGDIR to sub-makes
- Drop --output-sync=target (log files eliminate interleaving)
- Add --no-print-directory to suppress Entering/Leaving noise
- Split check-unstaged and check-untracked into separate defines
- Restyle both with colored indicators and clearer instructions
- Clean up tmpdir on success, preserve on failure for debugging
This commit is contained in:
Mathias Fredriksson
2026-03-12 11:16:31 +02:00
committed by GitHub
parent 5130404f2a
commit e7e2de99ba
2 changed files with 43 additions and 19 deletions
+18 -6
View File
@@ -8,6 +8,9 @@
# SHELL := $(CURDIR)/scripts/lib/timed-shell.sh
# .SHELLFLAGS = $@ -ceu
#
# When MAKE_LOGDIR is set, recipe output is captured to a log file.
# Otherwise output goes to stdout/stderr as normal.
#
# $(shell ...) uses SHELL but passes -c directly, not .SHELLFLAGS.
# Detect this and delegate to bash without timing output.
if [[ $1 == -* ]]; then
@@ -19,23 +22,32 @@ set -eu
target=$1
shift
bold=$(tput bold 2>/dev/null) || true
dim=$(tput dim 2>/dev/null) || dim=$(tput setaf 8 2>/dev/null) || true
green=$(tput setaf 2 2>/dev/null) || true
red=$(tput setaf 1 2>/dev/null) || true
reset=$(tput sgr0 2>/dev/null) || true
start=$(date +%s)
echo "${bold}==> ${target}${reset}"
set +e
bash "$@"
if [[ -n ${MAKE_LOGDIR:-} ]]; then
logfile="${MAKE_LOGDIR}/${target//\//-}.log"
bash "$@" >"$logfile" 2>&1
else
printf '%s○%s %s\n' "$dim" "$reset" "$target"
bash "$@"
fi
rc=$?
set -e
elapsed=$(($(date +%s) - start))
if ((rc == 0)); then
echo "${bold}${green}==> ${target} completed in ${elapsed}s${reset}"
printf '%s✓%s %s (%ds)\n' "$green" "$reset" "$target" "$elapsed"
else
echo "${bold}${red}==> ${target} FAILED after ${elapsed}s${reset}" >&2
exit $rc
if [[ -n ${MAKE_LOGDIR:-} ]]; then
printf '%s✗%s %s (%ds) → %s\n' "$red" "$reset" "$target" "$elapsed" "$logfile"
else
printf '%s✗%s %s (%ds)\n' "$red" "$reset" "$target" "$elapsed"
fi
exit "$rc"
fi