Skip to content

Commit 6c05684

Browse files
committed
gh-100220: Fix error handling in make rules
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.
1 parent 244d4cd commit 6c05684

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

Makefile.pre.in

+39-19
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ $(LIBRARY): $(LIBRARY_OBJS)
738738
$(AR) $(ARFLAGS) $@ $(LIBRARY_OBJS)
739739

740740
libpython$(LDVERSION).so: $(LIBRARY_OBJS) $(DTRACE_OBJS)
741+
set -e; \
741742
if test $(INSTSONAME) != $(LDLIBRARY); then \
742743
$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM); \
743744
$(LN) -f $(INSTSONAME) $@; \
@@ -894,7 +895,8 @@ $(LIBEXPAT_A): $(LIBEXPAT_OBJS)
894895
# pybuilddir.txt is created too late. We cannot use it in Makefile
895896
# targets. ln --relative is not portable.
896897
sharedmods: $(SHAREDMODS) pybuilddir.txt
897-
@target=`cat pybuilddir.txt`; \
898+
@set -e; \
899+
target=`cat pybuilddir.txt`; \
898900
$(MKDIR_P) $$target; \
899901
for mod in X $(SHAREDMODS); do \
900902
if test $$mod != X; then \
@@ -907,7 +909,8 @@ checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
907909
@$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/build/check_extension_modules.py
908910

909911
rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
910-
@if [ ! -z $(DSYMUTIL) ] ; then \
912+
@set -e; \
913+
if [ ! -z $(DSYMUTIL) ] ; then \
911914
echo $(DSYMUTIL_PATH) $(BUILDPYTHON); \
912915
$(DSYMUTIL_PATH) $(BUILDPYTHON); \
913916
if test -f $(LDLIBRARY); then \
@@ -1814,15 +1817,17 @@ commoninstall: check-clean-src @FRAMEWORKALTINSTALLFIRST@ \
18141817
DESTDIRS= $(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED)
18151818

18161819
sharedinstall: all
1817-
@for i in $(DESTDIRS); \
1820+
@set -e; \
1821+
for i in $(DESTDIRS); \
18181822
do \
18191823
if test ! -d $(DESTDIR)$$i; then \
18201824
echo "Creating directory $$i"; \
18211825
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
18221826
else true; \
18231827
fi; \
18241828
done
1825-
@for i in X $(SHAREDMODS); do \
1829+
@set -e; \
1830+
for i in X $(SHAREDMODS); do \
18261831
if test $$i != X; then \
18271832
echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
18281833
$(INSTALL_SHARED) $$i $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
@@ -1836,7 +1841,8 @@ sharedinstall: all
18361841
# Install the interpreter with $(VERSION) affixed
18371842
# This goes into $(exec_prefix)
18381843
altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
1839-
@for i in $(BINDIR) $(LIBDIR); \
1844+
@set -e; \
1845+
for i in $(BINDIR) $(LIBDIR); \
18401846
do \
18411847
if test ! -d $(DESTDIR)$$i; then \
18421848
echo "Creating directory $$i"; \
@@ -1855,7 +1861,8 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
18551861
fi; \
18561862
(cd $(DESTDIR)$(BINDIR); $(LN) python$(LDVERSION)$(EXE) python$(VERSION)$(EXE)); \
18571863
fi
1858-
@if test "$(PY_ENABLE_SHARED)" = 1 -o "$(STATIC_LIBPYTHON)" = 1; then \
1864+
@set -e; \
1865+
if test "$(PY_ENABLE_SHARED)" = 1 -o "$(STATIC_LIBPYTHON)" = 1; then \
18591866
if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
18601867
if test -n "$(DLLLIBRARY)" ; then \
18611868
$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
@@ -1942,7 +1949,8 @@ bininstall: altbininstall
19421949

19431950
# Install the versioned manual page
19441951
altmaninstall:
1945-
@for i in $(MANDIR) $(MANDIR)/man1; \
1952+
@set -e; \
1953+
for i in $(MANDIR) $(MANDIR)/man1; \
19461954
do \
19471955
if test ! -d $(DESTDIR)$$i; then \
19481956
echo "Creating directory $$i"; \
@@ -2077,15 +2085,17 @@ COMPILEALL_OPTS=-j0
20772085

20782086
TEST_MODULES=@TEST_MODULES@
20792087
libinstall: all $(srcdir)/Modules/xxmodule.c
2080-
@for i in $(SCRIPTDIR) $(LIBDEST); \
2088+
@set -e; \
2089+
for i in $(SCRIPTDIR) $(LIBDEST); \
20812090
do \
20822091
if test ! -d $(DESTDIR)$$i; then \
20832092
echo "Creating directory $$i"; \
20842093
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
20852094
else true; \
20862095
fi; \
20872096
done
2088-
@if test "$(TEST_MODULES)" = yes; then \
2097+
@set -e; \
2098+
if test "$(TEST_MODULES)" = yes; then \
20892099
subdirs="$(LIBSUBDIRS) $(TESTSUBDIRS)"; \
20902100
else \
20912101
subdirs="$(LIBSUBDIRS)"; \
@@ -2101,7 +2111,8 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
21012111
else true; \
21022112
fi; \
21032113
done
2104-
@for i in $(srcdir)/Lib/*.py; \
2114+
@set -e; \
2115+
for i in $(srcdir)/Lib/*.py; \
21052116
do \
21062117
if test -x $$i; then \
21072118
$(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \
@@ -2111,7 +2122,8 @@ libinstall: all $(srcdir)/Modules/xxmodule.c
21112122
echo $(INSTALL_DATA) $$i $(LIBDEST); \
21122123
fi; \
21132124
done
2114-
@if test "$(TEST_MODULES)" = yes; then \
2125+
@set -e; \
2126+
if test "$(TEST_MODULES)" = yes; then \
21152127
subdirs="$(LIBSUBDIRS) $(TESTSUBDIRS)"; \
21162128
else \
21172129
subdirs="$(LIBSUBDIRS)"; \
@@ -2201,7 +2213,8 @@ scripts: $(SCRIPT_2TO3) $(SCRIPT_IDLE) $(SCRIPT_PYDOC) python-config
22012213
# Install the include files
22022214
INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
22032215
inclinstall:
2204-
@for i in $(INCLDIRSTOMAKE); \
2216+
@set -e; \
2217+
for i in $(INCLDIRSTOMAKE); \
22052218
do \
22062219
if test ! -d $(DESTDIR)$$i; then \
22072220
echo "Creating directory $$i"; \
@@ -2219,17 +2232,20 @@ inclinstall:
22192232
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(INCLUDEPY)/internal; \
22202233
else true; \
22212234
fi
2222-
@for i in $(srcdir)/Include/*.h; \
2235+
@set -e; \
2236+
for i in $(srcdir)/Include/*.h; \
22232237
do \
22242238
echo $(INSTALL_DATA) $$i $(INCLUDEPY); \
22252239
$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY); \
22262240
done
2227-
@for i in $(srcdir)/Include/cpython/*.h; \
2241+
@set -e; \
2242+
for i in $(srcdir)/Include/cpython/*.h; \
22282243
do \
22292244
echo $(INSTALL_DATA) $$i $(INCLUDEPY)/cpython; \
22302245
$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY)/cpython; \
22312246
done
2232-
@for i in $(srcdir)/Include/internal/*.h; \
2247+
@set -e; \
2248+
for i in $(srcdir)/Include/internal/*.h; \
22332249
do \
22342250
echo $(INSTALL_DATA) $$i $(INCLUDEPY)/internal; \
22352251
$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY)/internal; \
@@ -2244,15 +2260,17 @@ LIBPL= @LIBPL@
22442260
LIBPC= $(LIBDIR)/pkgconfig
22452261

22462262
libainstall: all scripts
2247-
@for i in $(LIBDIR) $(LIBPL) $(LIBPC) $(BINDIR); \
2263+
@set -e; \
2264+
for i in $(LIBDIR) $(LIBPL) $(LIBPC) $(BINDIR); \
22482265
do \
22492266
if test ! -d $(DESTDIR)$$i; then \
22502267
echo "Creating directory $$i"; \
22512268
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
22522269
else true; \
22532270
fi; \
22542271
done
2255-
@if test "$(STATIC_LIBPYTHON)" = 1; then \
2272+
@set -e; \
2273+
if test "$(STATIC_LIBPYTHON)" = 1; then \
22562274
if test -d $(LIBRARY); then :; else \
22572275
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
22582276
if test "$(SHLIB_SUFFIX)" = .dll; then \
@@ -2282,7 +2300,8 @@ libainstall: all scripts
22822300
$(INSTALL_SCRIPT) $(SCRIPT_2TO3) $(DESTDIR)$(BINDIR)/2to3-$(VERSION)
22832301
$(INSTALL_SCRIPT) $(SCRIPT_IDLE) $(DESTDIR)$(BINDIR)/idle$(VERSION)
22842302
$(INSTALL_SCRIPT) $(SCRIPT_PYDOC) $(DESTDIR)$(BINDIR)/pydoc$(VERSION)
2285-
@if [ -s Modules/python.exp -a \
2303+
@set -e; \
2304+
if [ -s Modules/python.exp -a \
22862305
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
22872306
echo; echo "Installing support files for building shared extension modules on AIX:"; \
22882307
$(INSTALL_DATA) Modules/python.exp \
@@ -2322,7 +2341,8 @@ frameworkinstallstructure: $(LDLIBRARY)
23222341
exit 1; \
23232342
else true; \
23242343
fi
2325-
@for i in $(prefix)/Resources/English.lproj $(prefix)/lib; do\
2344+
@set -e; \
2345+
for i in $(prefix)/Resources/English.lproj $(prefix)/lib; do\
23262346
if test ! -d $(DESTDIR)$$i; then \
23272347
echo "Creating directory $(DESTDIR)$$i"; \
23282348
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error handling in compound Make rules that lead to the install targets
2+
succeeding when the respective files were not installed.

0 commit comments

Comments
 (0)