Merge ~cjwatson/launchpad-buildd:recipe-create-homedir into launchpad-buildd:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: f41cce57db2eacc2542d7f4c2c6eaca8ff31b2c8
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad-buildd:recipe-create-homedir
Merge into: launchpad-buildd:master
Diff against target: 130 lines (+52/-16)
3 files modified
debian/changelog (+7/-0)
lpbuildd/sourcepackagerecipe.py (+21/-16)
lpbuildd/tests/test_sourcepackagerecipe.py (+24/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+451464@code.launchpad.net

Commit message

sourcepackagerecipe: Create /home/buildd inside chroot if necessary

Description of the change

Recently-built chroots for mantic no longer include /home/buildd. This is probably a reasonable cleanup, but it broke recipe builds.

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

Could you please share your thoughts why you did not add an extra test?

review: Approve
5d290dd... by Colin Watson

Update tests for creating /home/buildd

f41cce5... by Colin Watson

Simplify comment slightly

Revision history for this message
Colin Watson (cjwatson) wrote :

Er, oops, apparently I hadn't run the tests at all! I've sorted out tests now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 0bdad53..fd9125d 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+launchpad-buildd (235) UNRELEASED; urgency=medium
7+
8+ * sourcepackagerecipe: Create /home/buildd inside the chroot if it doesn't
9+ already exist.
10+
11+ -- Colin Watson <cjwatson@ubuntu.com> Fri, 15 Sep 2023 17:30:59 +0100
12+
13 launchpad-buildd (234) focal; urgency=medium
14
15 [ Colin Watson ]
16diff --git a/lpbuildd/sourcepackagerecipe.py b/lpbuildd/sourcepackagerecipe.py
17index 250c3b5..00db21a 100644
18--- a/lpbuildd/sourcepackagerecipe.py
19+++ b/lpbuildd/sourcepackagerecipe.py
20@@ -6,6 +6,7 @@
21
22 import os
23 import re
24+import subprocess
25
26 from lpbuildd.builder import get_build_path
27 from lpbuildd.debian import DebianBuildManager, DebianBuildState
28@@ -17,19 +18,6 @@ RETCODE_FAILURE_INSTALL_BUILD_DEPS = 202
29 RETCODE_FAILURE_BUILD_SOURCE_PACKAGE = 203
30
31
32-def splat_file(path, contents):
33- """Write a string to the specified path.
34-
35- :param path: The path to store the string in.
36- :param contents: The string to write to the file.
37- """
38- file_obj = open(path, "w")
39- try:
40- file_obj.write(contents)
41- finally:
42- file_obj.close()
43-
44-
45 def get_chroot_path(home, build_id, *extra):
46 """Return a path within the chroot.
47
48@@ -81,9 +69,26 @@ class SourcePackageRecipeBuildManager(DebianBuildManager):
49
50 def doRunBuild(self):
51 """Run the build process to build the source package."""
52- os.makedirs(get_chroot_path(self.home, self._buildid, "work"))
53- recipe_path = get_chroot_path(self.home, self._buildid, "work/recipe")
54- splat_file(recipe_path, self.recipe_text)
55+ work_dir = os.path.join(os.environ["HOME"], "work")
56+ self.backend.run(["mkdir", "-p", work_dir])
57+ # buildrecipe needs to be able to write directly to the work
58+ # directory. (That directory needs to be inside the chroot so that
59+ # buildrecipe can run dpkg-buildpackage on it from inside the
60+ # chroot.)
61+ subprocess.run(
62+ [
63+ "sudo",
64+ "chown",
65+ "-R",
66+ "buildd:",
67+ get_chroot_path(self.home, self._buildid, "work"),
68+ ],
69+ check=True,
70+ )
71+ with self.backend.open(
72+ os.path.join(work_dir, "recipe"), "w"
73+ ) as recipe_file:
74+ recipe_file.write(self.recipe_text)
75 args = ["buildrecipe"]
76 if self.git:
77 args.append("--git")
78diff --git a/lpbuildd/tests/test_sourcepackagerecipe.py b/lpbuildd/tests/test_sourcepackagerecipe.py
79index ca14223..4ff7004 100644
80--- a/lpbuildd/tests/test_sourcepackagerecipe.py
81+++ b/lpbuildd/tests/test_sourcepackagerecipe.py
82@@ -6,6 +6,7 @@ import shutil
83 import tempfile
84 from textwrap import dedent
85
86+from systemfixtures import FakeProcesses
87 from testtools import TestCase
88 from testtools.deferredruntest import AsynchronousDeferredRunTest
89 from twisted.internet import defer
90@@ -83,17 +84,40 @@ class TestSourcePackageRecipeBuildManagerIteration(TestCase):
91 }
92 if git:
93 extra_args["git"] = True
94+ original_backend_name = self.buildmanager.backend_name
95+ self.buildmanager.backend_name = "fake"
96 self.buildmanager.initiate({}, "chroot.tar.gz", extra_args)
97+ self.buildmanager.backend_name = original_backend_name
98
99 # Skip states that are done in DebianBuildManager to the state
100 # directly before BUILD_RECIPE.
101 self.buildmanager._state = SourcePackageRecipeBuildState.UPDATE
102
103 # BUILD_RECIPE: Run the builder's payload to build the source package.
104+ processes_fixture = self.useFixture(FakeProcesses())
105+ processes_fixture.add(lambda _: {}, name="sudo")
106 yield self.buildmanager.iterate(0)
107 self.assertEqual(
108 SourcePackageRecipeBuildState.BUILD_RECIPE, self.getState()
109 )
110+ self.assertEqual(
111+ [(["mkdir", "-p", os.path.join(os.environ["HOME"], "work")],)],
112+ self.buildmanager.backend.run.extract_args(),
113+ )
114+ self.assertEqual(
115+ [
116+ [
117+ "sudo",
118+ "chown",
119+ "-R",
120+ "buildd:",
121+ os.path.join(
122+ self.chrootdir, os.environ["HOME"][1:], "work"
123+ ),
124+ ]
125+ ],
126+ [proc._args["args"] for proc in processes_fixture.procs],
127+ )
128 expected_command = ["sharepath/bin/buildrecipe", "buildrecipe"]
129 if git:
130 expected_command.append("--git")

Subscribers

People subscribed via source and target branches