Merge lp:~ericsnowcurrently/fake-juju/makefile-tweaks into lp:~landscape/fake-juju/trunk-old

Proposed by Eric Snow
Status: Merged
Approved by: Eric Snow
Approved revision: 37
Merged at revision: 36
Proposed branch: lp:~ericsnowcurrently/fake-juju/makefile-tweaks
Merge into: lp:~landscape/fake-juju/trunk-old
Diff against target: 169 lines (+93/-57)
1 file modified
Makefile (+93/-57)
To merge this branch: bzr merge lp:~ericsnowcurrently/fake-juju/makefile-tweaks
Reviewer Review Type Date Requested Status
Free Ekanayaka (community) Approve
Chad Smith Approve
🤖 Landscape Builder test results Approve
Review via email: mp+306506@code.launchpad.net

Commit message

Refactor Makefile to support targeting a single version.

This patch also adds the "install-dev" target.

Description of the change

Refactor Makefile to support targeting a single version.

This patch also adds the "install-dev" target.

Testing instructions:

Run each of the make targets, with and without JUJU_VERSION set.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-test
Result: Success
Revno: 37
Branch: lp:~ericsnowcurrently/fake-juju/makefile-tweaks
Jenkins: https://ci.lscape.net/job/latch-test-xenial/10/

review: Approve (test results)
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

I'm a bit confused, it seems the makefile already supports targeting single versions? E.g.:

JUJU_VERSION=1.25.6 make build-common

Already does the right thing in trunk.

Not sure what I'm missing.

review: Needs Information
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

Yes, you could do it before. However, it wasn't very clear. Now the version-specific case is much clearer.

Revision history for this message
Chad Smith (chad.smith) wrote :

I like the changes as-is as it feels like a slight improvement, we can tweak as we need to.
The looping construct over "all" targets seems to exit too quickly (@1.24.7) if nothing is needed for that target.

If I run initially make all targets, make changes to 2.0.X, the subsequent make attempt will exit early upon first noop success without trying to build 1.25 or 2.0 targets

make: '1.24.7/1.24.7' is up to date.

review: Approve
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

I find it a bit odd to have those "duplicate" targets with a different implementation depending on whether JUJU_VERSION is set or not. Personally, I'd find more natural to have a JUJU_VERSIONS environment variable instead, that should be set to a space or comma separated list of versions you want to build, that defaults to all versions. This will both make the Makefile more natural and allow you to possibly build not only one specific version but also more than one version. If you want to keep the JUJU_VERSION variable, you could add support for that by making JUJU_VERSIONS=$(JUJU_VERSION) if it's set.

All in all, I'm fine with the idea of the branch, but find the implementation a bit convoluted.

I'm keeping the N/I vote to see what you think of the above, but since it's all relatively minor, I'll be fine if you want to keep the implementation like it.s

Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

@chad.smith, could you give me explicit steps to reproduce? I tried:

1. make build
2. rm 1.25.6/1.25.6
3. make build

and it did the right thing.

Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

@free.ekanayaka, we have to accommodate the "$(JUJU_VERSION)/$(JUJU_VERSION)" case as a target to leverage "make" properly. So Makefile must handle both the single and the multiple cases separately. Makefile would definitely be simpler if that were not the case.

Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

@eric: hmm, I didn't dig but my impression is that "$(JUJU_VERSION)/$(JUJU_VERSION)" is just an internal naming detail. I believe you could name it $(VERSION)/$(VERSION) and set VERSION as appropriate and have it all working as described (i.e. single-version would be a particular case of multi-version, not a case on its own). Anyway, it's a minor detail as long as it works and you're happy enough with it (exp. from a code maintenance point of view), so +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2016-09-15 20:06:25 +0000
3+++ Makefile 2016-09-22 15:58:27 +0000
4@@ -1,24 +1,103 @@
5+JUJUCLIENT_DOWNLOADS = $(shell pwd)/tests/jujuclient-archive
6+JUJUCLIENT_REQ = $(JUJUCLIENT_DOWNLOADS)/requirements
7+
8+
9+ifdef JUJU_VERSION #############################
10+# for one version
11+
12+GO_VERSION = 1.6
13+JUJU_TARBALL = juju-core_$(JUJU_VERSION).tar.gz
14+JUJU_PATCH = patches/juju-core_$(JUJU_VERSION).patch
15+INSTALLDIR = $(DESTDIR)/usr/bin
16+INSTALLED = $(INSTALLDIR)/fake-juju-$(JUJU_VERSION)
17+
18+$(JUJU_VERSION)/$(JUJU_VERSION):
19+ case $(JUJU_VERSION) in \
20+ 1.*) $(MAKE) build-common PATH=$$PATH JUJU_VERSION=$(JUJU_VERSION) ;;\
21+ 2.*) $(MAKE) build-common PATH=/usr/lib/go-$(GO_VERSION)/bin:$$PATH JUJU_VERSION=$(JUJU_VERSION) ;;\
22+ esac
23+
24+juju-core_%.tar.gz:
25+ case $* in \
26+ 1.*) PROJECT="juju-core" ;;\
27+ 2.*) PROJECT="juju" ;;\
28+ esac;\
29+ wget https://launchpad.net/$$PROJECT/$(shell (echo $* | cut -f 1 -d - | cut -f 1,2 -d .))/$*/+download/$@
30+
31+.PHONY: build
32+build: $(JUJU_VERSION)/$(JUJU_VERSION)
33+
34+.PHONY: build-common
35+build-common: $(JUJU_TARBALL) $(JUJU_PATCH)
36+ rm -rf $(JUJU_VERSION)/src # Go doesn't play nice with existing files.
37+ tar -C $(JUJU_VERSION) --strip=1 -z -xf $(JUJU_TARBALL)
38+ patch -p0 < $(JUJU_PATCH)
39+ cd $(JUJU_VERSION) && GOPATH=$(shell pwd)/$(JUJU_VERSION) PATH=$(PATH) go build
40+
41+.PHONY: install
42+install: $(JUJU_VERSION)/$(JUJU_VERSION)
43+ install -D $(JUJU_VERSION)/$(JUJU_VERSION) $(INSTALLED)
44+
45+.PHONY: install-dev
46+install-dev: $(JUJU_VERSION)/$(JUJU_VERSION)
47+ mkdir -p $(INSTALLDIR)
48+ ln -s --backup=existing --suffix .orig $(shell pwd)/$(JUJU_VERSION)/$(JUJU_VERSION) $(INSTALLED)
49+
50+.PHONY: clean
51+clean:
52+ rm -f $(JUJU_TARBALL)
53+ rm -rf $(JUJU_VERSION)/src
54+ rm -f $(JUJU_VERSION)/$(JUJU_VERSION)
55+ rm -rf _trial_temp
56+ rm -f tests/*.pyc
57+
58+.PHONY: test
59+test: $(JUJU_VERSION)/$(JUJU_VERSION)
60+ env JUJU_VERSION=$(JUJU_VERSION) python3 -m unittest tests.test_fake
61+
62+
63+else ###########################################
64+# for all versions
65+
66 JUJU1_VERSIONS = 1.24.7 1.25.6
67 JUJU2_VERSIONS = 2.0-beta17
68 VERSIONS = $(JUJU1_VERSIONS) $(JUJU2_VERSIONS)
69-GO_VERSION = 1.6
70-TARBALLS = $(foreach version,$(VERSIONS),juju-core_$(version).tar.gz)
71 BUILT_VERSIONS = $(foreach version,$(VERSIONS),$(version)/$(version))
72-JUJU_TARBALL = juju-core_$(JUJU_VERSION).tar.gz
73-JUJU_PATCH = patches/juju-core_$(JUJU_VERSION).patch
74-JUJUCLIENT_DOWNLOADS = $(shell pwd)/tests/jujuclient-archive
75-JUJUCLIENT_REQ = $(JUJUCLIENT_DOWNLOADS)/requirements
76+
77+$(BUILT_VERSIONS):
78+ for VERSION in $(VERSIONS); do \
79+ $(MAKE) build JUJU_VERSION=$$VERSION; \
80+ done
81
82 .PHONY: build
83 build: $(BUILT_VERSIONS)
84
85-$(BUILT_VERSIONS):
86- for VERSION in $(JUJU1_VERSIONS); do \
87- $(MAKE) build-common PATH=$$PATH JUJU_VERSION=$$VERSION; \
88- done
89- for VERSION in $(JUJU2_VERSIONS); do \
90- $(MAKE) build-common PATH=/usr/lib/go-$(GO_VERSION)/bin:$$PATH JUJU_VERSION=$$VERSION; \
91- done
92+.PHONY: install
93+install:
94+ for VERSION in $(VERSIONS); do \
95+ $(MAKE) install JUJU_VERSION=$$VERSION; \
96+ done
97+
98+.PHONY: install-dev
99+install-dev:
100+ for VERSION in $(VERSIONS); do \
101+ $(MAKE) install-dev JUJU_VERSION=$$VERSION; \
102+ done
103+
104+.PHONY: clean
105+clean:
106+ for VERSION in $(VERSIONS) ; do \
107+ $(MAKE) clean JUJU_VERSION=$$VERSION; \
108+ done
109+
110+.PHONY: test
111+# Use xargs here so that we don't throw away the return codes, and correctly fail if any of the tests fail
112+test: $(BUILT_VERSIONS)
113+ #@echo -n $(VERSIONS) | xargs -t -d' ' -I {} env JUJU_VERSION={} python3 -m unittest tests.test_fake
114+ @echo -n $(VERSIONS) | xargs -t -d' ' -I {} $(MAKE) test JUJU_VERSION={}
115+
116+
117+endif ##########################################
118
119 .PHONY: ci-test
120 ci-test:
121@@ -34,47 +113,4 @@
122 --no-index \
123 --find-links $(JUJUCLIENT_DOWNLOADS) \
124 --requirement $(JUJUCLIENT_REQ)
125- make test
126-
127-.PHONY: build-common
128-build-common: $(JUJU_TARBALL) $(JUJU_PATCH)
129- rm -rf $(JUJU_VERSION)/src # Go doesn't play nice with existing files.
130- tar -C $(JUJU_VERSION) --strip=1 -z -xf $(JUJU_TARBALL)
131- patch -p0 < $(JUJU_PATCH)
132- cd $(JUJU_VERSION) && GOPATH=$(shell pwd)/$(JUJU_VERSION) PATH=$(PATH) go build
133-
134-.PHONY: install
135-install:
136- for VERSION in $(VERSIONS); do \
137- $(MAKE) install-common JUJU_VERSION=$$VERSION; \
138- done
139-
140-.PHONY: install-common
141-install-common: $(JUJU_VERSION)/$(JUJU_VERSION)
142- install -D $(JUJU_VERSION)/$(JUJU_VERSION) $(DESTDIR)/usr/bin/fake-juju-$(JUJU_VERSION)
143-
144-.PHONY: clean
145-clean:
146- for VERSION in $(VERSIONS) ; do \
147- JUJU_VERSION=$$VERSION make clean-common; \
148- done
149-
150-.PHONY: clean-common
151-clean-common:
152- rm -f $(JUJU_TARBALL)
153- rm -rf $(JUJU_VERSION)/src
154- rm -f $(JUJU_VERSION)/$(JUJU_VERSION)
155- rm -rf _trial_temp
156- rm -f tests/*.pyc
157-
158-.PHONY: test
159-# Use xargs here so that we don't throw away the return codes, and correctly fail if any of the tests fail
160-test: $(BUILT_VERSIONS)
161- @echo -n $(VERSIONS) | xargs -t -d' ' -I {} env JUJU_VERSION={} python3 -m unittest tests.test_fake
162-
163-juju-core_%.tar.gz:
164- case $* in \
165- 1.*) PROJECT="juju-core" ;;\
166- 2.*) PROJECT="juju" ;;\
167- esac;\
168- wget https://launchpad.net/$$PROJECT/$(shell (echo $* | cut -f 1 -d - | cut -f 1,2 -d .))/$*/+download/$@
169+ $(MAKE) test

Subscribers

People subscribed via source and target branches

to all changes: