Merge lp:~cjwatson/launchpad-buildd/reduce-arch-hardcoding into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 242
Proposed branch: lp:~cjwatson/launchpad-buildd/reduce-arch-hardcoding
Merge into: lp:launchpad-buildd
Prerequisite: lp:~cjwatson/launchpad-buildd/remove-qemu
Diff against target: 230 lines (+102/-52)
6 files modified
Makefile (+3/-14)
bin/buildlivefs (+3/-2)
bin/buildsnap (+2/-2)
debian/changelog (+2/-0)
lpbuildd/tests/test_util.py (+59/-0)
lpbuildd/util.py (+33/-34)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/reduce-arch-hardcoding
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+328213@code.launchpad.net

Commit message

Remove most architecture hardcoding from lpbuildd.util, relying on
dpkg-architecture instead.

To post a comment you must log in.
236. By Colin Watson

Merge trunk.

237. By Colin Watson

Use test discovery rather than hardcoding a list of test modules.

238. By Colin Watson

Remove most architecture hardcoding from lpbuildd.util, relying on
dpkg-architecture instead.

239. By Colin Watson

Merge trunk.

Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2017-07-28 10:39:50 +0000
3+++ Makefile 2017-07-28 14:08:19 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 all: deb
10@@ -22,16 +22,5 @@
11
12 PYTHON=python
13 check:
14- PYTHONPATH=$(CURDIR):$(PYTHONPATH) $(PYTHON) -m testtools.run -v \
15- lpbuildd.pottery.tests.test_generate_translation_templates \
16- lpbuildd.pottery.tests.test_intltool \
17- lpbuildd.tests.test_binarypackage \
18- lpbuildd.tests.test_buildd_slave \
19- lpbuildd.tests.test_buildrecipe \
20- lpbuildd.tests.test_check_implicit_pointer_functions \
21- lpbuildd.tests.test_debian \
22- lpbuildd.tests.test_harness \
23- lpbuildd.tests.test_livefs \
24- lpbuildd.tests.test_snap \
25- lpbuildd.tests.test_sourcepackagerecipe \
26- lpbuildd.tests.test_translationtemplatesbuildmanager
27+ PYTHONPATH=$(CURDIR):$(PYTHONPATH) $(PYTHON) -m testtools.run \
28+ discover -v
29
30=== modified file 'bin/buildlivefs'
31--- bin/buildlivefs 2017-07-25 22:11:19 +0000
32+++ bin/buildlivefs 2017-07-28 14:08:19 +0000
33@@ -1,5 +1,5 @@
34 #! /usr/bin/python -u
35-# Copyright 2013 Canonical Ltd. This software is licensed under the
36+# Copyright 2013-2017 Canonical Ltd. This software is licensed under the
37 # GNU Affero General Public License version 3 (see the file LICENSE).
38
39 """A script that builds a live file system."""
40@@ -48,7 +48,8 @@
41
42 :param args: the command and arguments to run.
43 """
44- args = set_personality(self.options.arch, args)
45+ args = set_personality(
46+ args, self.options.arch, series=self.options.series)
47 if echo:
48 print("Running in chroot: %s" %
49 ' '.join("'%s'" % arg for arg in args))
50
51=== modified file 'bin/buildsnap'
52--- bin/buildsnap 2017-07-25 22:11:19 +0000
53+++ bin/buildsnap 2017-07-28 14:08:19 +0000
54@@ -1,5 +1,5 @@
55 #! /usr/bin/python -u
56-# Copyright 2015 Canonical Ltd. This software is licensed under the
57+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
58 # GNU Affero General Public License version 3 (see the file LICENSE).
59
60 """A script that builds a snap."""
61@@ -58,7 +58,7 @@
62 :param echo: if True, print the command before executing it.
63 :param get_output: if True, return the output from the command.
64 """
65- args = set_personality(self.options.arch, args)
66+ args = set_personality(args, self.options.arch)
67 if echo:
68 print(
69 "Running in chroot: %s" % ' '.join(
70
71=== modified file 'debian/changelog'
72--- debian/changelog 2017-07-28 11:10:52 +0000
73+++ debian/changelog 2017-07-28 14:08:19 +0000
74@@ -6,6 +6,8 @@
75 ppa:launchpad/ubuntu/ppa (and >= zesty).
76 * Drop qemu emulation support. It was quite unreliable, and we've had
77 real hardware for a while.
78+ * Remove most architecture hardcoding from lpbuildd.util, relying on
79+ dpkg-architecture instead.
80
81 -- Colin Watson <cjwatson@ubuntu.com> Tue, 25 Jul 2017 23:07:58 +0100
82
83
84=== added file 'lpbuildd/tests/test_util.py'
85--- lpbuildd/tests/test_util.py 1970-01-01 00:00:00 +0000
86+++ lpbuildd/tests/test_util.py 2017-07-28 14:08:19 +0000
87@@ -0,0 +1,59 @@
88+# Copyright 2017 Canonical Ltd. This software is licensed under the
89+# GNU Affero General Public License version 3 (see the file LICENSE).
90+
91+__metaclass__ = type
92+
93+from testtools import TestCase
94+
95+from lpbuildd.util import (
96+ get_arch_bits,
97+ set_personality,
98+ shell_escape,
99+ )
100+
101+
102+class TestShellEscape(TestCase):
103+
104+ def test_plain(self):
105+ self.assertEqual("foo", shell_escape("foo"))
106+
107+ def test_whitespace(self):
108+ self.assertEqual("' '", shell_escape(" "))
109+
110+ def test_single_quotes(self):
111+ self.assertEqual("'shell'\\''s great'", shell_escape("shell's great"))
112+
113+
114+class TestGetArchBits(TestCase):
115+
116+ def test_x32(self):
117+ self.assertEqual(64, get_arch_bits("x32"))
118+
119+ def test_32bit(self):
120+ self.assertEqual(32, get_arch_bits("armhf"))
121+ self.assertEqual(32, get_arch_bits("i386"))
122+
123+ def test_64bit(self):
124+ self.assertEqual(64, get_arch_bits("amd64"))
125+ self.assertEqual(64, get_arch_bits("arm64"))
126+
127+
128+class TestSetPersonality(TestCase):
129+
130+ def test_32bit(self):
131+ self.assertEqual(
132+ ["linux32", "sbuild"], set_personality(["sbuild"], "i386"))
133+
134+ def test_64bit(self):
135+ self.assertEqual(
136+ ["linux64", "sbuild"], set_personality(["sbuild"], "amd64"))
137+
138+ def test_uname_26(self):
139+ self.assertEqual(
140+ ["linux64", "--uname-2.6", "sbuild"],
141+ set_personality(["sbuild"], "amd64", series="precise"))
142+
143+ def test_no_uname_26(self):
144+ self.assertEqual(
145+ ["linux64", "sbuild"],
146+ set_personality(["sbuild"], "amd64", series="trusty"))
147
148=== modified file 'lpbuildd/util.py'
149--- lpbuildd/util.py 2015-07-31 11:54:07 +0000
150+++ lpbuildd/util.py 2017-07-28 14:08:19 +0000
151@@ -1,9 +1,10 @@
152-# Copyright 2015 Canonical Ltd. This software is licensed under the
153+# Copyright 2015-2017 Canonical Ltd. This software is licensed under the
154 # GNU Affero General Public License version 3 (see the file LICENSE).
155
156 __metaclass__ = type
157
158 import re
159+import subprocess
160
161
162 non_meta_re = re.compile(r'^[a-zA-Z0-9+,./:=@_-]+$')
163@@ -15,36 +16,34 @@
164 return "'%s'" % arg.replace("'", "'\\''")
165
166
167-linux32_arches = [
168- "armel",
169- "armhf",
170- "hppa",
171- "i386",
172- "lpia",
173- "mips",
174- "mipsel",
175- "powerpc",
176- "s390",
177- "sparc",
178- ]
179-linux64_arches = [
180- "alpha",
181- "amd64",
182- "arm64",
183- "hppa64",
184- "ia64",
185- "ppc64",
186- "ppc64el",
187- "s390x",
188- "sparc64",
189- "x32",
190- ]
191-
192-
193-def set_personality(arch, args):
194- if arch in linux32_arches:
195- return ["linux32"] + args
196- elif arch in linux64_arches:
197- return ["linux64"] + args
198- else:
199- return args
200+def get_arch_bits(arch):
201+ if arch == "x32":
202+ # x32 is an exception: the userspace is 32-bit, but it expects to be
203+ # running on a 64-bit kernel.
204+ return 64
205+ else:
206+ bits = subprocess.check_output(
207+ ["dpkg-architecture", "-a%s" % arch,
208+ "-qDEB_HOST_ARCH_BITS"]).rstrip("\n")
209+ if bits == "32":
210+ return 32
211+ elif bits == "64":
212+ return 64
213+ else:
214+ raise RuntimeError(
215+ "Don't know how to deal with architecture %s "
216+ "(DEB_HOST_ARCH_BITS=%s)" % (arch, bits))
217+
218+
219+def set_personality(args, arch, series=None):
220+ bits = get_arch_bits(arch)
221+ assert bits in (32, 64)
222+ if bits == 32:
223+ setarch_cmd = ["linux32"]
224+ else:
225+ setarch_cmd = ["linux64"]
226+
227+ if series in ("hardy", "lucid", "maverick", "natty", "oneiric", "precise"):
228+ setarch_cmd.append("--uname-2.6")
229+
230+ return setarch_cmd + args

Subscribers

People subscribed via source and target branches

to all changes: