From 6cc5978540893f5d33596d9f9f14b34c84529f7e Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Wed, 19 Nov 2025 11:28:02 +0000 Subject: [PATCH] Harden the error handling of shell commands Run all shell commands from the build system with -e (abort on any error), -u (abort on undefined variables) and, when available, -o pipefail (abort if any process in a pipeline exits with non-zero status) --- Makefile | 2 ++ doc/Makefile | 2 ++ release/Makefile | 2 ++ src_ext/Makefile | 2 ++ 4 files changed, 8 insertions(+) diff --git a/Makefile b/Makefile index d9280b0adfd..4ff375fb597 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.SHELLFLAGS := -eu$(if $(shell (set -o pipefail 2>/dev/null && echo yes)),o pipefail) $(.SHELLFLAGS) + ifeq ($(filter distclean clean,$(MAKECMDGOALS)),) -include Makefile.config endif diff --git a/doc/Makefile b/doc/Makefile index 5c7d59110f9..30d45e6ca0b 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,3 +1,5 @@ +.SHELLFLAGS := -eu$(if $(shell (set -o pipefail 2>/dev/null && echo yes)),o pipefail) $(.SHELLFLAGS) + -include ../Makefile.config ifeq ($(DUNE),) diff --git a/release/Makefile b/release/Makefile index 36e32b3c376..bdd5a2bdceb 100644 --- a/release/Makefile +++ b/release/Makefile @@ -1,3 +1,5 @@ +.SHELLFLAGS := -eu$(if $(shell (set -o pipefail 2>/dev/null && echo yes)),o pipefail) $(.SHELLFLAGS) + TAG = master VERSION = $(shell git describe $(TAG)) OPAM_VERSION = $(subst -,~,$(VERSION)) diff --git a/src_ext/Makefile b/src_ext/Makefile index 0c2fe7b3b67..438f67fa32d 100644 --- a/src_ext/Makefile +++ b/src_ext/Makefile @@ -1,3 +1,5 @@ +.SHELLFLAGS := -eu$(if $(shell (set -o pipefail 2>/dev/null && echo yes)),o pipefail) $(.SHELLFLAGS) + ifneq ($(wildcard ../Makefile.config)$(filter-out archives cache-archives,$(MAKECMDGOALS)),) -include ../Makefile.config endif