Merge ~cjwatson/launchpad-buildd:brz-builder into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 89ee2a61cbbafaf791d809238674523028add63b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:brz-builder
Merge into: launchpad-buildd:master
Diff against target: 164 lines (+101/-0)
3 files modified
bin/buildrecipe (+17/-0)
debian/changelog (+2/-0)
lpbuildd/tests/test_buildrecipe.py (+82/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+412287@code.launchpad.net

Commit message

Use brz-build-daily-recipe if it exists

Description of the change

In order to fully support focal, we need to use `brz` rather than `bzr` to support Python 3. Fortunately, `bzr-builder` was already ported upstream as `brz-builder`, so make use of it if it exists.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

As I lack a bit about background on buildd, I compared the new with the existing similar test and the changes look good.

I have not run the tests yet, as I need to setup the environment before.

review: Approve
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/buildrecipe b/bin/buildrecipe
index b447f01..4d04c4f 100755
--- a/bin/buildrecipe
+++ b/bin/buildrecipe
@@ -84,6 +84,21 @@ class RecipeBuilder:
84 """84 """
85 return self.chroot(['apt-get', 'install', '-y', 'lsb-release'])85 return self.chroot(['apt-get', 'install', '-y', 'lsb-release'])
8686
87 # XXX cjwatson 2021-11-23: Use shutil.which instead once we can assume
88 # Python >= 3.3.
89 def _is_command_on_path(self, command):
90 """Is 'command' on the executable search path?"""
91 if "PATH" not in os.environ:
92 return False
93 path = os.environ["PATH"]
94 for element in path.split(os.pathsep):
95 if not element:
96 continue
97 filename = os.path.join(element, command)
98 if os.path.isfile(filename) and os.access(filename, os.X_OK):
99 return True
100 return False
101
87 def buildTree(self):102 def buildTree(self):
88 """Build the recipe into a source tree.103 """Build the recipe into a source tree.
89104
@@ -127,6 +142,8 @@ class RecipeBuilder:
127 }142 }
128 if self.git:143 if self.git:
129 cmd = ['git-build-recipe']144 cmd = ['git-build-recipe']
145 elif self._is_command_on_path('brz-build-daily-recipe'):
146 cmd = ['brz-build-daily-recipe']
130 else:147 else:
131 cmd = ['bzr', '-Derror', 'dailydeb']148 cmd = ['bzr', '-Derror', 'dailydeb']
132 cmd.extend([149 cmd.extend([
diff --git a/debian/changelog b/debian/changelog
index 28df0fc..2eb11a0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,8 @@
1launchpad-buildd (205) UNRELEASED; urgency=medium1launchpad-buildd (205) UNRELEASED; urgency=medium
22
3 * Ignore NotAutomatic flag for -proposed and -backports (LP: #1016776).3 * Ignore NotAutomatic flag for -proposed and -backports (LP: #1016776).
4 * Use brz-build-daily-recipe rather than "bzr -Derror dailydeb" if the
5 former exists (see LP #1943292).
46
5 -- Colin Watson <cjwatson@ubuntu.com> Mon, 29 Nov 2021 16:20:37 +00007 -- Colin Watson <cjwatson@ubuntu.com> Mon, 29 Nov 2021 16:20:37 +0000
68
diff --git a/lpbuildd/tests/test_buildrecipe.py b/lpbuildd/tests/test_buildrecipe.py
index a4da180..2faa985 100644
--- a/lpbuildd/tests/test_buildrecipe.py
+++ b/lpbuildd/tests/test_buildrecipe.py
@@ -16,8 +16,10 @@ import tempfile
16from textwrap import dedent16from textwrap import dedent
1717
18from fixtures import (18from fixtures import (
19 EnvironmentVariable,
19 MockPatch,20 MockPatch,
20 MockPatchObject,21 MockPatchObject,
22 TempDir,
21 )23 )
22import six24import six
23from systemfixtures import FakeProcesses25from systemfixtures import FakeProcesses
@@ -86,6 +88,30 @@ class TestRecipeBuilder(TestCase):
86 self.resetEnvironment()88 self.resetEnvironment()
87 super(TestRecipeBuilder, self).tearDown()89 super(TestRecipeBuilder, self).tearDown()
8890
91 def test_is_command_on_path_missing_environment(self):
92 self.useFixture(EnvironmentVariable("PATH"))
93 self.assertFalse(self.builder._is_command_on_path("ls"))
94
95 def test_is_command_on_path_present_executable(self):
96 temp_dir = self.useFixture(TempDir()).path
97 bin_dir = os.path.join(temp_dir, "bin")
98 os.mkdir(bin_dir)
99 program = os.path.join(bin_dir, "program")
100 with open(program, "w"):
101 pass
102 os.chmod(program, 0o755)
103 self.useFixture(EnvironmentVariable("PATH", bin_dir))
104 self.assertTrue(self.builder._is_command_on_path("program"))
105
106 def test_is_command_on_path_present_not_executable(self):
107 temp_dir = self.useFixture(TempDir()).path
108 bin_dir = os.path.join(temp_dir, "bin")
109 os.mkdir(bin_dir)
110 with open(os.path.join(bin_dir, "program"), "w"):
111 pass
112 self.useFixture(EnvironmentVariable("PATH", bin_dir))
113 self.assertFalse(self.builder._is_command_on_path("program"))
114
89 def test_buildTree_git(self):115 def test_buildTree_git(self):
90 def fake_git(args):116 def fake_git(args):
91 if args["args"][1] == "--version":117 if args["args"][1] == "--version":
@@ -139,6 +165,60 @@ class TestRecipeBuilder(TestCase):
139 """) % repr(expected_recipe_command),165 """) % repr(expected_recipe_command),
140 mock_stdout.getvalue())166 mock_stdout.getvalue())
141167
168 def test_buildTree_brz(self):
169 def fake_bzr(args):
170 if args["args"][1] == "version":
171 print("brz version x.y.z")
172 return {}
173 elif args["args"][1] == "plugins":
174 print("brz-plugin x.y.z")
175 return {}
176 else:
177 return {"returncode": 1}
178
179 def fake_brz_build_daily_recipe(args):
180 print("dummy recipe build")
181 os.makedirs(os.path.join(self.builder.tree_path, "foo"))
182 return {}
183
184 processes_fixture = self.useFixture(FakeProcesses())
185 processes_fixture.add(
186 lambda _: {"stdout": io.StringIO(u"5.10\n")}, name="sudo")
187 processes_fixture.add(fake_bzr, name="bzr")
188 processes_fixture.add(
189 fake_brz_build_daily_recipe, name="brz-build-daily-recipe")
190 with open(os.path.join(self.builder.work_dir, "recipe"), "w") as f:
191 f.write("dummy recipe contents\n")
192 mock_stdout = six.StringIO()
193 self.useFixture(MockPatch("sys.stdout", mock_stdout))
194 self.useFixture(MockPatchObject(
195 self.builder, "_is_command_on_path",
196 side_effect=lambda command: command == "brz-build-daily-recipe"))
197 self.assertEqual(0, self.builder.buildTree())
198 self.assertEqual(
199 os.path.join(self.builder.work_dir_relative, "tree", "foo"),
200 self.builder.source_dir_relative)
201 expected_recipe_command = [
202 "brz-build-daily-recipe", "--safe", "--no-build",
203 "--manifest", os.path.join(self.builder.tree_path, "manifest"),
204 "--distribution", "grumpy", "--allow-fallback-to-native",
205 "--append-version", u"~ubuntu5.10.1",
206 os.path.join(self.builder.work_dir, "recipe"),
207 self.builder.tree_path,
208 ]
209 self.assertEqual(
210 dedent("""\
211 Bazaar versions:
212 brz version x.y.z
213 brz-plugin x.y.z
214 Building recipe:
215 dummy recipe contents
216
217 RUN %s
218 dummy recipe build
219 """) % repr(expected_recipe_command),
220 mock_stdout.getvalue())
221
142 def test_buildTree_bzr(self):222 def test_buildTree_bzr(self):
143 def fake_bzr(args):223 def fake_bzr(args):
144 if args["args"][1] == "version":224 if args["args"][1] == "version":
@@ -162,6 +242,8 @@ class TestRecipeBuilder(TestCase):
162 f.write("dummy recipe contents\n")242 f.write("dummy recipe contents\n")
163 mock_stdout = six.StringIO()243 mock_stdout = six.StringIO()
164 self.useFixture(MockPatch("sys.stdout", mock_stdout))244 self.useFixture(MockPatch("sys.stdout", mock_stdout))
245 self.useFixture(MockPatchObject(
246 self.builder, "_is_command_on_path", return_value=False))
165 self.assertEqual(0, self.builder.buildTree())247 self.assertEqual(0, self.builder.buildTree())
166 self.assertEqual(248 self.assertEqual(
167 os.path.join(self.builder.work_dir_relative, "tree", "foo"),249 os.path.join(self.builder.work_dir_relative, "tree", "foo"),

Subscribers

People subscribed via source and target branches