THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 13KB

  1. # WARN: gmake syntax
  2. ########################################################
  3. # Makefile for Ansible
  4. #
  5. # useful targets:
  6. # make clean ---------------- clean up
  7. # make webdocs -------------- produce ansible doc at docs/docsite/_build/html
  8. # make sdist ---------------- produce a tarball
  9. # make srpm ----------------- produce a SRPM
  10. # make rpm ----------------- produce RPMs
  11. # make deb-src -------------- produce a DEB source
  12. # make deb ------------------ produce a DEB
  13. # make docs ----------------- rebuild the manpages (results are checked in)
  14. # make tests ---------------- run the tests (see https://docs.ansible.com/ansible/devel/dev_guide/testing_units.html for requirements)
  15. ########################################################
  16. # variable section
  17. NAME = ansible
  18. OS = $(shell uname -s)
  19. PREFIX ?= '/usr/local'
  20. SDIST_DIR ?= 'dist'
  21. # This doesn't evaluate until it's called. The -D argument is the
  22. # directory of the target file ($@), kinda like `dirname`.
  23. MANPAGES ?= $(patsubst %.rst.in,%,$(wildcard ./docs/man/man1/ansible*.1.rst.in))
  24. ifneq ($(shell which rst2man 2>/dev/null),)
  25. ASCII2MAN = rst2man $< $@
  26. else ifneq ($(shell which rst2man.py 2>/dev/null),)
  27. ASCII2MAN = rst2man.py $< $@
  28. else
  29. ASCII2MAN = @echo "ERROR: rst2man from docutils command is not installed but is required to build $(MANPAGES)" && exit 1
  30. endif
  31. PYTHON=python
  32. GENERATE_CLI = hacking/build-ansible.py generate-man
  33. SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")
  34. # fetch version from project release.py as single source-of-truth
  35. VERSION := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --raw || echo error)
  36. ifeq ($(findstring error,$(VERSION)), error)
  37. $(error "version_helper failed")
  38. endif
  39. MAJOR_VERSION := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --majorversion)
  40. CODENAME := $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --codename)
  41. # if a specific release was not requested, set to 1 (RPMs have "fancier" logic for this further down)
  42. RELEASE ?= 1
  43. # Get the branch information from git
  44. ifneq ($(shell which git),)
  45. GIT_DATE := $(shell git log -n 1 --format="%ci")
  46. GIT_HASH := $(shell git log -n 1 --format="%h")
  47. GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/[-_.\/]//g')
  48. GITINFO = .$(GIT_HASH).$(GIT_BRANCH)
  49. else
  50. GITINFO = ""
  51. endif
  52. ifeq ($(shell echo $(OS) | egrep -c 'Darwin|FreeBSD|OpenBSD|DragonFly'),1)
  53. DATE := $(shell date -j -r $(shell git log -n 1 --format="%ct") +%Y%m%d%H%M)
  54. CPUS ?= $(shell sysctl hw.ncpu|awk '{print $$2}')
  55. else
  56. DATE := $(shell date --utc --date="$(GIT_DATE)" +%Y%m%d%H%M)
  57. CPUS ?= $(shell nproc)
  58. endif
  59. # DEB build parameters
  60. DEBUILD_BIN ?= debuild
  61. DEBUILD_OPTS = --source-option="-I"
  62. DPUT_BIN ?= dput
  63. DPUT_OPTS ?=
  64. DEB_DATE := $(shell LC_TIME=C date +"%a, %d %b %Y %T %z")
  65. DEB_VERSION ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --debversion)
  66. ifeq ($(OFFICIAL),yes)
  67. DEB_RELEASE ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --debrelease)ppa
  68. # Sign OFFICIAL builds using 'DEBSIGN_KEYID'
  69. # DEBSIGN_KEYID is required when signing
  70. ifneq ($(DEBSIGN_KEYID),)
  71. DEBUILD_OPTS += -k$(DEBSIGN_KEYID)
  72. endif
  73. else
  74. DEB_RELEASE ?= 100.git$(DATE)$(GITINFO)
  75. # Do not sign unofficial builds
  76. DEBUILD_OPTS += -uc -us
  77. DPUT_OPTS += -u
  78. endif
  79. DEBUILD = $(DEBUILD_BIN) $(DEBUILD_OPTS)
  80. DEB_PPA ?= ppa
  81. # Choose the desired Ubuntu release: lucid precise saucy trusty
  82. DEB_DIST ?= unstable
  83. # pbuilder parameters
  84. PBUILDER_ARCH ?= amd64
  85. PBUILDER_CACHE_DIR = /var/cache/pbuilder
  86. PBUILDER_BIN ?= pbuilder
  87. PBUILDER_OPTS ?= --debootstrapopts --variant=buildd --architecture $(PBUILDER_ARCH) --debbuildopts -b
  88. # RPM build parameters
  89. RPMSPECDIR= packaging/rpm
  90. RPMSPEC = $(RPMSPECDIR)/ansible.spec
  91. RPMDIST = $(shell rpm --eval '%{?dist}')
  92. ifneq ($(OFFICIAL),yes)
  93. RPMRELEASE = 100.git$(DATE)$(GITINFO)
  94. endif
  95. ifeq ($(PUBLISH),nightly)
  96. # https://fedoraproject.org/wiki/Packaging:Versioning#Snapshots
  97. RPMRELEASE = $(RELEASE).$(DATE)git.$(GIT_HASH)
  98. endif
  99. RPMVERSION ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --baseversion)
  100. RPMRELEASE ?= $(shell $(PYTHON) packaging/release/versionhelper/version_helper.py --rpmrelease)
  101. RPMNVR = "$(NAME)-$(RPMVERSION)-$(RPMRELEASE)$(RPMDIST)$(REPOTAG)"
  102. # MOCK build parameters
  103. MOCK_BIN ?= mock
  104. MOCK_CFG ?=
  105. # dynamically add repotag define only if specified
  106. ifneq ($(REPOTAG),)
  107. EXTRA_RPM_DEFINES += --define "repotag $(REPOTAG)"
  108. endif
  109. # ansible-test parameters
  110. ANSIBLE_TEST ?= bin/ansible-test
  111. TEST_FLAGS ?=
  112. # ansible-test units parameters (make test / make test-py3)
  113. PYTHON_VERSION ?= $(shell python2 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
  114. PYTHON3_VERSION ?= $(shell python3 -c 'import sys; print("%s.%s" % sys.version_info[:2])')
  115. # ansible-test integration parameters (make integration)
  116. IMAGE ?= centos7
  117. TARGET ?=
  118. ########################################################
  119. .PHONY: all
  120. all: clean python
  121. .PHONY: tests
  122. tests:
  123. $(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS)
  124. .PHONY: tests-py3
  125. tests-py3:
  126. $(ANSIBLE_TEST) units -v --python $(PYTHON3_VERSION) $(TEST_FLAGS)
  127. .PHONY: tests-nonet
  128. tests-nonet:
  129. $(ANSIBLE_TEST) units -v --python $(PYTHON_VERSION) $(TEST_FLAGS) --exclude test/units/modules/network/
  130. .PHONY: integration
  131. integration:
  132. $(ANSIBLE_TEST) integration -v --docker $(IMAGE) $(TARGET) $(TEST_FLAGS)
  133. .PHONY: authors
  134. authors:
  135. sh hacking/authors.sh
  136. # Regenerate %.1.rst if %.1.rst.in has been modified more
  137. # recently than %.1.rst.
  138. %.1.rst: %.1.rst.in
  139. sed "s/%VERSION%/$(VERSION)/" $< > $@
  140. rm $<
  141. # Regenerate %.1 if %.1.rst or release.py has been modified more
  142. # recently than %.1. (Implicitly runs the %.1.rst recipe)
  143. %.1: %.1.rst lib/ansible/release.py
  144. $(ASCII2MAN)
  145. .PHONY: clean
  146. clean:
  147. @echo "Cleaning up distutils stuff"
  148. rm -rf build
  149. rm -rf dist
  150. rm -rf lib/ansible.egg-info/
  151. @echo "Cleaning up byte compiled python stuff"
  152. find . -type f -regex ".*\.py[co]$$" -delete
  153. find . -type d -name "__pycache__" -delete
  154. @echo "Cleaning up editor backup files"
  155. find . -type f -not -path ./test/units/inventory_test_data/group_vars/noparse/all.yml~ \( -name "*~" -or -name "#*" \) -delete
  156. find . -type f \( -name "*.swp" \) -delete
  157. @echo "Cleaning up manpage stuff"
  158. find ./docs/man -type f -name "*.xml" -delete
  159. find ./docs/man -type f -name "*.rst" -delete
  160. find ./docs/man/man3 -type f -name "*.3" -delete
  161. rm -f ./docs/man/man1/*
  162. @echo "Cleaning up output from test runs"
  163. rm -rf test/test_data
  164. rm -rf shippable/
  165. rm -rf logs/
  166. rm -rf .cache/
  167. rm -f test/units/.coverage*
  168. rm -rf test/results/*/*
  169. find test/ -type f -name '*.retry' -delete
  170. @echo "Cleaning up RPM building stuff"
  171. rm -rf MANIFEST rpm-build
  172. @echo "Cleaning up Debian building stuff"
  173. rm -rf debian
  174. rm -rf deb-build
  175. rm -rf docs/json
  176. rm -rf docs/js
  177. @echo "Cleaning up authors file"
  178. rm -f AUTHORS.TXT
  179. @echo "Cleaning up docsite"
  180. $(MAKE) -C docs/docsite clean
  181. .PHONY: python
  182. python:
  183. $(PYTHON) setup.py build
  184. .PHONY: install
  185. install:
  186. $(PYTHON) setup.py install
  187. install_manpages:
  188. gzip -9 $(wildcard ./docs/man/man1/ansible*.1)
  189. cp $(wildcard ./docs/man/man1/ansible*.1.gz) $(PREFIX)/man/man1/
  190. .PHONY: sdist_check
  191. sdist_check:
  192. $(PYTHON) packaging/sdist/check-link-behavior.py
  193. .PHONY: sdist
  194. sdist: sdist_check clean docs
  195. _ANSIBLE_SDIST_FROM_MAKEFILE=1 $(PYTHON) setup.py sdist --dist-dir=$(SDIST_DIR)
  196. # Official releases generate the changelog as the last commit before the release.
  197. # Snapshots shouldn't result in new checkins so the changelog is generated as
  198. # part of creating the tarball.
  199. .PHONY: snapshot
  200. snapshot: sdist_check clean docs changelog
  201. _ANSIBLE_SDIST_FROM_MAKEFILE=1 $(PYTHON) setup.py sdist --dist-dir=$(SDIST_DIR)
  202. .PHONY: sdist_upload
  203. sdist_upload: clean docs
  204. $(PYTHON) setup.py sdist upload 2>&1 |tee upload.log
  205. .PHONY: changelog
  206. changelog:
  207. PYTHONPATH=./lib packaging/release/changelogs/changelog.py release -vv && PYTHONPATH=./lib packaging/release/changelogs/changelog.py generate -vv
  208. .PHONY: rpmcommon
  209. rpmcommon: sdist
  210. @mkdir -p rpm-build
  211. @cp dist/*.gz rpm-build/
  212. @cp $(RPMSPEC) rpm-build/$(NAME).spec
  213. .PHONY: mock-srpm
  214. mock-srpm: /etc/mock/$(MOCK_CFG).cfg rpmcommon
  215. $(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --bootstrap-chroot --old-chroot --buildsrpm --spec rpm-build/$(NAME).spec --sources rpm-build/ \
  216. --define "rpmversion $(RPMVERSION)" \
  217. --define "upstream_version $(VERSION)" \
  218. --define "rpmrelease $(RPMRELEASE)" \
  219. $(EXTRA_RPM_DEFINES)
  220. @echo "#############################################"
  221. @echo "Ansible SRPM is built:"
  222. @echo rpm-build/*.src.rpm
  223. @echo "#############################################"
  224. .PHONY: mock-rpm
  225. mock-rpm: /etc/mock/$(MOCK_CFG).cfg mock-srpm
  226. $(MOCK_BIN) -r $(MOCK_CFG) $(MOCK_ARGS) --resultdir rpm-build/ --bootstrap-chroot --old-chroot --rebuild rpm-build/$(NAME)-*.src.rpm \
  227. --define "rpmversion $(RPMVERSION)" \
  228. --define "upstream_version $(VERSION)" \
  229. --define "rpmrelease $(RPMRELEASE)" \
  230. $(EXTRA_RPM_DEFINES)
  231. @echo "#############################################"
  232. @echo "Ansible RPM is built:"
  233. @echo rpm-build/*.noarch.rpm
  234. @echo "#############################################"
  235. .PHONY: srpm
  236. srpm: rpmcommon
  237. @rpmbuild --define "_topdir %(pwd)/rpm-build" \
  238. --define "_builddir %{_topdir}" \
  239. --define "_rpmdir %{_topdir}" \
  240. --define "_srcrpmdir %{_topdir}" \
  241. --define "_specdir $(RPMSPECDIR)" \
  242. --define "_sourcedir %{_topdir}" \
  243. --define "upstream_version $(VERSION)" \
  244. --define "rpmversion $(RPMVERSION)" \
  245. --define "rpmrelease $(RPMRELEASE)" \
  246. $(EXTRA_RPM_DEFINES) \
  247. -bs rpm-build/$(NAME).spec
  248. @rm -f rpm-build/$(NAME).spec
  249. @echo "#############################################"
  250. @echo "Ansible SRPM is built:"
  251. @echo " rpm-build/$(RPMNVR).src.rpm"
  252. @echo "#############################################"
  253. .PHONY: rpm
  254. rpm: rpmcommon
  255. @rpmbuild --define "_topdir %(pwd)/rpm-build" \
  256. --define "_builddir %{_topdir}" \
  257. --define "_rpmdir %{_topdir}" \
  258. --define "_srcrpmdir %{_topdir}" \
  259. --define "_specdir $(RPMSPECDIR)" \
  260. --define "_sourcedir %{_topdir}" \
  261. --define "_rpmfilename $(RPMNVR).%%{ARCH}.rpm" \
  262. --define "__python `which $(PYTHON)`" \
  263. --define "upstream_version $(VERSION)" \
  264. --define "rpmversion $(RPMVERSION)" \
  265. --define "rpmrelease $(RPMRELEASE)" \
  266. $(EXTRA_RPM_DEFINES) \
  267. -ba rpm-build/$(NAME).spec
  268. @rm -f rpm-build/$(NAME).spec
  269. @echo "#############################################"
  270. @echo "Ansible RPM is built:"
  271. @echo " rpm-build/$(RPMNVR).noarch.rpm"
  272. @echo "#############################################"
  273. .PHONY: debian
  274. debian: sdist
  275. @for DIST in $(DEB_DIST) ; do \
  276. mkdir -p deb-build/$${DIST} ; \
  277. tar -C deb-build/$${DIST} -xvf dist/$(NAME)-$(VERSION).tar.gz ; \
  278. cp -a packaging/debian deb-build/$${DIST}/$(NAME)-$(VERSION)/ ; \
  279. sed -ie "s|%VERSION%|$(DEB_VERSION)|g;s|%RELEASE%|$(DEB_RELEASE)|;s|%DIST%|$${DIST}|g;s|%DATE%|$(DEB_DATE)|g" deb-build/$${DIST}/$(NAME)-$(VERSION)/debian/changelog ; \
  280. done
  281. .PHONY: deb
  282. deb: deb-src
  283. @for DIST in $(DEB_DIST) ; do \
  284. PBUILDER_OPTS="$(PBUILDER_OPTS) --distribution $${DIST} --basetgz $(PBUILDER_CACHE_DIR)/$${DIST}-$(PBUILDER_ARCH)-base.tgz --buildresult $(CURDIR)/deb-build/$${DIST}" ; \
  285. $(PBUILDER_BIN) create $${PBUILDER_OPTS} --othermirror "deb http://archive.ubuntu.com/ubuntu $${DIST} universe" ; \
  286. $(PBUILDER_BIN) update $${PBUILDER_OPTS} ; \
  287. $(PBUILDER_BIN) build $${PBUILDER_OPTS} deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}.dsc ; \
  288. done
  289. @echo "#############################################"
  290. @echo "Ansible DEB artifacts:"
  291. @for DIST in $(DEB_DIST) ; do \
  292. echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
  293. done
  294. @echo "#############################################"
  295. # Build package outside of pbuilder, with locally installed dependencies.
  296. # Install BuildRequires as noted in packaging/debian/control.
  297. .PHONY: local_deb
  298. local_deb: debian
  299. @for DIST in $(DEB_DIST) ; do \
  300. (cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -b) ; \
  301. done
  302. @echo "#############################################"
  303. @echo "Ansible DEB artifacts:"
  304. @for DIST in $(DEB_DIST) ; do \
  305. echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
  306. done
  307. @echo "#############################################"
  308. .PHONY: deb-src
  309. deb-src: debian
  310. @for DIST in $(DEB_DIST) ; do \
  311. (cd deb-build/$${DIST}/$(NAME)-$(VERSION)/ && $(DEBUILD) -S) ; \
  312. done
  313. @echo "#############################################"
  314. @echo "Ansible DEB artifacts:"
  315. @for DIST in $(DEB_DIST) ; do \
  316. echo deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
  317. done
  318. @echo "#############################################"
  319. .PHONY: deb-upload
  320. deb-upload: deb
  321. @for DIST in $(DEB_DIST) ; do \
  322. $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_amd64.changes ; \
  323. done
  324. .PHONY: deb-src-upload
  325. deb-src-upload: deb-src
  326. @for DIST in $(DEB_DIST) ; do \
  327. $(DPUT_BIN) $(DPUT_OPTS) $(DEB_PPA) deb-build/$${DIST}/$(NAME)_$(DEB_VERSION)-$(DEB_RELEASE)~$${DIST}_source.changes ; \
  328. done
  329. .PHONY: epub
  330. epub:
  331. (cd docs/docsite/; CPUS=$(CPUS) $(MAKE) epub)
  332. # for arch or gentoo, read instructions in the appropriate 'packaging' subdirectory directory
  333. .PHONY: webdocs
  334. webdocs:
  335. (cd docs/docsite/; CPUS=$(CPUS) $(MAKE) docs)
  336. .PHONY: generate_rst
  337. generate_rst: lib/ansible/cli/*.py
  338. mkdir -p ./docs/man/man1/ ; \
  339. PYTHONPATH=./lib $(GENERATE_CLI) --template-file=docs/templates/man.j2 --output-dir=docs/man/man1/ --output-format man lib/ansible/cli/*.py
  340. docs: generate_rst
  341. $(MAKE) $(MANPAGES)
  342. .PHONY: alldocs
  343. alldocs: docs webdocs
  344. version:
  345. @echo $(VERSION)