Merge lp:~cjwatson/click/native-chroots into lp:click/devel

Proposed by Colin Watson
Status: Merged
Approved by: Michael Vogt
Approved revision: 444
Merged at revision: 444
Proposed branch: lp:~cjwatson/click/native-chroots
Merge into: lp:click/devel
Diff against target: 149 lines (+76/-5)
3 files modified
click/chroot.py (+33/-5)
click/tests/test_chroot.py (+38/-0)
debian/changelog (+5/-0)
To merge this branch: bzr merge lp:~cjwatson/click/native-chroots
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+220232@code.launchpad.net

This proposal supersedes a proposal from 2014-05-20.

Commit message

chroot: Handle the case where we can execute binaries for the target architecture directly and thus don't need a cross-compiler (LP: #1319153).

Description of the change

chroot: Handle the case where we can execute binaries for the target architecture directly and thus don't need a cross-compiler (LP: #1319153).

This implements my suggestion from here:

  https://bugs.launchpad.net/ubuntu/+source/click/+bug/1319153/comments/3

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

This looks good!

You may want to consider using amd64 in line 110 in "def test_gen_sources_native(self):" so that line 47,48 is tested (but thats really minor).

review: Approve
Revision history for this message
Michael Vogt (mvo) wrote :

Please ignore my previous comment about the "def test_gen_sources_native(self):". The new test test_gen_sources_native() is testing the new case when native_arch == target_arch and the other cases are already tested.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/chroot.py'
2--- click/chroot.py 2014-05-20 08:59:35 +0000
3+++ click/chroot.py 2014-05-20 11:54:47 +0000
4@@ -132,9 +132,10 @@
5 series = framework_series[self.framework_base]
6 self.series = series
7 self.session = session
8- self.native_arch = subprocess.check_output(
9+ system_arch = subprocess.check_output(
10 ["dpkg", "--print-architecture"],
11 universal_newlines=True).strip()
12+ self.native_arch = self._get_native_arch(system_arch, self.target_arch)
13 self.chroots_dir = "/var/lib/schroot/chroots"
14 # this doesn't work because we are running this under sudo
15 if 'DEBOOTSTRAP_MIRROR' in os.environ:
16@@ -149,6 +150,24 @@
17 self.user = pwd.getpwuid(os.getuid()).pw_name
18 self.dpkg_architecture = self._dpkg_architecture()
19
20+ def _get_native_arch(self, system_arch, target_arch):
21+ """Determine the proper native architecture for a chroot.
22+
23+ Some combinations of system and target architecture do not require
24+ cross-building, so in these cases we just create a chroot suitable
25+ for native building.
26+ """
27+ if (system_arch, target_arch) in (
28+ ("amd64", "i386"),
29+ # This will only work if the system is running a 64-bit
30+ # kernel; but there's no alternative since no i386-to-amd64
31+ # cross-compiler is available in the Ubuntu archive.
32+ ("i386", "amd64"),
33+ ):
34+ return target_arch
35+ else:
36+ return system_arch
37+
38 def _dpkg_architecture(self):
39 dpkg_architecture = {}
40 command = ["dpkg-architecture", "-a%s" % self.target_arch]
41@@ -171,7 +190,10 @@
42 pockets.append('%s-%s' % (series, pocket))
43 sources = []
44 # write binary lines
45- for arch in (target_arch, native_arch):
46+ arches = [target_arch]
47+ if native_arch != target_arch:
48+ arches.append(native_arch)
49+ for arch in arches:
50 if arch not in primary_arches:
51 mirror = ports_mirror
52 else:
53@@ -211,6 +233,13 @@
54 mode = stat.S_IMODE(os.stat(path).st_mode)
55 os.chmod(path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
56
57+ def _make_cross_package(self, prefix):
58+ if self.native_arch == self.target_arch:
59+ return prefix
60+ else:
61+ target_tuple = self.dpkg_architecture["DEB_HOST_GNU_TYPE"]
62+ return "%s-%s" % (prefix, target_tuple)
63+
64 def create(self, keep_broken_chroot_on_fail=False):
65 if self.exists():
66 raise ClickChrootAlreadyExistsException(
67@@ -224,11 +253,10 @@
68 proxy = subprocess.check_output(
69 'unset x; eval "$(apt-config shell x Acquire::HTTP::Proxy)"; echo "$x"',
70 shell=True, universal_newlines=True).strip()
71- target_tuple = self.dpkg_architecture["DEB_HOST_GNU_TYPE"]
72 build_pkgs = [
73 "build-essential", "fakeroot",
74- "apt-utils", "g++-%s" % target_tuple,
75- "pkg-config-%s" % target_tuple, "cmake",
76+ "apt-utils", self._make_cross_package("g++"),
77+ self._make_cross_package("pkg-config"), "cmake",
78 "dpkg-cross", "libc-dev:%s" % self.target_arch
79 ]
80 for package in extra_packages.get(self.framework_base, []):
81
82=== modified file 'click/tests/test_chroot.py'
83--- click/tests/test_chroot.py 2014-05-20 06:30:48 +0000
84+++ click/tests/test_chroot.py 2014-05-20 11:54:47 +0000
85@@ -30,6 +30,18 @@
86
87
88 class TestClickChroot(TestCase):
89+ def test_get_native_arch_amd64_to_amd64(self):
90+ chroot = ClickChroot("amd64", "ubuntu-sdk-14.04", series="trusty")
91+ self.assertEqual("amd64", chroot._get_native_arch("amd64", "amd64"))
92+
93+ def test_get_native_arch_amd64_to_armhf(self):
94+ chroot = ClickChroot("armhf", "ubuntu-sdk-14.04", series="trusty")
95+ self.assertEqual("amd64", chroot._get_native_arch("amd64", "armhf"))
96+
97+ def test_get_native_arch_amd64_to_i386(self):
98+ chroot = ClickChroot("i386", "ubuntu-sdk-14.04", series="trusty")
99+ self.assertEqual("i386", chroot._get_native_arch("amd64", "i386"))
100+
101 def test_gen_sources_archive_only(self):
102 chroot = ClickChroot("amd64", "ubuntu-sdk-13.10", series="trusty")
103 chroot.native_arch = "i386"
104@@ -83,3 +95,29 @@
105 'deb-src http://archive.ubuntu.com/ubuntu trusty-updates main',
106 'deb-src http://archive.ubuntu.com/ubuntu trusty-security main',
107 ], sources)
108+
109+ def test_gen_sources_native(self):
110+ chroot = ClickChroot("i386", "ubuntu-sdk-14.04", series="trusty")
111+ chroot.native_arch = "i386"
112+ sources = chroot._generate_sources(
113+ chroot.series, chroot.native_arch, chroot.target_arch,
114+ "main")
115+ self.assertEqual([
116+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty main',
117+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-updates main',
118+ 'deb [arch=i386] http://archive.ubuntu.com/ubuntu trusty-security main',
119+ 'deb-src http://archive.ubuntu.com/ubuntu trusty main',
120+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-updates main',
121+ 'deb-src http://archive.ubuntu.com/ubuntu trusty-security main',
122+ ], sources)
123+
124+ def test_make_cross_package_native(self):
125+ chroot = ClickChroot("amd64", "ubuntu-sdk-14.04", series="trusty")
126+ chroot.native_arch = "amd64"
127+ self.assertEqual("g++", chroot._make_cross_package("g++"))
128+
129+ def test_make_cross_package_cross(self):
130+ chroot = ClickChroot("armhf", "ubuntu-sdk-14.04", series="trusty")
131+ chroot.native_arch = "amd64"
132+ self.assertEqual(
133+ "g++-arm-linux-gnueabihf", chroot._make_cross_package("g++"))
134
135=== modified file 'debian/changelog'
136--- debian/changelog 2014-05-20 09:02:41 +0000
137+++ debian/changelog 2014-05-20 11:54:47 +0000
138@@ -21,6 +21,11 @@
139 * click chroot creation depends on dpkg-architecture, so recommend
140 dpkg-dev.
141
142+ [ Colin Watson ]
143+ * chroot: Handle the case where we can execute binaries for the target
144+ architecture directly and thus don't need a cross-compiler
145+ (LP: #1319153).
146+
147 -- Colin Watson <cjwatson@ubuntu.com> Thu, 15 May 2014 17:10:58 +0100
148
149 click (0.4.22) utopic; urgency=medium

Subscribers

People subscribed via source and target branches

to all changes: