UBUNTU: debian: add locking to protect debian/files from parallel update
authorAndy Whitcroft <apw@canonical.com>
Wed, 26 Oct 2011 14:07:28 +0000 (15:07 +0100)
committerLeann Ogasawara <leann.ogasawara@canonical.com>
Mon, 2 Apr 2012 20:12:42 +0000 (13:12 -0700)
When building with high parallelism we may overlap calls to dh_gencontrol
and/or the .ddeb removal code from the debian/files list.  If these happen
in parallel files may be lost or updates fail leading to build failures or
incomplete packing lists.  Add primative locking to each of these scenarios
using the flock command, utilising a lock file in the debian directory.

Signed-off-by: Andy Whitcroft <apw@canonical.com>

debian.master/control.stub.in
debian/rules.d/0-common-vars.mk
debian/rules.d/2-binary-arch.mk
debian/rules.d/3-binary-indep.mk
debian/rules.d/5-udebs.mk

index ad433e2..84dd89b 100644 (file)
@@ -3,7 +3,7 @@ Section: devel
 Priority: optional
 Maintainer: Ubuntu Kernel Team <kernel-team@lists.ubuntu.com>
 Standards-Version: 3.8.4.0
-Build-Depends: debhelper (>= 5), cpio, module-init-tools, kernel-wedge (>= 2.24ubuntu1), makedumpfile [amd64 i386], device-tree-compiler [powerpc], libelf-dev, binutils-dev, rsync, libdw-dev, dpkg (>= 1.16.0~ubuntu4)
+Build-Depends: debhelper (>= 5), cpio, module-init-tools, kernel-wedge (>= 2.24ubuntu1), makedumpfile [amd64 i386], device-tree-compiler [powerpc], libelf-dev, binutils-dev, rsync, libdw-dev, dpkg (>= 1.16.0~ubuntu4), util-linux
 Build-Depends-Indep: xmlto, docbook-utils, ghostscript, transfig, bzip2, sharutils, asciidoc
 Build-Conflicts: findutils (= 4.4.1-1ubuntu1)
 Vcs-Git: http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-precise.git
index 8915c40..9022d53 100644 (file)
@@ -220,3 +220,8 @@ ifneq ($(LOCAL_ENV_CC),)
 kmake += CC=$(LOCAL_ENV_CC) DISTCC_HOSTS=$(LOCAL_ENV_DISTCC_HOSTS)
 endif
 
+# Locking is required in parallel builds to prevent loss of contents
+# of the debian/files.
+lockme_file = $(CURDIR)/debian/.LOCK
+lockme_cmd = flock -w 60
+lockme = $(lockme_cmd) $(lockme_file)
index 7a42734..dec5adc 100644 (file)
@@ -268,7 +268,7 @@ endif
        dh_compress -plinux-libc-dev
        dh_fixperms -plinux-libc-dev
        dh_installdeb -plinux-libc-dev
-       dh_gencontrol -plinux-libc-dev -- $(libc_dev_version)
+       $(lockme) dh_gencontrol -plinux-libc-dev -- $(libc_dev_version)
        dh_md5sums -plinux-libc-dev
        dh_builddeb -plinux-libc-dev
 endif
@@ -289,7 +289,7 @@ binary-%: install-%
        dh_fixperms -p$(pkgimg) -X/boot/
        dh_installdeb -p$(pkgimg)
        dh_shlibdeps -p$(pkgimg)
-       dh_gencontrol -p$(pkgimg)
+       $(lockme) dh_gencontrol -p$(pkgimg)
        dh_md5sums -p$(pkgimg)
        dh_builddeb -p$(pkgimg) -- -Zbzip2 -z9
 
@@ -300,7 +300,7 @@ binary-%: install-%
                dh_fixperms -p$(pkgimg_ex) -X/boot/; \
                dh_installdeb -p$(pkgimg_ex); \
                dh_shlibdeps -p$(pkgimg_ex); \
-               dh_gencontrol -p$(pkgimg_ex); \
+               $(lockme) dh_gencontrol -p$(pkgimg_ex); \
                dh_md5sums -p$(pkgimg_ex); \
                dh_builddeb -p$(pkgimg_ex) -- -Zbzip2 -z9; \
        fi
@@ -311,7 +311,7 @@ binary-%: install-%
        dh_fixperms -p$(pkghdr)
        dh_shlibdeps -p$(pkghdr)
        dh_installdeb -p$(pkghdr)
-       dh_gencontrol -p$(pkghdr)
+       $(lockme) dh_gencontrol -p$(pkghdr)
        dh_md5sums -p$(pkghdr)
        dh_builddeb -p$(pkghdr)
 
@@ -324,7 +324,7 @@ ifneq ($(skipsub),true)
                dh_fixperms -p$$pkg -X/boot/;           \
                dh_shlibdeps -p$$pkg;                   \
                dh_installdeb -p$$pkg;                  \
-               dh_gencontrol -p$$pkg;                  \
+               $(lockme) dh_gencontrol -p$$pkg;                        \
                dh_md5sums -p$$pkg;                     \
                dh_builddeb -p$$pkg;                    \
        done
@@ -336,7 +336,7 @@ ifneq ($(skipdbg),true)
        dh_compress -p$(dbgpkg)
        dh_fixperms -p$(dbgpkg)
        dh_installdeb -p$(dbgpkg)
-       dh_gencontrol -p$(dbgpkg)
+       $(lockme) dh_gencontrol -p$(dbgpkg)
        dh_md5sums -p$(dbgpkg)
        dh_builddeb -p$(dbgpkg)
 
@@ -349,12 +349,15 @@ ifneq ($(skipdbg),true)
        mv ../$(dbgpkg)_$(release)-$(revision)_$(arch).deb \
                ../$(dbgpkg)_$(release)-$(revision)_$(arch).ddeb
        set -e; \
-       if grep -qs '^Build-Debug-Symbols: yes$$' /CurrentlyBuilding; then \
-               sed -i '/^$(dbgpkg)_/s/\.deb /.ddeb /' debian/files; \
-       else \
-               grep -v '^$(dbgpkg)_.*$$' debian/files > debian/files.new; \
-               mv debian/files.new debian/files; \
-       fi
+       ( \
+               $(lockme_cmd) 9 || exit 1; \
+               if grep -qs '^Build-Debug-Symbols: yes$$' /CurrentlyBuilding; then \
+                       sed -i '/^$(dbgpkg)_/s/\.deb /.ddeb /' debian/files; \
+               else \
+                       grep -v '^$(dbgpkg)_.*$$' debian/files > debian/files.new; \
+                       mv debian/files.new debian/files; \
+               fi; \
+       ) 9>$(lockme_file)
        # Now, the package wont get into the archive, but it will get put
        # into the debug system.
 endif
@@ -415,7 +418,7 @@ ifeq ($(do_tools),true)
        dh_fixperms -p$(toolspkg)
        dh_shlibdeps -p$(toolspkg)
        dh_installdeb -p$(toolspkg)
-       dh_gencontrol -p$(toolspkg)
+       $(lockme) dh_gencontrol -p$(toolspkg)
        dh_md5sums -p$(toolspkg)
        dh_builddeb -p$(toolspkg)
 endif
index 55c7904..462d721 100644 (file)
@@ -125,7 +125,7 @@ binary-headers: install-headers
        dh_compress -p$(indep_hdrpkg)
        dh_fixperms -p$(indep_hdrpkg)
        dh_installdeb -p$(indep_hdrpkg)
-       dh_gencontrol -p$(indep_hdrpkg)
+       $(lockme) dh_gencontrol -p$(indep_hdrpkg)
        dh_md5sums -p$(indep_hdrpkg)
        dh_builddeb -p$(indep_hdrpkg)
 
@@ -138,6 +138,6 @@ binary-indep: install-indep
        dh_compress -i
        dh_fixperms -i
        dh_installdeb -i
-       dh_gencontrol -i
+       $(lockme) dh_gencontrol -i
        dh_md5sums -i
        dh_builddeb -i
index 63583de..2cb81fd 100644 (file)
@@ -33,6 +33,6 @@ do-binary-udebs: debian/control
        [ -z "$dilist" ] || \
        for i in $$dilist; do \
          dh_fixperms -p$$i; \
-         dh_gencontrol -p$$i; \
+         $(lockme) dh_gencontrol -p$$i; \
          dh_builddeb -p$$i; \
        done