← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:recipe-create-homedir into launchpad-buildd:master.

Commit message:
sourcepackagerecipe: Create /home/buildd inside chroot if necessary

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/451464

Recently-built chroots for mantic no longer include /home/buildd.  This is probably a reasonable cleanup, but it broke recipe builds.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:recipe-create-homedir into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 0bdad53..fd9125d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+launchpad-buildd (235) UNRELEASED; urgency=medium
+
+  * sourcepackagerecipe: Create /home/buildd inside the chroot if it doesn't
+    already exist.
+
+ -- Colin Watson <cjwatson@xxxxxxxxxx>  Fri, 15 Sep 2023 17:30:59 +0100
+
 launchpad-buildd (234) focal; urgency=medium
 
   [ Colin Watson ]
diff --git a/lpbuildd/sourcepackagerecipe.py b/lpbuildd/sourcepackagerecipe.py
index 250c3b5..83dfa60 100644
--- a/lpbuildd/sourcepackagerecipe.py
+++ b/lpbuildd/sourcepackagerecipe.py
@@ -6,6 +6,7 @@
 
 import os
 import re
+import subprocess
 
 from lpbuildd.builder import get_build_path
 from lpbuildd.debian import DebianBuildManager, DebianBuildState
@@ -17,19 +18,6 @@ RETCODE_FAILURE_INSTALL_BUILD_DEPS = 202
 RETCODE_FAILURE_BUILD_SOURCE_PACKAGE = 203
 
 
-def splat_file(path, contents):
-    """Write a string to the specified path.
-
-    :param path: The path to store the string in.
-    :param contents: The string to write to the file.
-    """
-    file_obj = open(path, "w")
-    try:
-        file_obj.write(contents)
-    finally:
-        file_obj.close()
-
-
 def get_chroot_path(home, build_id, *extra):
     """Return a path within the chroot.
 
@@ -81,9 +69,26 @@ class SourcePackageRecipeBuildManager(DebianBuildManager):
 
     def doRunBuild(self):
         """Run the build process to build the source package."""
-        os.makedirs(get_chroot_path(self.home, self._buildid, "work"))
-        recipe_path = get_chroot_path(self.home, self._buildid, "work/recipe")
-        splat_file(recipe_path, self.recipe_text)
+        work_dir = os.path.join(os.environ["HOME"], "work")
+        self.backend.run(["mkdir", "-p", work_dir])
+        # buildrecipe currently needs to be able to write directly to the
+        # work directory.  (That directory needs to be inside the chroot so
+        # that buildrecipe can run dpkg-buildpackage on it from inside the
+        # chroot.)
+        subprocess.run(
+            [
+                "sudo",
+                "chown",
+                "-R",
+                "buildd:",
+                get_chroot_path(self.home, self._buildid, "work"),
+            ],
+            check=True,
+        )
+        with self.backend.open(
+            os.path.join(work_dir, "recipe"), "w"
+        ) as recipe_file:
+            recipe_file.write(self.recipe_text)
         args = ["buildrecipe"]
         if self.git:
             args.append("--git")