Merge lp:~benji/charmworld/makefile-tweaks into lp:~juju-jitsu/charmworld/trunk

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: 352
Merged at revision: 382
Proposed branch: lp:~benji/charmworld/makefile-tweaks
Merge into: lp:~juju-jitsu/charmworld/trunk
Diff against target: 210 lines (+71/-47)
1 file modified
Makefile (+71/-47)
To merge this branch: bzr merge lp:~benji/charmworld/makefile-tweaks
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+184105@code.launchpad.net

Commit message

Several tweaks to the Makefile:

- added a debugging tool at the top (normally commented out)
- removed some single-use and tiny constants in favor of less indirection
- added "canaries" to several rules so they are only run when needed
- wrapped long lines
- added a dependency on requirements.txt so that changes will trigger a
  re-install of Python dependencies
- made a test script (bin/test) so we don't have to remember the
  spelling to invoke the tests outside of the Makefile (preserving the
  existing make targets for continuity, especially for CI)
- removed some unnecessary phoney entries
- added "install" as the default goal
- removed unneeded indirection in phoney definition

As a result of the above you can run just "make" in a new checkout and
everything will be built. If "make" is run again, no work will be
done. There is also now a bin/test script that is friendlier than
having to remember the spelling to invoke the test runner (directly or
through the Makefile, but that still works too).

Description of the change

Several tweaks to the Makefile:

- added a debugging tool at the top (normally commented out)
- removed some single-use and tiny constants in favor of less indirection
- added "canaries" to several rules so they are only run when needed
- wrapped long lines
- added a dependency on requirements.txt so that changes will trigger a
  re-install of Python dependencies
- made a test script (bin/test) so we don't have to remember the
  spelling to invoke the tests outside of the Makefile (preserving the
  existing make targets for continuity, especially for CI)
- removed some unnecessary phoney entries
- added "install" as the default goal
- removed unneeded indirection in phoney definition

As a result of the above you can run just "make" in a new checkout and
everything will be built. If "make" is run again, no work will be
done. There is also now a bin/test script that is friendlier than
having to remember the spelling to invoke the test runner (directly or
through the Makefile, but that still works too).

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Thanks, this behaves much nicer and with bin/test i can get rid of my ./tr.sh script! :)

Do you know how the charmworld charm invokes make for production? I see 'install' depends on 'develop' ... is that appropriate for the production environment?

review: Approve (code)
Revision history for this message
Benji York (benji) wrote :

> Do you know how the charmworld charm invokes make for production?

That's a good question, let me look...

> I see
> 'install' depends on 'develop' ... is that appropriate for the production
> environment?

Yep, the charm uses "make install" which previously depended on charmworld.egg-info, but that was replaced with "deploy", so we should be good there.

Revision history for this message
Charmworld Lander (charmworld-lander) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2013-08-05 20:16:49 +0000
3+++ Makefile 2013-09-05 13:40:44 +0000
4@@ -1,11 +1,15 @@
5+# Makefile debugging hack: uncomment the two lines below and make will tell you
6+# more about what is happening. The output generated is of the form
7+# "FILE:LINE [TARGET (DEPENDENCIES) (NEWER)]" where DEPENDENCIES are all the
8+# things TARGET depends on and NEWER are all the files that are newer than
9+# TARGET. DEPENDENCIES will be colored green and NEWER will be blue.
10+#OLD_SHELL := $(SHELL)
11+#SHELL = $(warning [$@ ($^) ($?) ])$(OLD_SHELL)
12+
13 WD := $(shell pwd)
14-PY := bin/python
15-FLAKE8 := bin/flake8
16-PIP := bin/pip
17 CACHE := download-cache/dist
18 CSS_PATH := charmworld/static/css
19 LESSC := node_modules/less/bin/lessc
20-NOSE := INI="test.ini" bin/nosetests
21 PSERVE := bin/pserve
22 SYSTEM_DEPS := \
23 build-essential bzr charm-tools libyaml-dev python-dev python-virtualenv\
24@@ -36,27 +40,27 @@
25 # INSTALL targets
26 # ###############
27
28-install: charmworld.egg-info
29-
30-venv: bin/python
31+bin/pip:
32+ virtualenv .
33
34 bin/python:
35 virtualenv .
36
37-# Made PHONY so that setup.py develop is rerun to include new entry point for
38-# mongo sessions.
39-.PHONY: charmworld.egg-info
40-charmworld.egg-info: deps bin/python $(INI) charmworld/static/css/theme.css
41- $(PY) setup.py develop
42-
43-bin/es-update: $(PY)
44- $(PY) setup.py develop
45-
46-es_update:
47- bin/es-update
48+# We use a "canary" file to tell us if the charmworld package has been
49+# installed in "develop" mode.
50+DEVELOP_CANARY := lib/__develop_canary
51+develop: $(DEVELOP_CANARY)
52+$(DEVELOP_CANARY): | bin/python
53+ bin/python setup.py develop
54+ touch $(DEVELOP_CANARY)
55+
56+install: deps bin/python bin/pip $(INI) develop css bin/test
57+
58+bin/es-update: bin/python
59+ bin/python setup.py develop
60
61 clean_venv:
62- - rm -r bin include lib local
63+ rm -rf bin include lib local
64
65 css: charmworld/static/css/theme.css
66 charmworld/static/css/theme.css: $(LESSC) $(CSS_PATH)/theme.less $(CSS_PATH)/variables.less
67@@ -66,7 +70,8 @@
68 sudo add-apt-repository -y ppa:juju/pkgs
69 sudo add-apt-repository -y ppa:ce-orange-squad/experimental
70 sudo apt-get update
71- sudo apt-get install -y $(SYSTEM_DEPS) mongodb-server elasticsearch-java;
72+ sudo apt-get install -y $(SYSTEM_DEPS) mongodb-server \
73+ elasticsearch-java;
74 # On quantal need to provide node bin for deps to work.
75 if test ! -e /usr/bin/node; \
76 then - sudo ln -s /usr/bin/nodejs /usr/bin/node; \
77@@ -75,33 +80,54 @@
78 deploy_sysdeps:
79 sudo apt-get install -y $(SYSTEM_DEPS) mongodb-clients;
80
81-deps: venv
82+# We use a "canary" file to tell us if the Python packages have been installed.
83+PYTHON_PACKAGE_CANARY := lib/python2.7/site-packages/___canary
84+python-deps: $(PYTHON_PACKAGE_CANARY)
85+$(PYTHON_PACKAGE_CANARY): requirements.txt | bin/pip
86 if test -d download-cache; \
87- then bzr up download-cache; \
88- else bzr checkout lp:~juju-jitsu/charmworld/download-cache; \
89+ then : bzr up download-cache; \
90+ else bzr checkout lp:~juju-jitsu/charmworld/download-cache; \
91 fi
92- $(PIP) install --no-index --no-dependencies --find-links file:///$(WD)/$(CACHE) -r requirements.txt
93+ bin/pip install --no-index --no-dependencies --find-links \
94+ file:///$(WD)/$(CACHE) -r requirements.txt
95+ touch $(PYTHON_PACKAGE_CANARY)
96+
97+# We use a "canary" file to tell us if the Node packages have been installed.
98+NODE_CANARY := node_modules/___canary
99+node-deps: $(NODE_CANARY)
100+$(NODE_CANARY):
101 npm install download-cache/npm/ycssmin.tar.gz
102 npm install download-cache/npm/less.tar.gz
103- - rm -r build
104- - rm -r share;
105+ rm -rf build
106+ rm -rf share
107+ touch $(NODE_CANARY)
108+
109+deps: python-deps node-deps
110+
111
112 # ###################
113 # Development helpers
114 # ###################
115
116-test: test.ini $(INI) bin/nosetests
117- $(NOSE) charmworld
118-
119-testid: test.ini bin/nosetests
120+bin/nosetests: python-deps
121+
122+bin/test: | test.ini $(INI) bin/nosetests
123+ echo "#!/bin/sh" > $@
124+ echo INI="test.ini" bin/nosetests '$$@' >> $@
125+ chmod +x $@
126+
127+test: bin/test
128+ bin/test
129+
130+testid: bin/test
131 # Run specific nose id tests.
132 # To set up the index you must run `make testid` once to completion to
133 # setup the index. Then you can run a group of tests like:
134 # Call with `ID="3 5" make testid`
135- $(NOSE) -v -s -x --with-id $(ID) charmworld
136+ bin/test -v -s -x --with-id $(ID) charmworld
137
138-testdebug: test.ini bin/nosetests
139- $(NOSE) --with-id --pdb --pdb-failures charmworld
140+testdebug: bin/test
141+ bin/test --with-id --pdb --pdb-failures charmworld
142
143 check: clear_ini clean sysdeps install testid
144
145@@ -124,7 +150,8 @@
146 doc-upload: doc
147 scp -r docs/_build/html/* people.canonical.com:/home/rharding/public_html/charmworld
148
149-run: $(INI) charmworld/static/css/theme.css es_update
150+run: $(INI) charmworld/static/css/theme.css bin/es_update
151+ bin/es-update
152 $(PSERVE) --reload --monitor-restart $(INI)
153
154 start_supervisor:
155@@ -146,26 +173,28 @@
156 bin/supervisorctl -c charmworld/jobs/supervisord.conf status ingest
157
158 clean:
159- find . -type f -name '*.py[co]' -print0 | xargs -r0 $(RM)
160- find . -type f -name '*~' -print0 | xargs -r0 $(RM)
161+ find . -type f -name '*.py[co]' -print0 | xargs -r0 rm -rf
162+ find . -type f -name '*~' -print0 | xargs -r0 rm -rf
163+ rm -rf node_modules
164
165 clear_ini:
166- - rm -f charmworld.ini
167+ rm -f charmworld.ini
168
169 distclean: clean clean_venv
170- $(RM) tags TAGS .installed.cfg
171+ rm -rf tags TAGS .installed.cfg lib
172+
173
174
175 #
176 # Phony stuff.
177 #
178-define phony_targets
179+define phony
180 check
181 css
182 clean_venv
183 clean
184- deploy
185 deps
186+ develop
187 distclean
188 doc
189 doc-open
190@@ -176,18 +205,13 @@
191 tags
192 test
193 testid
194- venv
195- start_supervisord
196- stop_supervisord
197 start_worker
198 stop_worker
199 worker_status
200 endef
201
202-define phony
203- $(phony_targets)
204-endef
205-
206 phony := $(sort $(strip $(phony)))
207
208 .PHONY: $(phony)
209+
210+.DEFAULT_GOAL := install

Subscribers

People subscribed via source and target branches