Merge lp:~cjwatson/launchpad-buildd/git-recipes into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 187
Proposed branch: lp:~cjwatson/launchpad-buildd/git-recipes
Merge into: lp:launchpad-buildd
Diff against target: 239 lines (+75/-28)
4 files modified
buildrecipe (+51/-22)
debian/changelog (+2/-0)
lpbuildd/sourcepackagerecipe.py (+7/-3)
lpbuildd/tests/test_sourcepackagerecipe.py (+15/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/git-recipes
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+281680@code.launchpad.net

Commit message

Use git-build-recipe to run git-based recipe builds (LP: #1453022).

Description of the change

Use git-build-recipe to run git-based recipe builds.

git-build-recipe is in ppa:cjwatson/launchpad, and will need to be copied into the appropriate PPAs and installed via the launchpad-buildd-image-modifier charm before this is deployed. It still needs various bits of work, but it works well enough for simple recipes.

The Launchpad webapp will also need to be taught about git-based recipes.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
188. By Colin Watson

Print git-build-recipe version.

189. By Colin Watson

Merge trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'buildrecipe'
2--- buildrecipe 2015-07-04 14:29:24 +0000
3+++ buildrecipe 2016-01-18 11:41:14 +0000
4@@ -7,6 +7,7 @@
5 __metaclass__ = type
6
7
8+from optparse import OptionParser
9 import os
10 import pwd
11 import socket
12@@ -15,6 +16,7 @@
13 Popen,
14 call,
15 check_call,
16+ check_output,
17 )
18 import sys
19 from textwrap import dedent
20@@ -47,13 +49,16 @@
21 """Builds a package from a recipe."""
22
23 def __init__(self, build_id, author_name, author_email,
24- suite, distroseries_name, component, archive_purpose):
25+ suite, distroseries_name, component, archive_purpose,
26+ git=False):
27 """Constructor.
28
29 :param build_id: The id of the build (a str).
30 :param author_name: The name of the author (a str).
31 :param author_email: The email address of the author (a str).
32 :param suite: The suite the package should be built for (a str).
33+ :param git: If True, build a git-based recipe; if False, build a
34+ bzr-based recipe.
35 """
36 self.build_id = build_id
37 self.author_name = author_name.decode('utf-8')
38@@ -62,7 +67,7 @@
39 self.component = component
40 self.distroseries_name = distroseries_name
41 self.suite = suite
42- self.base_branch = None
43+ self.git = git
44 self.chroot_path = get_build_path(build_id, 'chroot-autobuild')
45 self.work_dir_relative = os.environ['HOME'] + '/work'
46 self.work_dir = os.path.join(self.chroot_path,
47@@ -86,7 +91,7 @@
48 """Build the recipe into a source tree.
49
50 As a side-effect, sets self.source_dir_relative.
51- :return: a retcode from `bzr dailydeb`.
52+ :return: a retcode from `bzr dailydeb` or `git-build-recipe`.
53 """
54 assert not os.path.exists(self.tree_path)
55 recipe_path = os.path.join(self.work_dir, 'recipe')
56@@ -99,16 +104,23 @@
57 # As of bzr 2.2, a defined identity is needed. In this case, we're
58 # using buildd@<hostname>.
59 hostname = socket.gethostname()
60- bzr_email = 'buildd@%s' % hostname
61+ email = 'buildd@%s' % hostname
62 lsb_release = Popen(['/usr/bin/sudo',
63 '/usr/sbin/chroot', self.chroot_path, 'lsb_release',
64 '-r', '-s'], stdout=PIPE)
65 distroseries_version = lsb_release.communicate()[0].rstrip()
66 assert lsb_release.returncode == 0
67
68- print 'Bazaar versions:'
69- check_call(['bzr', 'version'])
70- check_call(['bzr', 'plugins'])
71+ if self.git:
72+ print 'Git version:'
73+ check_call(['git', '--version'])
74+ print check_output(
75+ ['dpkg-query', '-W', 'git-build-recipe']).rstrip(
76+ '\n').replace('\t', ' ')
77+ else:
78+ print 'Bazaar versions:'
79+ check_call(['bzr', 'version'])
80+ check_call(['bzr', 'plugins'])
81
82 print 'Building recipe:'
83 print recipe
84@@ -116,17 +128,22 @@
85 env = {
86 'DEBEMAIL': self.author_email,
87 'DEBFULLNAME': self.author_name.encode('utf-8'),
88- 'BZR_EMAIL': bzr_email,
89+ 'EMAIL': email,
90 'LANG': 'C.UTF-8',
91 }
92- retcode = call_report_rusage([
93- 'bzr',
94- '-Derror',
95- 'dailydeb', '--safe', '--no-build', recipe_path,
96- self.tree_path, '--manifest', manifest_path,
97+ if self.git:
98+ cmd = ['git-build-recipe']
99+ else:
100+ cmd = ['bzr', '-Derror', 'dailydeb']
101+ cmd.extend([
102+ '--safe', '--no-build',
103+ '--manifest', manifest_path,
104 '--distribution', self.distroseries_name,
105- '--allow-fallback-to-native', '--append-version',
106- '~ubuntu%s.1' % distroseries_version], env=env)
107+ '--allow-fallback-to-native',
108+ '--append-version', '~ubuntu%s.1' % distroseries_version,
109+ recipe_path, self.tree_path,
110+ ])
111+ retcode = call_report_rusage(cmd, env=env)
112 if retcode != 0:
113 return retcode
114 (source,) = [name for name in os.listdir(self.tree_path)
115@@ -295,14 +312,26 @@
116 os.environ["HOME"], "build-" + build_id, *extra)
117
118
119-if __name__ == '__main__':
120- builder = RecipeBuilder(*sys.argv[1:])
121+def main():
122+ parser = OptionParser(usage=(
123+ "usage: %prog BUILD-ID AUTHOR-NAME AUTHOR-EMAIL SUITE "
124+ "DISTROSERIES-NAME COMPONENT ARCHIVE-PURPOSE"))
125+ parser.add_option(
126+ "--git", default=False, action="store_true",
127+ help="build a git recipe (default: bzr)")
128+ options, args = parser.parse_args()
129+
130+ builder = RecipeBuilder(*args, git=options.git)
131 if builder.install() != 0:
132- sys.exit(RETCODE_FAILURE_INSTALL)
133+ return RETCODE_FAILURE_INSTALL
134 if builder.buildTree() != 0:
135- sys.exit(RETCODE_FAILURE_BUILD_TREE)
136+ return RETCODE_FAILURE_BUILD_TREE
137 if builder.installBuildDeps() != 0:
138- sys.exit(RETCODE_FAILURE_INSTALL_BUILD_DEPS)
139+ return RETCODE_FAILURE_INSTALL_BUILD_DEPS
140 if builder.buildSourcePackage() != 0:
141- sys.exit(RETCODE_FAILURE_BUILD_SOURCE_PACKAGE)
142- sys.exit(RETCODE_SUCCESS)
143+ return RETCODE_FAILURE_BUILD_SOURCE_PACKAGE
144+ return RETCODE_SUCCESS
145+
146+
147+if __name__ == '__main__':
148+ sys.exit(main())
149
150=== modified file 'debian/changelog'
151--- debian/changelog 2016-01-05 17:48:42 +0000
152+++ debian/changelog 2016-01-18 11:41:14 +0000
153@@ -8,6 +8,8 @@
154 /etc/launchpad-buildd/default.
155 * Try to load the nbd module when starting launchpad-buildd
156 (LP: #1531171).
157+ * buildrecipe: Add option parsing framework.
158+ * Use git-build-recipe to run git-based recipe builds (LP: #1453022).
159
160 -- Colin Watson <cjwatson@ubuntu.com> Mon, 16 Nov 2015 18:12:29 +0000
161
162
163=== modified file 'lpbuildd/sourcepackagerecipe.py'
164--- lpbuildd/sourcepackagerecipe.py 2015-05-11 05:39:25 +0000
165+++ lpbuildd/sourcepackagerecipe.py 2016-01-18 11:41:14 +0000
166@@ -76,6 +76,7 @@
167 self.author_email = extra_args['author_email']
168 self.archive_purpose = extra_args['archive_purpose']
169 self.distroseries_name = extra_args['distroseries_name']
170+ self.git = extra_args.get('git', False)
171
172 super(SourcePackageRecipeBuildManager, self).initiate(
173 files, chroot, extra_args)
174@@ -85,10 +86,13 @@
175 os.makedirs(get_chroot_path(self.home, self._buildid, 'work'))
176 recipe_path = get_chroot_path(self.home, self._buildid, 'work/recipe')
177 splat_file(recipe_path, self.recipe_text)
178- args = [
179- "buildrecipe", self._buildid, self.author_name.encode('utf-8'),
180+ args = ["buildrecipe"]
181+ if self.git:
182+ args.append("--git")
183+ args.extend([
184+ self._buildid, self.author_name.encode('utf-8'),
185 self.author_email, self.suite, self.distroseries_name,
186- self.component, self.archive_purpose]
187+ self.component, self.archive_purpose])
188 self.runSubProcess(self.build_recipe_path, args)
189
190 def iterate_BUILD_RECIPE(self, retcode):
191
192=== modified file 'lpbuildd/tests/test_sourcepackagerecipe.py'
193--- lpbuildd/tests/test_sourcepackagerecipe.py 2015-05-11 05:55:24 +0000
194+++ lpbuildd/tests/test_sourcepackagerecipe.py 2016-01-18 11:41:14 +0000
195@@ -54,7 +54,7 @@
196 """Retrieve build manager's state."""
197 return self.buildmanager._state
198
199- def startBuild(self):
200+ def startBuild(self, git=False):
201 # The build manager's iterate() kicks off the consecutive states
202 # after INIT.
203 extra_args = {
204@@ -73,6 +73,8 @@
205 'ubuntu main',
206 ],
207 }
208+ if git:
209+ extra_args['git'] = True
210 self.buildmanager.initiate({}, 'chroot.tar.gz', extra_args)
211
212 # Skip states that are done in DebianBuildManager to the state
213@@ -84,10 +86,14 @@
214 self.assertEqual(
215 SourcePackageRecipeBuildState.BUILD_RECIPE, self.getState())
216 expected_command = [
217- 'sharepath/slavebin/buildrecipe', 'buildrecipe', self.buildid,
218+ 'sharepath/slavebin/buildrecipe', 'buildrecipe']
219+ if git:
220+ expected_command.append('--git')
221+ expected_command.extend([
222+ self.buildid,
223 'Steve\u1234'.encode('utf-8'), 'stevea@example.org',
224 'maverick', 'maverick', 'universe', 'puppies',
225- ]
226+ ])
227 self.assertEqual(expected_command, self.buildmanager.commands[-1])
228 self.assertEqual(
229 self.buildmanager.iterate, self.buildmanager.iterators[-1])
230@@ -213,3 +219,9 @@
231 self.assertEqual(expected_command, self.buildmanager.commands[-1])
232 self.assertEqual(
233 self.buildmanager.iterate, self.buildmanager.iterators[-1])
234+
235+ def test_iterate_git(self):
236+ # Starting a git-based recipe build passes the correct option. (The
237+ # rest of the build is identical to bzr-based recipe builds from the
238+ # build manager's point of view.)
239+ self.startBuild(git=True)

Subscribers

People subscribed via source and target branches

to all changes: