← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:charm-fix-build-path into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:charm-fix-build-path into launchpad-buildd:master.

Commit message:
Fix gathering the output of charm recipe builds that use --build-path

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Charm recipe builds have a "build path" option that allows configuring them to run `charmcraft` in a subdirectory of the project rather than in the project root.  This mostly worked, except that the build manager tried to gather output files from the wrong place.  Fix it to gather from the appropriate subdirectory in this case.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:charm-fix-build-path into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index 2dc69b1..3b85725 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ launchpad-buildd (210) UNRELEASED; urgency=medium
     lucid.
   * Make more loop device nodes available in LXD containers (LP: #1963706).
   * Drop pre-Python-3.6 code using pyupgrade.
+  * Fix gathering the output of charm recipe builds that use --build-path.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Mon, 28 Feb 2022 11:27:20 +0000
 
diff --git a/lpbuildd/charm.py b/lpbuildd/charm.py
index 11c7a5a..d8fc402 100644
--- a/lpbuildd/charm.py
+++ b/lpbuildd/charm.py
@@ -90,6 +90,8 @@ class CharmBuildManager(BuildManagerProxyMixin, DebianBuildManager):
     def gatherResults(self):
         """Gather the results of the build and add them to the file cache."""
         output_path = os.path.join("/home/buildd", self.name)
+        if self.build_path is not None:
+            output_path = os.path.join(output_path, self.build_path)
         if self.backend.path_exists(output_path):
             for entry in sorted(self.backend.listdir(output_path)):
                 path = os.path.join(output_path, entry)
diff --git a/lpbuildd/tests/test_charm.py b/lpbuildd/tests/test_charm.py
index ed2e1d0..72b4e0c 100644
--- a/lpbuildd/tests/test_charm.py
+++ b/lpbuildd/tests/test_charm.py
@@ -148,6 +148,59 @@ class TestCharmBuildManagerIteration(TestCase):
             self.buildmanager.iterate, self.buildmanager.iterators[-1])
         self.assertFalse(self.builder.wasCalled("buildFail"))
 
+    @defer.inlineCallbacks
+    def test_iterate_build_path(self):
+        # The build manager iterates a build using build_path from start to
+        # finish.
+        args = {
+            "git_repository": "https://git.launchpad.dev/~example/+git/charm";,
+            "git_path": "master",
+            "build_path": "charm",
+            }
+        expected_options = [
+            "--git-repository",
+            "https://git.launchpad.dev/~example/+git/charm";,
+            "--git-path", "master",
+            "--build-path", "charm",
+            ]
+        yield self.startBuild(args, expected_options)
+
+        log_path = os.path.join(self.buildmanager._cachepath, "buildlog")
+        with open(log_path, "w") as log:
+            log.write("I am a build log.")
+
+        self.buildmanager.backend.add_file(
+            "/home/buildd/test-charm/charm/test-charm_0_all.charm",
+            b"I am charming.")
+
+        # After building the package, reap processes.
+        yield self.buildmanager.iterate(0)
+        expected_command = [
+            "sharepath/bin/in-target", "in-target", "scan-for-processes",
+            "--backend=lxd", "--series=xenial", "--arch=i386", self.buildid,
+            ]
+
+        self.assertEqual(CharmBuildState.BUILD_CHARM, self.getState())
+        self.assertEqual(expected_command, self.buildmanager.commands[-1])
+        self.assertNotEqual(
+            self.buildmanager.iterate, self.buildmanager.iterators[-1])
+        self.assertFalse(self.builder.wasCalled("buildFail"))
+        self.assertThat(self.builder, HasWaitingFiles.byEquality({
+            "test-charm_0_all.charm": b"I am charming.",
+            }))
+
+        # Control returns to the DebianBuildManager in the UMOUNT state.
+        self.buildmanager.iterateReap(self.getState(), 0)
+        expected_command = [
+            "sharepath/bin/in-target", "in-target", "umount-chroot",
+            "--backend=lxd", "--series=xenial", "--arch=i386", self.buildid,
+            ]
+        self.assertEqual(CharmBuildState.UMOUNT, self.getState())
+        self.assertEqual(expected_command, self.buildmanager.commands[-1])
+        self.assertEqual(
+            self.buildmanager.iterate, self.buildmanager.iterators[-1])
+        self.assertFalse(self.builder.wasCalled("buildFail"))
+
     @mock.patch('lpbuildd.proxy.urlopen')
     def test_revokeProxyToken(self, urlopen_mock):
         self.buildmanager.revocation_endpoint = "http://revoke_endpoint";