From 8ae556b8d341bb73d862f5af6a2b70e05fae3a4c Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 21 Mar 2015 14:32:30 -0500 Subject: [PATCH] Only build _version.py once; remove phony targets 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 Tested-by: Rob Browning --- Makefile | 14 +++++--------- configure-version | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) create mode 100755 configure-version diff --git a/Makefile b/Makefile index 5bc3bcc..1189613 100644 --- 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 index 0000000..87126b7 --- /dev/null +++ b/configure-version @@ -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 -- 2.39.2