◐ Shell
clean mode source ↗

gh-100220: Fix error handling in make rules by mgorny · Pull Request #100328 · python/cpython

@bedevere-bot mentioned this pull request

Dec 18, 2022
Use `set -e` before compound shell commands in order to ensure that make
targets fail correctly when at least one of the subcommands fail.

This is necessary since make considers a target failed only if one of
the shell invocations returns with unsuccessful exit status.  If a shell
script does not exit explicitly, the shell uses the exit status
of the *last* executed command.  This means that when multiple commands
are executed (e.g. through a `for` loop), the exit statuses of prior
command invocations are ignored.

This can be either resolved by adding an explicit `|| exit 1` to every
command that is expected to succeed, or by running the whole script
with `set -e`.  The latter was used here as it the rules seem to be
written with the assumption that individual commands were supposed
to cause the make rules to fail.
Instead of setting `set -e` per target, add it to the definition
of `SHELL` to force it globally.  This was suggested by Zachary Ware.

@arhadthedev

zware

@mgorny mgorny deleted the make-fail-100220 branch

April 8, 2023 05:14

warsaw pushed a commit to warsaw/cpython that referenced this pull request

Apr 11, 2023
Set `SHELL = /bin/sh -e` to ensure that complex recipes fail on the first error rather than incorrectly reporting success.

Co-authored-by: Zachary Ware <zach@python.org>

@zware zware mentioned this pull request

Apr 24, 2023