Whamcloud - gitweb
LU-1016 build: no sub-builds in sub-shells
authorBruce Korb <bruce_korb@xyratex.com>
Mon, 12 Mar 2012 23:54:49 +0000 (16:54 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 9 Apr 2012 20:58:43 +0000 (16:58 -0400)
The make program paradigm is to have command failures fail the make.
Invoking a failing "make" in a subshell will cause the subshell
to exit returning non-zero to the invoking shell.  However, the
invoking shell will *NOT* exit.  Therefore, to correctly use a
subshell in a make file scriptlet, use the following template:

  ( do-some-stuff ) || false

this will work as expected.  You want "false" instead of "exit 1"
in case make as been invoked with the "-i" ("--ignore-errors")
option.

WRT the code in question, there really is no need of even using
a subshell.  So this patch fixes two (related) things:

1.  the "for subdir in $(RPM_SUBDIR)" is now done in one process
    and will cause the superior make to stop if any subdirectory
    make fails.

2.  The tests for BUILD_TESTS and BUILD_SERVER for building RPMs
    need to take into account the possibility that these are not
    necessarily defined in all autoMakefile.am's that use the
    autoMakefile.am.toplevel file.

Signed-off-by: Bruce Korb <bruce_korb@xyratex.com>
Xyratex-bug-id: MRP-361
Change-Id: Icbfd453d42a69a2b65d66677e02d89f746533121
Reviewed-on: http://review.whamcloud.com/2012
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Minh Diep <mdiep@whamcloud.com>
Reviewed-by: Brian J. Murrell <brian@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
build/autoMakefile.am.toplevel

index 3b1c706..9ae93da 100644 (file)
@@ -1,3 +1,4 @@
+# -*- Makefile -*-
 # This file is included by each package's toplevel autoMakefile[.am],
 # which must define SUBDIRS as a minimum.
 
@@ -7,6 +8,15 @@ FIND_TAG_FILES_CMD = find $(top_srcdir) \
                     -path $(top_srcdir)/ldiskfs/ldiskfs/linux-stage -prune -false -o\
                     -type f -name '*.[hc]'
 
+MAKEEACHSUBDIR =                                       \
+       for subdir in $(RPM_SUBDIRS) ; do               \
+               echo "Making $@ in $$subdir" ;          \
+               cd $$subdir ;                           \
+               $(MAKE) $(AM_MAKEFLAGS) $@ ;            \
+               cd - ;                                  \
+               echo "Finished $@ in $$subdir" ;        \
+       done
+
 # these empty rules are needed so that automake doesn't add its own
 # recursive rules
 etags-recursive:
@@ -105,46 +115,42 @@ EXTRA_DIST = @PACKAGE_TARNAME@.spec                                       \
        build/funcs.sh build/find_linux_rpms build/exit_traps.sh
 
 rpms-real: @PACKAGE_TARNAME@.spec dist Makefile
-       CONFIGURE_ARGS=$$(echo $$(eval echo $(ac_configure_args)) | sed -re 's/--(en|dis)able-tests//'); \
+       CONFIGURE_ARGS=$$(echo $$(eval echo $(ac_configure_args)) | \
+               sed -re 's/--(en|dis)able-tests//'); \
        if [ -n "@LINUX@" ]; then \
-               CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-linux=[^ ][^ ]*//'); \
+               CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | \
+                       sed -re 's/--with-linux=[^ ][^ ]*//'); \
                RPMARGS="--define \"kdir @LINUX@\""; \
-               CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-linux-obj=[^ ][^ ]*//'); \
+               CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | \
+                       sed -re 's/--with-linux-obj=[^ ][^ ]*//'); \
                if [ -n "@LINUX_OBJ@" -a "@LINUX_OBJ@" != "@LINUX@" ]; then \
                        RPMARGS="$$RPMARGS --define \"kobjdir @LINUX_OBJ@\""; \
                fi; \
        fi; \
-       CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-release=[^ ][^ ]*//'); \
+       CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | \
+               sed -re 's/--with-release=[^ ][^ ]*//'); \
        RPMARGS="$$RPMARGS --define \"configure_args $$CONFIGURE_ARGS\""; \
-       if ! $(BUILD_TESTS); then \
+       if [[ "X$(BUILD_TESTS)" = Xfalse ]]; then \
                RPMARGS="$$RPMARGS --define \"build_lustre_tests 0\""; \
        fi; \
-       if ! $(BUILD_SERVER); then \
+       if [[ "X$(BUILD_SERVER)" = Xfalse ]]; then \
                RPMARGS="$$RPMARGS --define \"lustre_name lustre-client\""; \
        fi; \
        echo "Building Lustre RPM with $$RPMARGS"; \
        eval rpmbuild $$RPMARGS -ta $(distdir).tar.gz
 
 srpm-real: @PACKAGE_TARNAME@.spec dist Makefile
-       if ! $(BUILD_TESTS); then \
+       if [[ "X$(BUILD_TESTS)" = Xfalse ]]; then \
                RPMARGS="--define \"build_lustre_tests 0\""; \
        fi; \
        eval rpmbuild $$RPMARGS -ta $(distdir).tar.gz
 
 rpms:
-       for subdir in $(RPM_SUBDIRS) ; do                               \
-               echo "Making rpms in $$subdir";                         \
-               (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) rpms);          \
-               echo "Finished rpms in $$subdir";                       \
-       done;                                                           \
+       @$(MAKEEACHSUBDIR)
        $(MAKE) $(AM_MAKEFLAGS) rpms-real
 
 srpm:
-       for subdir in $(RPM_SUBDIRS) ; do                               \
-               echo "Making srpm in $$subdir";                         \
-               (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) srpm);          \
-               echo "Finished srpms in $$subdir";                      \
-       done;                                                           \
+       @$(MAKEEACHSUBDIR)
        $(MAKE) $(AM_MAKEFLAGS) srpm-real
 
 # In the debs target, first make sure what's in the changelog reflects