Skip to contentSkip to conversation

Force build failure if modules build fails

PATCH In review Mark McLoughlin 2 participants 2 messages Dec 20, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Force build failure if modules build fails

# HG changeset patch
# User Mark McLoughlin <[email protected]> # Date 1198143499 0
# Node ID 77d3a8ef20ffbd8275c4c7341b255e3049122ce4 # Parent f12da56acc577ac48a997c10480b220ec2a3d44d Force build failure if modules build fails

When building a linux kernel, if the modules build fails, then the build carries on regardless.

The problem is simple - the "make modules" failure is not seen by the calling make since its return value is not what is returned.

buildconfigs/mk.linux-2.6-common +1 -1
diff -r f12da56acc57 -r 77d3a8ef20ff buildconfigs/mk.linux-2.6-common
@@ -59,7 +59,7 @@ ifneq ($(XEN_LINUX_ALLOW_INTERFACE_MISMA
 	fi
 endif
 	if grep "^CONFIG_MODULES=" $(LINUX_DIR)/.config ; then \
-	    $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) modules ; \
+	    $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) modules || exit 1 ; \
 	    $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) INSTALL_MOD_PATH=$(DESTDIR) modules_install ; \
 	fi
 	$(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) INSTALL_PATH=$(DESTDIR) $(IMAGE_TARGET)
#1 lore raw

Mark McLoughlin writes ("[Xen-devel] [PATCH] Force build failure if modules build fails"):

Review

Quoted 3 lines
(quoted diff) +1 -1
 	if grep "^CONFIG_MODULES=" $(LINUX_DIR)/.config ; then \
-	    $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) modules ; \
+	    $(MAKE) -C $(LINUX_DIR) ARCH=$(LINUX_ARCH) modules || exit 1 ; \

Usually a better way to do this is to add `set -e' to the start of the multi-statement shell command, like this:

  -	if grep "^CONFIG_MODULES=" $(LINUX_DIR)/.config ; then \
  +	set -e; if grep "^CONFIG_MODULES=" $(LINUX_DIR)/.config ; then \

Doing it that way means you don't have to keep track of exactly which parts need || exit 1'. Best practice is to start any nontrivial command in a makefile with set -e'.

I've done some searching through the code and come up with the patch below which fixes a number of similar mistakes. I've only intended to change places where the code was definitely wrong, rather than the IMO much larger set of places where set -e would have been good style but is technically unnecessary.

I've also checked that at least `make all' still works.

Ian.

buildconfigs/mk.linux-2.6-common +1 -1
diff -r e2fa79c659e2 buildconfigs/mk.linux-2.6-common
@@ -103,7 +103,7 @@ ifneq ($(EXTRAVERSION),)
 	echo "$(EXTRAVERSION)" >$(LINUX_DIR)/localversion-xen
 endif
 	$(MAKE) -C $(LINUX_SRCDIR) ARCH=$(LINUX_ARCH) oldconfig O=$$(/bin/pwd)/$(LINUX_DIR)
-	@if [ ! -f $(LINUX_DIR)/Makefile ] ; then \
+	@set -e ; if [ ! -f $(LINUX_DIR)/Makefile ] ; then \
 	    echo "***********************************"; \
 	    echo "oldconfig did not create a Makefile"; \
 	    echo "Generating $(LINUX_DIR)/Makefile   "; \
buildconfigs/src.hg-clone +1 -1
diff -r e2fa79c659e2 buildconfigs/src.hg-clone
@@ -25,7 +25,7 @@ XEN_LINUX_HGREV  ?= tip
 	    echo "Pulling changes from $${__parent} into $(LINUX_SRCDIR)." ; \
 	    $(HG) -R $(LINUX_SRCDIR) pull $${__parent} ; \
 	fi
-	if [ -n "$(XEN_LINUX_HGREV)" ] ; then \
+	set -e ; if [ -n "$(XEN_LINUX_HGREV)" ] ; then \
 	    echo "Updating $(LINUX_SRCDIR) to revision $(XEN_LINUX_HGREV)." ; \
 	    ( cd $(LINUX_SRCDIR) && $(HG) update $(XEN_LINUX_HGREV) ); \
 	fi
docs/Makefile +1 -1
diff -r e2fa79c659e2 docs/Makefile
@@ -44,7 +44,7 @@ html:
 .PHONY: python-dev-docs
 python-dev-docs:
 	@mkdir -v -p api/tools/python
-	@if which $(DOXYGEN) 1>/dev/null 2>/dev/null; then         \
+	@set -e ; if which $(DOXYGEN) 1>/dev/null 2>/dev/null; then \
         echo "Running doxygen to generate Python tools APIs ... "; \
 	$(DOXYGEN) Doxyfile;                                       \
 	$(MAKE) -C api/tools/python/latex ; else                   \
tools/examples/Makefile +6 -7
diff -r e2fa79c659e2 tools/examples/Makefile
@@ -76,7 +76,7 @@ install-configs: $(XEN_CONFIGS)
 		$(INSTALL_DIR) $(DESTDIR)$(XEN_CONFIG_DIR)
 	[ -d $(DESTDIR)$(XEN_CONFIG_DIR)/auto ] || \
 		$(INSTALL_DIR) $(DESTDIR)$(XEN_CONFIG_DIR)/auto
-	for i in $(XEN_CONFIGS); \
+	set -e; for i in $(XEN_CONFIGS); \
 	    do [ -e $(DESTDIR)$(XEN_CONFIG_DIR)/$$i ] || \
 	    $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_CONFIG_DIR); \
 	done
@@ -85,11 +85,11 @@ install-scripts:
 install-scripts:
 	[ -d $(DESTDIR)$(XEN_SCRIPT_DIR) ] || \
 		$(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR)
-	for i in $(XEN_SCRIPTS); \
+	set -e; for i in $(XEN_SCRIPTS); \
 	    do \
 	    $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \
 	done
-	for i in $(XEN_SCRIPT_DATA); \
+	set -e; for i in $(XEN_SCRIPT_DATA); \
 	    do \
 	    $(INSTALL_DATA) $$i $(DESTDIR)$(XEN_SCRIPT_DIR); \
 	done
@@ -98,7 +98,7 @@ install-hotplug:
 install-hotplug:
 	[ -d $(DESTDIR)$(XEN_HOTPLUG_DIR) ] || \
 		$(INSTALL_DIR) $(DESTDIR)$(XEN_HOTPLUG_DIR)
-	for i in $(XEN_HOTPLUG_SCRIPTS); \
+	set -e; for i in $(XEN_HOTPLUG_SCRIPTS); \
 	    do \
 	    $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_HOTPLUG_DIR); \
 	done
@@ -107,11 +107,10 @@ install-udev:
 install-udev:
 	[ -d $(DESTDIR)$(UDEV_RULES_DIR) ] || \
 		$(INSTALL_DIR) $(DESTDIR)$(UDEV_RULES_DIR)/rules.d
-	for i in $(UDEV_RULES); \
+	set -e; for i in $(UDEV_RULES); \
 	    do \
 	    $(INSTALL_DATA) $$i $(DESTDIR)$(UDEV_RULES_DIR); \
-	    ( cd $(DESTDIR)$(UDEV_RULES_DIR)/rules.d ; \
-	        ln -sf ../$$i . ) \
+	    ln -sf ../$$i $(DESTDIR)$(UDEV_RULES_DIR)/rules.d; \
 	done
 
 .PHONY: clean
tools/firmware/rombios/32bit/Makefile +1 -1
diff -r e2fa79c659e2 tools/firmware/rombios/32bit/Makefile
@@ -19,7 +19,7 @@ MODULES = tcgbios/tcgbiosext.o
 .PHONY: all subdirs clean
 
 subdirs:
-	@for subdir in $(SUBDIRS); do \
+	@set -e; for subdir in $(SUBDIRS); do \
 		$(MAKE) -C $$subdir all; \
 	done;
 
tools/ioemu/Makefile +4 -4
diff -r e2fa79c659e2 tools/ioemu/Makefile
@@ -89,7 +89,7 @@ install: all $(if $(BUILD_DOCS),install-
 #	done
 ifndef CONFIG_WIN32
 	mkdir -p "$(DESTDIR)$(datadir)/keymaps"
-	for x in $(KEYMAPS); do \
+	set -e; for x in $(KEYMAPS); do \
 		$(INSTALL_DATA) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
 	done
 endif
@@ -140,12 +140,12 @@ tar:
 tar:
 	rm -rf /tmp/$(FILE)
 	cp -r . /tmp/$(FILE)
-	( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
+	cd /tmp && tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS
 	rm -rf /tmp/$(FILE)
 
 # generate a binary distribution
 tarbin:
-	( cd / ; tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
+	cd / && tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
 	$(bindir)/qemu \
 	$(bindir)/qemu-system-ppc \
 	$(bindir)/qemu-system-sparc \
@@ -173,7 +173,7 @@ tarbin:
         $(datadir)/pxe-pcnet.bin \
 	$(docdir)/qemu-doc.html \
 	$(docdir)/qemu-tech.html \
-	$(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1 )
+	$(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1
 
 ifneq ($(wildcard .depend),)
 include .depend
tools/ioemu/tests/Makefile +1 -1
diff -r e2fa79c659e2 tools/ioemu/tests/Makefile
@@ -91,7 +91,7 @@ hello-mipsel: hello-mips.c
 
 # XXX: find a way to compile easily a test for each arch
 test2:
-	@for arch in i386 arm armeb sparc ppc mips mipsel; do \
+	@set -e; for arch in i386 arm armeb sparc ppc mips mipsel; do \
            ../$${arch}-linux-user/qemu-$${arch} $${arch}/ls -l linux-test.c ; \
         done
 
tools/libaio/Makefile +2 -2
diff -r e2fa79c659e2 tools/libaio/Makefile
@@ -25,9 +25,9 @@ tag-archive:
 
 create-archive: tag-archive
 	@rm -rf /tmp/$(NAME)
-	@cd /tmp; cvs -Q -d $(CVSROOT) export -r$(CVSTAG) $(NAME) || echo GRRRrrrrr -- ignore [export aborted]
+	@cd /tmp && cvs -Q -d $(CVSROOT) export -r$(CVSTAG) $(NAME) || echo GRRRrrrrr -- ignore [export aborted]
 	@mv /tmp/$(NAME) /tmp/$(NAME)-$(VERSION)
-	@cd /tmp; tar czSpf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
+	@cd /tmp && tar czSpf $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
 	@rm -rf /tmp/$(NAME)-$(VERSION)
 	@cp /tmp/$(NAME)-$(VERSION).tar.gz .
 	@rm -f /tmp/$(NAME)-$(VERSION).tar.gz 
tools/libxen/Makefile +1 -1
diff -r e2fa79c659e2 tools/libxen/Makefile
@@ -61,7 +61,7 @@ install: all
 	ln -sf libxenapi.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxenapi.so.$(MAJOR)
 	ln -sf libxenapi.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenapi.so
 	$(INSTALL_DATA) libxenapi.a $(DESTDIR)/usr/$(LIBDIR)
-	for i in $(LIBXENAPI_HDRS); do \
+	set -e; for i in $(LIBXENAPI_HDRS); do \
 	    $(INSTALL_DATA) $$i $(DESTDIR)/usr/include/xen/api; \
 	done
 
tools/libxen/Makefile.dist +1 -1
diff -r e2fa79c659e2 tools/libxen/Makefile.dist
@@ -71,7 +71,7 @@ install: all
 	ln -sf libxenapi.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxenapi.so.$(MAJOR)
 	ln -sf libxenapi.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenapi.so
 	$(INSTALL_DATA) libxenapi.a $(DESTDIR)/usr/$(LIBDIR)
-	for i in $(LIBXENAPI_HDRS); do \
+	set -e; for i in $(LIBXENAPI_HDRS); do \
 	    $(INSTALL_DATA) $$i $(DESTDIR)/usr/include/xen/api; \
 	done
 
tools/python/Makefile +3 -3
diff -r e2fa79c659e2 tools/python/Makefile
@@ -40,7 +40,7 @@ refresh-pot: $(I18NSRCFILES)
 		$(I18NSRCFILES)
 	sed -f remove-potcdate.sed < $(POTFILE) > $(POTFILE)-1
 	sed -f remove-potcdate.sed < $(POTFILE)-tmp > $(POTFILE)-2
-	if cmp -s $(POTFILE)-1 $(POTFILE)-2; then \
+	set -e; if cmp -s $(POTFILE)-1 $(POTFILE)-2; then \
 		rm -f $(POTFILE)-tmp $(POTFILE)-1 $(POTFILE)-2; \
 	else \
 		mv $(POTFILE)-tmp $(POTFILE); \
@@ -48,7 +48,7 @@ refresh-pot: $(I18NSRCFILES)
 	fi
 
 refresh-po: $(POTFILE)
-	for l in $(LINGUAS); do \
+	set -e; for l in $(LINGUAS); do \
 		if $(MSGMERGE) $(PODIR)/$$l.po $(POTFILE) > $(PODIR)/$$l-tmp ; then \
 			mv -f $(PODIR)/$$l-tmp $(PODIR)/$$l.po ; \
 			echo "$(MSGMERGE) of $$l.po succeeded" ; \
@@ -88,7 +88,7 @@ install-dtd: all
 	$(INSTALL_DATA) xen/xm/create.dtd $(DESTDIR)/usr/share/xen
 
 install-messages: all
-	if which $(MSGFMT) >/dev/null ; then \
+	set -e; if which $(MSGFMT) >/dev/null ; then \
 		mkdir -p $(DESTDIR)$(NLSDIR); \
 		for l in $(LINGUAS); do \
 			$(INSTALL_DIR) $(DESTDIR)$(NLSDIR)/$$l; \
tools/security/Makefile +2 -2
diff -r e2fa79c659e2 tools/security/Makefile
@@ -51,10 +51,10 @@ install: all $(ACM_CONFIG_FILE)
 	$(INSTALL_DIR) $(DESTDIR)$(ACM_POLICY_DIR)
 	$(INSTALL_DATA) policies/$(ACM_SCHEMA) $(DESTDIR)$(ACM_POLICY_DIR)
 	$(INSTALL_DIR) $(DESTDIR)$(ACM_POLICY_DIR)/example
-	for i in $(ACM_EXAMPLES); do \
+	set -e; for i in $(ACM_EXAMPLES); do \
 		$(INSTALL_DATA) policies/example/$$i-$(ACM_POLICY_SUFFIX) $(DESTDIR)$(ACM_POLICY_DIR)/example/; \
 	done
-	for i in $(ACM_DEF_POLICIES); do \
+	set -e; for i in $(ACM_DEF_POLICIES); do \
 		$(INSTALL_DATA) policies/$$i-$(ACM_POLICY_SUFFIX) $(DESTDIR)$(ACM_POLICY_DIR); \
 	done
 	$(INSTALL_DIR) $(DESTDIR)$(ACM_SCRIPT_DIR)
tools/vtpm/Makefile +7 -7
diff -r e2fa79c659e2 tools/vtpm/Makefile
@@ -49,7 +49,7 @@ mrproper:
 # Create vtpm and TPM emulator dirs
 # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance
 $(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch 
-	if [ "$(BUILD_EMULATOR)" = "y" ]; then \
+	set -e; if [ "$(BUILD_EMULATOR)" = "y" ]; then \
 		rm -rf $(TPM_EMULATOR_DIR); \
 		tar -xzf $(TPM_EMULATOR_TARFILE); \
 		mv $(TPM_EMULATOR_NAME) $(TPM_EMULATOR_DIR); \
@@ -59,20 +59,20 @@ mrproper:
 
 $(VTPM_DIR): $(TPM_EMULATOR_TARFILE) vtpm.patch
 	rm -rf $(VTPM_DIR)
-	tar -xzf $(TPM_EMULATOR_TARFILE);  
-	mv $(TPM_EMULATOR_NAME) $(VTPM_DIR); 
+	tar -xzf $(TPM_EMULATOR_TARFILE)
+	mv $(TPM_EMULATOR_NAME) $(VTPM_DIR)
 
-	cd $(VTPM_DIR); \
+	set -e; cd $(VTPM_DIR); \
 	patch -p1 < ../tpm_emulator.patch; \
 	patch -p1 < ../vtpm.patch
 
 orig: $(TPM_EMULATOR_TARFILE)
 	mkdir $(ORIG_DIR);
-	cd $(ORIG_DIR); \
+	set -e; cd $(ORIG_DIR); \
 	tar -xzf ../$(TPM_EMULATOR_TARFILE);
 
 updatepatches: clean orig
-	if [ "$(BUILD_EMULATOR)" = "y" ]; then \
+	set -e; if [ "$(BUILD_EMULATOR)" = "y" ]; then \
 		find $(TPM_EMULATOR_DIR) -name "*.orig" -print | xargs rm -f; \
 		mv tpm_emulator.patch tpm_emulator.patch.old; \
 		diff -uprN orig/$(TPM_EMULATOR_NAME) $(TPM_EMULATOR_DIR) > tpm_emulator.patch || true; \
@@ -83,7 +83,7 @@ updatepatches: clean orig
 
 .PHONY: build_sub
 build_sub:
-	@if [ -e $(GMP_HEADER) ]; then \
+	set -e; @if [ -e $(GMP_HEADER) ]; then \
 		$(MAKE) -C $(VTPM_DIR); \
 		if [ "$(BUILD_EMULATOR)" = "y" ]; then \
 			$(MAKE) -C $(TPM_EMULATOR_DIR); \
tools/xm-test/ramdisk/Makefile.am +4 -4
diff -r e2fa79c659e2 tools/xm-test/ramdisk/Makefile.am
@@ -59,8 +59,8 @@ endif
 	cp configs/buildroot-$(BR_ARCH) $(BR_SRC)/.config
 	cp configs/busybox $(BR_SRC)/package/busybox/busybox.config
 	cp configs/uClibc $(BR_SRC)/toolchain/uClibc/uClibc.config
-	(for i in patches/buildroot/*.patch; do \
-	  cd $(BR_SRC) && patch -p1 <../$$i && cd ..; done )
+	set -e; for i in patches/buildroot/*.patch; do \
+	  cd $(BR_SRC) && patch -p1 <../$$i && cd ..; done
 	cd $(BR_SRC) && make oldconfig && make
 
 $(XMTEST_VER_IMG): $(BR_IMG)
@@ -69,8 +69,8 @@ endif
 	-[ -e "$(BLKDRV)" ] && cp $(BLKDRV) skel/modules
 	-[ -e "$(NETDRV)" ] && cp $(NETDRV) skel/modules
 	-[ -e "$(PKTDRV)" ] && cp $(PKTDRV) skel/modules
-	(cd skel; tar cf - .) \
-		| (cd $(BR_SRC)/$(BR_ROOT); tar xvf -)
+	(cd skel && tar cf - .) \
+		| (cd $(BR_SRC)/$(BR_ROOT) && tar xvf -)
 	cd $(BR_SRC) && make
 	cp $(BR_IMG) $(XMTEST_VER_IMG)
 
xen/Makefile +2 -2
diff -r e2fa79c659e2 xen/Makefile
@@ -141,13 +141,13 @@ endef
 
 .PHONY: _TAGS
 _TAGS: 
-	rm -f TAGS; \
+	set -e; rm -f TAGS; \
 	$(call set_exuberant_flags,etags); \
 	$(all_sources) | xargs etags $$exuberant_flags -a
 
 .PHONY: _tags
 _tags: 
-	rm -f tags; \
+	set -e; rm -f tags; \
 	$(call set_exuberant_flags,ctags); \
 	$(all_sources) | xargs ctags $$exuberant_flags -a
 
xen/include/Makefile +1 -1
diff -r e2fa79c659e2 xen/include/Makefile
@@ -37,7 +37,7 @@ all: $(headers-y)
 all: $(headers-y)
 
 compat/%.h: compat/%.i Makefile
-	id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
+	set -e; id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
 	echo "#ifndef $$id" >[email protected]; \
 	echo "#define $$id" >>[email protected]; \
 	echo "#include <xen/compat.h>" >>[email protected]; \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel