| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | PYTESTS = $(wildcard test/test_*.py) | 
					
						
							| 
									
										
										
										
											2020-12-21 21:30:28 +00:00
										 |  |  | IMAGE = yadm/testbed:2020-12-21 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 16:56:33 +00:00
										 |  |  | .PHONY: all | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | all: | 
					
						
							|  |  |  | 	@$(MAKE) usage | less | 
					
						
							| 
									
										
										
										
											2015-07-17 00:38:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | # Display usage for all make targets
 | 
					
						
							|  |  |  | .PHONY: usage | 
					
						
							|  |  |  | usage: | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo 'make TARGET [option=value, ...]' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo 'TESTING' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make test [testargs=ARGS]' | 
					
						
							|  |  |  | 	@echo '    - Run all tests. "testargs" can specify a single string of arguments' | 
					
						
							|  |  |  | 	@echo '      for py.test.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make <testfile>.py [testargs=ARGS]' | 
					
						
							|  |  |  | 	@echo '    - Run tests from a specific test file. "testargs" can specify a' | 
					
						
							|  |  |  | 	@echo '      single string of arguments for py.test.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make testhost [version=VERSION]' | 
					
						
							|  |  |  | 	@echo '    - Create an ephemeral container for doing adhoc yadm testing. The' | 
					
						
							|  |  |  | 	@echo '      HEAD revision of yadm will be used unless "version" is' | 
					
						
							|  |  |  | 	@echo '      specified. "version" can be set to any commit, branch, tag, etc.' | 
					
						
							|  |  |  | 	@echo '      The targeted "version" will be retrieved from the repo, and' | 
					
						
							|  |  |  | 	@echo '      linked into the container as a local volume.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 	@echo '  make scripthost [version=VERSION]' | 
					
						
							|  |  |  | 	@echo '    - Create an ephemeral container for demonstrating a bug. After' | 
					
						
							|  |  |  | 	@echo '      exiting the shell, a log of the commands used to illustrate the' | 
					
						
							|  |  |  | 	@echo '      problem will be written to the file "script.txt". This file can' | 
					
						
							|  |  |  | 	@echo '      be useful to developers to make a repeatable test for the' | 
					
						
							|  |  |  | 	@echo '      problem.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo 'LINTING' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make testenv' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '    - Create a python virtual environment with the same dependencies' | 
					
						
							|  |  |  | 	@echo "      used by yadm's testbed environment. Creating and activating" | 
					
						
							|  |  |  | 	@echo '      this environment might be useful if your editor does real time' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo '      linting of python files. After creating the virtual environment,' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '      you can activate it by typing:' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '          source testenv/bin/activate' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo 'MANPAGES' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make man' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '    - View yadm.1 as a standard man page.' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make man-wide' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '    - View yadm.1 as a man page, using all columns of your display.' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make man-ps' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '    - Create a postscript version of the man page.' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo 'FILE GENERATION' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make yadm.md' | 
					
						
							| 
									
										
										
										
											2019-03-07 14:26:17 +00:00
										 |  |  | 	@echo '    - Generate the markdown version of the man page (for viewing on' | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo '      the web).' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make contrib' | 
					
						
							|  |  |  | 	@echo '    - Generate the CONTRIBUTORS file, from the repo history.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2019-11-09 21:48:14 +00:00
										 |  |  | 	@echo 'INSTALLATION' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make install PREFIX=<prefix>' | 
					
						
							|  |  |  | 	@echo '    - Install yadm, manpage, etc. to <prefix>' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo 'UTILITIES' | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo '  make sync-clock' | 
					
						
							|  |  |  | 	@echo '    - Reset the hardware clock for the docker hypervisor host. This' | 
					
						
							|  |  |  | 	@echo '      can be useful for docker engine hosts which are not' | 
					
						
							|  |  |  | 	@echo '      Linux-based.' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2015-07-17 00:38:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | # Make it possible to run make specifying a py.test test file
 | 
					
						
							|  |  |  | .PHONY: $(PYTESTS) | 
					
						
							|  |  |  | $(PYTESTS): | 
					
						
							|  |  |  | 	@$(MAKE) test testargs="-k $@ $(testargs)" | 
					
						
							|  |  |  | %.py: | 
					
						
							|  |  |  | 	@$(MAKE) test testargs="-k $@ $(testargs)" | 
					
						
							| 
									
										
										
										
											2015-07-17 00:38:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | # Run all tests with additional testargs
 | 
					
						
							| 
									
										
										
										
											2016-03-24 00:18:33 +00:00
										 |  |  | .PHONY: test | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | test: | 
					
						
							|  |  |  | 	@if [ -f /.yadmtestbed ]; then \
 | 
					
						
							|  |  |  | 		cd /yadm && \
 | 
					
						
							| 
									
										
										
										
											2020-07-08 05:58:54 +00:00
										 |  |  | 		py.test -v $(testargs); \
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	else \
 | 
					
						
							| 
									
										
										
										
											2020-10-09 20:55:10 +00:00
										 |  |  | 		if command -v "docker-compose" > /dev/null 2>&1; then \
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 			docker-compose run --rm testbed make test testargs="$(testargs)"; \
 | 
					
						
							|  |  |  | 		else \
 | 
					
						
							|  |  |  | 			echo "Sorry, this make test requires docker-compose to be installed."; \
 | 
					
						
							|  |  |  | 			false; \
 | 
					
						
							|  |  |  | 		fi \
 | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2016-04-07 13:16:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 16:48:45 +00:00
										 |  |  | .PHONY: testhost | 
					
						
							| 
									
										
										
										
											2020-10-10 08:12:31 +00:00
										 |  |  | testhost: version ?= HEAD | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | testhost: require-docker | 
					
						
							| 
									
										
										
										
											2017-09-04 16:48:45 +00:00
										 |  |  | 	@rm -rf /tmp/testhost | 
					
						
							| 
									
										
										
										
											2020-11-26 04:05:24 +00:00
										 |  |  | 	@if [ "$(version)" = "local" ]; then \
 | 
					
						
							|  |  |  | 		cp -f yadm /tmp/testhost; \
 | 
					
						
							|  |  |  | 	else \
 | 
					
						
							|  |  |  | 		git show $(version):yadm > /tmp/testhost; \
 | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2017-09-04 16:48:45 +00:00
										 |  |  | 	@chmod a+x /tmp/testhost | 
					
						
							| 
									
										
										
										
											2020-10-10 23:12:51 +00:00
										 |  |  | 	@echo Starting testhost version=\"$(version)\" | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 	@docker run \
 | 
					
						
							|  |  |  | 		-w /root \
 | 
					
						
							|  |  |  | 		--hostname testhost \
 | 
					
						
							|  |  |  | 		--rm -it \
 | 
					
						
							|  |  |  | 		-v "/tmp/testhost:/bin/yadm:ro" \
 | 
					
						
							| 
									
										
										
										
											2020-07-08 05:58:54 +00:00
										 |  |  | 		$(IMAGE) \
 | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 		bash -l | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PHONY: scripthost | 
					
						
							| 
									
										
										
										
											2020-10-10 08:12:31 +00:00
										 |  |  | scripthost: version ?= HEAD | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | scripthost: require-docker | 
					
						
							|  |  |  | 	@rm -rf /tmp/testhost | 
					
						
							|  |  |  | 	@git show $(version):yadm > /tmp/testhost | 
					
						
							|  |  |  | 	@chmod a+x /tmp/testhost | 
					
						
							| 
									
										
										
										
											2020-10-10 23:12:51 +00:00
										 |  |  | 	@echo Starting scripthost version=\"$(version)\" \(recording script\) | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 	@printf '' > script.gz | 
					
						
							|  |  |  | 	@docker run \
 | 
					
						
							|  |  |  | 		-w /root \
 | 
					
						
							|  |  |  | 		--hostname scripthost \
 | 
					
						
							|  |  |  | 		--rm -it \
 | 
					
						
							|  |  |  | 		-v "$$PWD/script.gz:/script.gz:rw" \
 | 
					
						
							|  |  |  | 		-v "/tmp/testhost:/bin/yadm:ro" \
 | 
					
						
							| 
									
										
										
										
											2020-07-08 05:58:54 +00:00
										 |  |  | 		$(IMAGE) \
 | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 		bash -c "script /tmp/script -q -c 'bash -l'; gzip < /tmp/script > /script.gz" | 
					
						
							|  |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo "Script saved to $$PWD/script.gz" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .PHONY: testenv | 
					
						
							|  |  |  | testenv: | 
					
						
							|  |  |  | 	@echo 'Creating a local virtual environment in "testenv/"' | 
					
						
							|  |  |  | 	@echo | 
					
						
							| 
									
										
										
										
											2020-01-29 06:14:37 +00:00
										 |  |  | 	python3 -m venv --clear testenv | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	testenv/bin/pip3 install --upgrade pip setuptools | 
					
						
							| 
									
										
										
										
											2020-12-21 21:30:28 +00:00
										 |  |  | 	testenv/bin/pip3 install --upgrade -r test/requirements.txt; | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@echo | 
					
						
							|  |  |  | 	@echo 'To activate this test environment type:' | 
					
						
							|  |  |  | 	@echo '  source testenv/bin/activate' | 
					
						
							| 
									
										
										
										
											2017-09-04 16:48:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-21 21:30:28 +00:00
										 |  |  | .PHONY: image | 
					
						
							|  |  |  | image: | 
					
						
							|  |  |  | 	@docker build -f test/Dockerfile . -t "$(IMAGE)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 16:56:33 +00:00
										 |  |  | .PHONY: man | 
					
						
							| 
									
										
										
										
											2015-07-17 00:38:17 +00:00
										 |  |  | man: | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | 	@groff -man -Tascii ./yadm.1 | less | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PHONY: man-wide | 
					
						
							|  |  |  | man-wide: | 
					
						
							|  |  |  | 	@man ./yadm.1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .PHONY: man-ps | 
					
						
							|  |  |  | man-ps: | 
					
						
							|  |  |  | 	@groff -man -Tps ./yadm.1 > yadm.ps | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | yadm.md: yadm.1 | 
					
						
							|  |  |  | 	@groff -man -Tascii ./yadm.1 | col -bx | sed 's/^[A-Z]/## &/g' | sed '/yadm(1)/d' > yadm.md | 
					
						
							| 
									
										
										
										
											2015-07-17 00:38:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 22:32:34 +00:00
										 |  |  | .PHONY: contrib | 
					
						
							|  |  |  | contrib: | 
					
						
							|  |  |  | 	@echo "CONTRIBUTORS\n" > CONTRIBUTORS | 
					
						
							| 
									
										
										
										
											2020-08-08 20:40:29 +00:00
										 |  |  | 	@IFS=$$'\n'; for author in $$(git shortlog -ns master gh-pages develop dev-pages | cut -f2); do \
 | 
					
						
							|  |  |  | 		git log master gh-pages develop dev-pages \
 | 
					
						
							|  |  |  | 			--author="$$author" --format=tformat: --numstat | \
 | 
					
						
							|  |  |  | 			awk "{sum += \$$1 + \$$2} END {print sum \"\t\" \"$$author\"}"; \
 | 
					
						
							|  |  |  | 	done | sort -nr | cut -f2 >> CONTRIBUTORS | 
					
						
							| 
									
										
										
										
											2018-07-11 12:50:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-09 21:48:14 +00:00
										 |  |  | .PHONY: install | 
					
						
							|  |  |  | install: | 
					
						
							|  |  |  | 	@[ -n "$(PREFIX)" ] || { echo "PREFIX is not set"; exit 1; } | 
					
						
							|  |  |  | 	@{\
 | 
					
						
							|  |  |  | 		set -e                                               ;\
 | 
					
						
							|  |  |  | 		bin="$(PREFIX)/bin"                                  ;\
 | 
					
						
							|  |  |  | 		doc="$(PREFIX)/share/doc/yadm"                       ;\
 | 
					
						
							|  |  |  | 		man="$(PREFIX)/share/man/man1"                       ;\
 | 
					
						
							|  |  |  | 		install -d "$$bin" "$$doc" "$$man"                   ;\
 | 
					
						
							|  |  |  | 		install -m 0755 yadm "$$bin"                         ;\
 | 
					
						
							|  |  |  | 		install -m 0644 yadm.1 "$$man"                       ;\
 | 
					
						
							|  |  |  | 		install -m 0644 CHANGES CONTRIBUTORS LICENSE "$$doc" ;\
 | 
					
						
							|  |  |  | 		cp -r contrib "$$doc"                                ;\
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-11 12:50:42 +00:00
										 |  |  | .PHONY: sync-clock | 
					
						
							|  |  |  | sync-clock: | 
					
						
							|  |  |  | 	docker run --rm --privileged alpine hwclock -s | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | .PHONY: require-docker | 
					
						
							|  |  |  | require-docker: | 
					
						
							| 
									
										
										
										
											2020-10-09 20:55:10 +00:00
										 |  |  | 	@if ! command -v "docker" > /dev/null 2>&1; then \
 | 
					
						
							| 
									
										
										
										
											2019-03-01 04:59:04 +00:00
										 |  |  | 		echo "Sorry, this make target requires docker to be installed."; \
 | 
					
						
							|  |  |  | 		false; \
 | 
					
						
							|  |  |  | 	fi |