Merge ~andrey-fedoseev/launchpad-buildd:snap-target-architectures into launchpad-buildd:master

Proposed by Andrey Fedoseev
Status: Merged
Approved by: Andrey Fedoseev
Approved revision: 454638aeec17a6d3c4a5f2bd070e680697cff214
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~andrey-fedoseev/launchpad-buildd:snap-target-architectures
Merge into: launchpad-buildd:master
Diff against target: 125 lines (+59/-0)
5 files modified
debian/changelog (+8/-0)
lpbuildd/snap.py (+4/-0)
lpbuildd/target/build_snap.py (+8/-0)
lpbuildd/target/tests/test_build_snap.py (+18/-0)
lpbuildd/tests/test_snap.py (+21/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+424145@code.launchpad.net

Commit message

Allow specifying target architectures for snaps

The list of target architectures is passed as an extra argument to `SnapBuildManager`

At the moment, we use only the first architecture from the list as
snapcraft doesn't allow multi-arch at the moment.

The target architecture is passed to `snapcraft` via
`SNAPCRAFT_BUILD_TO` env variable

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

Please remember to add a `debian/changelog` entry before you merge this.

Revision history for this message
Andrey Fedoseev (andrey-fedoseev) wrote :

Colin,

Does the `debian/changelog` entry look right?

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

AFAIK, if there is only one contributor for any given version, it is not necessary to repeat the name in the brackets.

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

It's fine with or without the bit in brackets.

review: Approve

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 b63d1f8..fbd0d9a 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,11 @@
6+launchpad-buildd (216) UNRELEASED; urgency=medium
7+
8+ [ Andrey Fedoseev ]
9+ * Allow specifying target architecture for snaps via
10+ SNAPCRAFT_BUILD_TO environment variable
11+
12+ -- Andrey Fedoseev <andrey.fedoseev@canonical.com> Mon, 27 Jun 2022 12:32:05 +0500
13+
14 launchpad-buildd (215) focal; urgency=medium
15
16 [ Jürgen Gmach ]
17diff --git a/lpbuildd/snap.py b/lpbuildd/snap.py
18index 8d1d2c6..720b1d8 100644
19--- a/lpbuildd/snap.py
20+++ b/lpbuildd/snap.py
21@@ -51,6 +51,7 @@ class SnapBuildManager(BuildManagerProxyMixin, DebianBuildManager):
22 "build_source_tarball", False)
23 self.private = extra_args.get("private", False)
24 self.proxy_service = None
25+ self.target_architectures = extra_args.get("target_architectures")
26
27 super().initiate(files, chroot, extra_args)
28
29@@ -85,6 +86,9 @@ class SnapBuildManager(BuildManagerProxyMixin, DebianBuildManager):
30 args.extend(["--snap-store-proxy-url", snap_store_proxy_url])
31 except (NoSectionError, NoOptionError):
32 pass
33+ if self.target_architectures:
34+ for arch in self.target_architectures:
35+ args.extend(["--target-arch", arch])
36 args.append(self.name)
37 self.runTargetSubProcess("buildsnap", *args)
38
39diff --git a/lpbuildd/target/build_snap.py b/lpbuildd/target/build_snap.py
40index a4930b8..5fdfcc8 100644
41--- a/lpbuildd/target/build_snap.py
42+++ b/lpbuildd/target/build_snap.py
43@@ -71,6 +71,12 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
44 parser.add_argument(
45 "--private", default=False, action="store_true",
46 help="build a private snap")
47+ parser.add_argument(
48+ "--target-arch",
49+ dest="target_architectures",
50+ action="append",
51+ help="build for the specified architectures"
52+ )
53 parser.add_argument("name", help="name of snap to build")
54
55 def install_svn_servers(self):
56@@ -179,6 +185,8 @@ class BuildSnap(BuilderProxyOperationMixin, VCSOperationMixin,
57 env["SNAPCRAFT_BUILD_INFO"] = "1"
58 env["SNAPCRAFT_IMAGE_INFO"] = self.image_info
59 env["SNAPCRAFT_BUILD_ENVIRONMENT"] = "host"
60+ if self.args.target_architectures:
61+ env["SNAPCRAFT_BUILD_TO"] = self.args.target_architectures[0]
62 self.run_build_command(
63 ["snapcraft"],
64 cwd=os.path.join("/build", self.args.name),
65diff --git a/lpbuildd/target/tests/test_build_snap.py b/lpbuildd/target/tests/test_build_snap.py
66index d9025eb..c625abe 100644
67--- a/lpbuildd/target/tests/test_build_snap.py
68+++ b/lpbuildd/target/tests/test_build_snap.py
69@@ -473,6 +473,24 @@ class TestBuildSnap(TestCase):
70 SNAPCRAFT_BUILD_ENVIRONMENT="host"),
71 ]))
72
73+ def test_build_target_architectures(self):
74+ args = [
75+ "buildsnap",
76+ "--backend=fake", "--series=xenial", "--arch=amd64", "1",
77+ "--branch", "lp:foo",
78+ "--target-arch", "i386",
79+ "--target-arch", "amd64",
80+ "test-snap",
81+ ]
82+ build_snap = parse_args(args=args).operation
83+ build_snap.build()
84+ self.assertThat(build_snap.backend.run.calls, MatchesListwise([
85+ RanBuildCommand(
86+ ["snapcraft"], cwd="/build/test-snap",
87+ SNAPCRAFT_BUILD_INFO="1", SNAPCRAFT_IMAGE_INFO="{}",
88+ SNAPCRAFT_BUILD_ENVIRONMENT="host", SNAPCRAFT_BUILD_TO="i386"),
89+ ]))
90+
91 # XXX cjwatson 2017-08-07: Test revoke_token. It may be easiest to
92 # convert it to requests first.
93
94diff --git a/lpbuildd/tests/test_snap.py b/lpbuildd/tests/test_snap.py
95index 59f0446..c2bce38 100644
96--- a/lpbuildd/tests/test_snap.py
97+++ b/lpbuildd/tests/test_snap.py
98@@ -446,6 +446,27 @@ class TestSnapBuildManagerIteration(TestCase):
99 "--snap-store-proxy-url", "http://snap-store-proxy.example/"]
100 yield self.startBuild(options=expected_options)
101
102+ @defer.inlineCallbacks
103+ def test_iterate_target_architectures(self):
104+ args = {
105+ "build_request_id": 13,
106+ "build_request_timestamp": "2018-04-13T14:50:02Z",
107+ "build_url": "https://launchpad.example/build",
108+ "git_repository": "https://git.launchpad.dev/~example/+git/snap",
109+ "git_path": "master",
110+ "target_architectures": ["i386", "amd64"],
111+ }
112+ expected_options = [
113+ "--build-request-id", "13",
114+ "--build-request-timestamp", "2018-04-13T14:50:02Z",
115+ "--build-url", "https://launchpad.example/build",
116+ "--git-repository", "https://git.launchpad.dev/~example/+git/snap",
117+ "--git-path", "master",
118+ "--target-arch", "i386",
119+ "--target-arch", "amd64",
120+ ]
121+ yield self.startBuild(args, expected_options)
122+
123 def getListenerURL(self, listener):
124 port = listener.getHost().port
125 return "http://localhost:%d/" % port

Subscribers

People subscribed via source and target branches