]> arthur.barton.de Git - bup.git/commitdiff
Only build _version.py once; remove phony targets
authorRob Browning <rlb@defaultvalue.org>
Sat, 21 Mar 2015 19:32:30 +0000 (14:32 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 28 Mar 2015 15:35:19 +0000 (10:35 -0500)
Previously _version.py was a phony target because we couldn't easily
tell when the current git working tree version had changed.  This caused
various targets to be rebuilt multiple times (i.e. recursive make
invocations, etc.).

To fix that, just update _version.py once (at startup) if needed, via an
immediate variable assignment that calls a new ./configure-version
command, i.e.

  initial_setup := $(shell ./configure-version --update)

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
Makefile
configure-version [new file with mode: 0755]

index 5bc3bcc8c7ec5596659813c834012bc0b8780153..11896134586681951ea2ea55de7c40033d4bd256 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ else
   test_tmp := $(CURDIR)/t/tmp
 endif
 
+initial_setup := $(shell ./configure-version --update)
 bup_deps := bup lib/bup/_version.py lib/bup/_helpers$(SOEXT) cmds
 
 all: $(bup_deps) Documentation/all $(current_sampledata)
@@ -82,15 +83,10 @@ lib/bup/_helpers$(SOEXT): \
        LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" $(PYTHON) csetup.py build
        cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
 
-# This must be completely atomic since it may be run (often) in
-# parallel when "-j" is specified, either via targets here, or via
-# tests that use an install tree as data.
-.PHONY: lib/bup/_version.py
 lib/bup/_version.py:
-       rm -f $@.tmp-$$$$ \
-       && ./format-subst.pl $@.pre > $@.tmp-$$$$ \
-       && (if ! test -e $@ || ! cmp $@ $@.tmp-$$$$; then mv $@.tmp-$$$$ $@; fi) \
-       && rm -f $@.tmp-$$$$
+       @echo "Something has gone wrong; $@ should already exist."
+       @echo 'Check "./configure-version --update"'
+       @false
 
 t/tmp:
        mkdir t/tmp
@@ -185,7 +181,6 @@ clean: Documentation/clean config/clean
                .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
                *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
                bup bup-* cmd/bup-* \
-               lib/bup/_version.py lib/bup/_version.py.tmp-* \
                randomgen memtest \
                testfs.img lib/bup/t/testfs.img
        if test -e t/mnt; then t/cleanup-mounts-under t/mnt; fi
@@ -196,4 +191,5 @@ clean: Documentation/clean config/clean
          then umount lib/bup/t/testfs || true; fi
        rm -rf *.tmp *.tmp.meta t/*.tmp lib/*/*/*.tmp build lib/bup/build lib/bup/t/testfs
        if test -e t/tmp; then t/force-delete t/tmp; fi
+       ./configure-version --clean
        t/configure-sampledata --clean
diff --git a/configure-version b/configure-version
new file mode 100755 (executable)
index 0000000..87126b7
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+set -eo pipefail
+
+top="$(pwd)"
+vpy=lib/bup/_version.py
+readonly top vpy
+
+usage()
+{
+    echo 'Usage: ./configure-version [--update | --clean]'
+}
+
+if test "$#" -ne 1; then
+    usage 1>&2; exit 1
+fi
+
+case "$1" in
+    --update)
+        rm -f $vpy.tmp-$$
+        ./format-subst.pl $vpy.pre > $vpy.tmp-$$
+        if ! test -e $vpy || ! cmp -s $vpy $vpy.tmp-$$; then
+            mv $vpy.tmp-$$ $vpy;
+        fi
+        rm -f $vpy.tmp-$$
+        ;;
+    --clean)
+       rm -f lib/bup/_version.py lib/bup/_version.pyc lib/bup/_version.py.tmp-*
+        ;;
+    *)
+        usage 1>&2; exit 1
+        ;;
+esac