]> arthur.barton.de Git - bup.git/blob - Makefile
tests: partially convert to pytest
[bup.git] / Makefile
1
2 MAKEFLAGS += --warn-undefined-variables
3
4 SHELL := bash
5 .DEFAULT_GOAL := all
6
7 # See config/config.vars.in (sets bup_python, among other things)
8 -include config/config.vars
9
10 pf := set -o pipefail
11 cfg_py := $(CURDIR)/config/bin/python
12
13 define isok
14   && echo " ok" || echo " no"
15 endef
16
17 # If ok, strip trailing " ok" and return the output, otherwise, error
18 define shout
19 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
20 endef
21
22 sampledata_rev := $(shell dev/configure-sampledata --revision $(isok))
23 sampledata_rev := \
24   $(call shout,$(sampledata_rev),Could not parse sampledata revision)
25
26 current_sampledata := test/sampledata/var/rev/v$(sampledata_rev)
27
28 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
29 os := $(call shout,$(os),Unable to determine OS)
30
31 CFLAGS := -O2 -Wall -Werror -Wformat=2 $(CFLAGS)
32 CFLAGS := -Wno-unknown-pragmas -Wsign-compare $(CFLAGS)
33 CFLAGS := -D_FILE_OFFSET_BITS=64 $(PYINCLUDE) $(CFLAGS)
34 SOEXT:=.so
35
36 ifeq ($(os),CYGWIN)
37   SOEXT:=.dll
38 endif
39
40 ifdef TMPDIR
41   test_tmp := $(TMPDIR)
42 else
43   test_tmp := $(CURDIR)/test/tmp
44 endif
45
46 initial_setup := $(shell dev/update-checkout-info lib/bup/checkout_info.py $(isok))
47 initial_setup := $(call shout,$(initial_setup),update-checkout-info failed))
48
49 config/config.vars: \
50   configure config/configure config/configure.inc \
51   $(wildcard config/*.in)
52         MAKE="$(MAKE)" ./configure
53
54 # On some platforms, Python.h and readline.h fight over the
55 # _XOPEN_SOURCE version, i.e. -Werror crashes on a mismatch, so for
56 # now, we're just going to let Python's version win.
57
58 ifneq ($(strip $(bup_readline_cflags)),)
59   readline_cflags += $(bup_readline_cflags)
60   readline_xopen := $(filter -D_XOPEN_SOURCE=%,$(readline_cflags))
61   readline_xopen := $(subst -D_XOPEN_SOURCE=,,$(readline_xopen))
62   readline_cflags := $(filter-out -D_XOPEN_SOURCE=%,$(readline_cflags))
63   readline_cflags += $(addprefix -DBUP_RL_EXPECTED_XOPEN_SOURCE=,$(readline_xopen))
64   CFLAGS += $(readline_cflags)
65 endif
66
67 LDFLAGS += $(bup_readline_ldflags)
68
69 ifeq ($(bup_have_libacl),1)
70   CFLAGS += $(bup_libacl_cflags)
71   LDFLAGS += $(bup_libacl_ldflags)
72 endif
73
74 config/bin/python: config/config.vars
75
76 bup_cmds := \
77   $(patsubst cmd/%-cmd.py,cmd/bup-%,$(wildcard cmd/*-cmd.py)) \
78   $(patsubst cmd/%-cmd.sh,cmd/bup-%,$(wildcard cmd/*-cmd.sh))
79
80 bup_deps := lib/bup/_helpers$(SOEXT) $(bup_cmds)
81
82 all: $(bup_deps) Documentation/all $(current_sampledata)
83
84 $(current_sampledata):
85         dev/configure-sampledata --setup
86
87 PANDOC ?= $(shell type -p pandoc)
88
89 ifeq (,$(PANDOC))
90   $(shell echo "Warning: pandoc not found; skipping manpage generation" 1>&2)
91   man_md :=
92 else
93   man_md := $(wildcard Documentation/*.md)
94 endif
95
96 man_roff := $(patsubst %.md,%.1,$(man_md))
97 man_html := $(patsubst %.md,%.html,$(man_md))
98
99 INSTALL=install
100 PREFIX=/usr/local
101 MANDIR=$(PREFIX)/share/man
102 DOCDIR=$(PREFIX)/share/doc/bup
103 BINDIR=$(PREFIX)/bin
104 LIBDIR=$(PREFIX)/lib/bup
105
106 dest_mandir := $(DESTDIR)$(MANDIR)
107 dest_docdir := $(DESTDIR)$(DOCDIR)
108 dest_bindir := $(DESTDIR)$(BINDIR)
109 dest_libdir := $(DESTDIR)$(LIBDIR)
110
111 install: all
112         $(INSTALL) -d $(dest_bindir) \
113                 $(dest_libdir)/bup $(dest_libdir)/cmd \
114                 $(dest_libdir)/web $(dest_libdir)/web/static
115         test -z "$(man_roff)" || install -d $(dest_mandir)/man1
116         test -z "$(man_roff)" || $(INSTALL) -m 0644 $(man_roff) $(dest_mandir)/man1
117         test -z "$(man_html)" || install -d $(dest_docdir)
118         test -z "$(man_html)" || $(INSTALL) -m 0644 $(man_html) $(dest_docdir)
119         dev/install-python-script lib/cmd/bup "$(dest_libdir)/cmd/bup"
120         set -e; \
121         for cmd in $$(ls cmd/bup-*); do \
122           dev/install-python-script "$$cmd" "$(dest_libdir)/$$cmd"; \
123         done
124         cd "$(dest_bindir)" && \
125           ln -sf "$$($(bup_python) -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')"
126         set -e; \
127         $(INSTALL) -pm 0644 \
128                 lib/bup/*.py \
129                 $(dest_libdir)/bup
130         $(INSTALL) -pm 0755 \
131                 lib/bup/*$(SOEXT) \
132                 $(dest_libdir)/bup
133         $(INSTALL) -pm 0644 \
134                 lib/web/static/* \
135                 $(dest_libdir)/web/static/
136         $(INSTALL) -pm 0644 \
137                 lib/web/*.html \
138                 $(dest_libdir)/web/
139         if test -e lib/bup/checkout_info.py; then \
140             $(INSTALL) -pm 0644 lib/bup/checkout_info.py \
141                 $(dest_libdir)/bup/source_info.py; \
142         else \
143             ! grep -qF '$$Format' lib/bup/source_info.py; \
144             $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \
145         fi
146
147 config/config.h: config/config.vars
148
149 lib/bup/_helpers$(SOEXT): \
150                 config/config.h lib/bup/bupsplit.h \
151                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
152         @rm -f $@
153         cd lib/bup && $(cfg_py) csetup.py build "$(CFLAGS)" "$(LDFLAGS)"
154         # Make sure there's just the one file we expect before we copy it.
155         $(cfg_py) -c \
156           "import glob; assert(len(glob.glob('lib/bup/build/*/_helpers*$(SOEXT)')) == 1)"
157         cp lib/bup/build/*/_helpers*$(SOEXT) "$@"
158
159 test/tmp:
160         mkdir test/tmp
161
162 runtests: runtests-python runtests-cmdline
163
164 runtests-python: all test/tmp
165         ./pytest
166
167 cmdline_tests := \
168   test/ext/test.sh \
169   test/ext/test-argv \
170   test/ext/test-cat-file.sh \
171   test/ext/test-command-without-init-fails.sh \
172   test/ext/test-compression.sh \
173   test/ext/test-drecurse.sh \
174   test/ext/test-fsck.sh \
175   test/ext/test-fuse.sh \
176   test/ext/test-ftp \
177   test/ext/test-help \
178   test/ext/test-web.sh \
179   test/ext/test-gc.sh \
180   test/ext/test-import-duplicity.sh \
181   test/ext/test-import-rdiff-backup.sh \
182   test/ext/test-index.sh \
183   test/ext/test-index-check-device.sh \
184   test/ext/test-index-clear.sh \
185   test/ext/test-list-idx.sh \
186   test/ext/test-ls \
187   test/ext/test-ls-remote \
188   test/ext/test-main.sh \
189   test/ext/test-meta.sh \
190   test/ext/test-on.sh \
191   test/ext/test-packsizelimit \
192   test/ext/test-prune-older \
193   test/ext/test-redundant-saves.sh \
194   test/ext/test-restore-map-owner.sh \
195   test/ext/test-restore-single-file.sh \
196   test/ext/test-rm.sh \
197   test/ext/test-rm-between-index-and-save.sh \
198   test/ext/test-save-creates-no-unrefs.sh \
199   test/ext/test-save-restore \
200   test/ext/test-save-errors \
201   test/ext/test-save-restore-excludes.sh \
202   test/ext/test-save-strip-graft.sh \
203   test/ext/test-save-with-valid-parent.sh \
204   test/ext/test-sparse-files.sh \
205   test/ext/test-split-join.sh \
206   test/ext/test-tz.sh \
207   test/ext/test-xdev.sh
208
209 tmp-target-run-test-get-%: all test/tmp
210         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
211           test/ext/test-get $* 2>&1 | tee -a test/tmp/test-log/$$$$.log
212
213 test_get_targets += \
214   tmp-target-run-test-get-replace \
215   tmp-target-run-test-get-universal \
216   tmp-target-run-test-get-ff \
217   tmp-target-run-test-get-append \
218   tmp-target-run-test-get-pick \
219   tmp-target-run-test-get-new-tag \
220   tmp-target-run-test-get-unnamed
221
222 # For parallel runs.
223 # The "pwd -P" here may not be appropriate in the long run, but we
224 # need it until we settle the relevant drecurse/exclusion questions:
225 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
226 tmp-target-run-test%: all test/tmp
227         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
228           test/ext/test$* 2>&1 | tee -a test/tmp/test-log/$$$$.log
229
230 runtests-cmdline: $(test_get_targets) $(subst test/ext/test,tmp-target-run-test,$(cmdline_tests))
231
232 stupid:
233         PATH=/bin:/usr/bin $(MAKE) test
234
235 test: all
236         if test -e test/tmp/test-log; then rm -r test/tmp/test-log; fi
237         mkdir -p test/tmp/test-log
238         $(MAKE) runtests-python
239         ./wvtest watch --no-counts \
240           $(MAKE) runtests-cmdline 2>test/tmp/test-log/$$$$.log
241         ./wvtest report test/tmp/test-log/*.log
242
243 check: test
244
245 distcheck: all
246         ./wvtest run test/ext/test-release-archive.sh
247
248 long-test: export BUP_TEST_LEVEL=11
249 long-test: test
250
251 long-check: export BUP_TEST_LEVEL=11
252 long-check: check
253
254 .PHONY: check-both
255 check-both:
256         $(MAKE) clean && PYTHON=python3 $(MAKE) check
257         $(MAKE) clean && PYTHON=python2 $(MAKE) check
258
259 cmd/bup-%: cmd/%-cmd.py
260         rm -f $@
261         ln -s $*-cmd.py $@
262
263 cmd/bup-%: cmd/%-cmd.sh
264         rm -f $@
265         ln -s $*-cmd.sh $@
266
267 .PHONY: Documentation/all
268 Documentation/all: $(man_roff) $(man_html)
269
270 Documentation/substvars: $(bup_deps)
271         echo "s,%BUP_VERSION%,$$(./bup version),g" > $@
272         echo "s,%BUP_DATE%,$$(./bup version --date),g" >> $@
273
274 Documentation/%.1: Documentation/%.md Documentation/substvars
275         $(pf); sed -f Documentation/substvars $< \
276           | $(PANDOC) -s -r markdown -w man -o $@
277
278 Documentation/%.html: Documentation/%.md Documentation/substvars
279         $(pf); sed -f Documentation/substvars $< \
280           | $(PANDOC) -s -r markdown -w html -o $@
281
282 .PHONY: Documentation/clean
283 Documentation/clean:
284         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
285
286 # Note: this adds commits containing the current manpages in roff and
287 # html format to the man and html branches respectively.  The version
288 # is determined by "git describe --always".
289 .PHONY: update-doc-branches
290 update-doc-branches: Documentation/all
291         dev/update-doc-branches refs/heads/man refs/heads/html
292
293 # push the pregenerated doc files to origin/man and origin/html
294 push-docs: export-docs
295         git push origin man html
296
297 # import pregenerated doc files from origin/man and origin/html, in case you
298 # don't have pandoc but still want to be able to install the docs.
299 import-docs: Documentation/clean
300         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
301         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
302
303 clean: Documentation/clean config/bin/python
304         cd config && rm -rf config.var
305         cd config && rm -f *~ .*~ \
306           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
307         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
308                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
309                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
310                 lib/bup/checkout_info.py \
311                 randomgen memtest \
312                 testfs.img test/int/testfs.img
313         for x in $$(ls cmd/*-cmd.py cmd/*-cmd.sh | grep -vF python-cmd.sh | cut -b 5-); do \
314             echo "cmd/bup-$${x%-cmd.*}"; \
315         done | xargs -t rm -f
316         if test -e test/mnt; then dev/cleanup-mounts-under test/mnt; fi
317         if test -e test/mnt; then rm -r test/mnt; fi
318         if test -e test/tmp; then dev/cleanup-mounts-under test/tmp; fi
319         # FIXME: migrate these to test/mnt/
320         if test -e test/int/testfs; \
321           then umount test/int/testfs || true; fi
322         rm -rf *.tmp *.tmp.meta test/*.tmp lib/*/*/*.tmp build lib/bup/build test/int/testfs
323         if test -e test/tmp; then dev/force-delete test/tmp; fi
324         dev/configure-sampledata --clean
325         # Remove last so that cleanup tools can depend on it
326         rm -rf config/bin