Merge lp:~cjwatson/click/native-dpkg-architecture into lp:click/devel

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 458
Merged at revision: 464
Proposed branch: lp:~cjwatson/click/native-dpkg-architecture
Merge into: lp:click/devel
Diff against target: 92 lines (+46/-0)
3 files modified
click/chroot.py (+8/-0)
click/tests/test_chroot.py (+34/-0)
debian/changelog (+4/-0)
To merge this branch: bzr merge lp:~cjwatson/click/native-dpkg-architecture
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+222691@code.launchpad.net

This proposal supersedes a proposal from 2014-06-10.

Commit message

Fix DEB_BUILD_* environment variables when building on amd64 for i386 (LP: #1328486).

Description of the change

When we're building on amd64 for i386 using "click chroot run", we override the native architecture to i386, but at the moment we don't fix up DEB_BUILD_* to match. That causes various problems such as cmake trying to use the wrong path to moc.

It doesn't appear to be possible to tell dpkg-architecture to use a different build architecture, short of supplying a mock "dpkg --print-architecture", which seems rather fragile. However, since we read its output and export it ourselves anyway, and we only need to worry about the case where the build and host architectures are being forced to be equal, we can just substitute DEB_HOST_* as DEB_BUILD_*.

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

Thanks Colin, this looks fine, I just have one inline comment about the tests.

review: Approve
458. By Colin Watson

Mock "dpkg --print-architecture" so that we can select different native architectures in tests.

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-22 09:56:13 +0000
3+++ click/chroot.py 2014-06-10 17:42:09 +0000
4@@ -212,6 +212,14 @@
5 except ValueError:
6 continue
7 dpkg_architecture[key] = value
8+ if self.native_arch == self.target_arch:
9+ # We may have overridden the native architecture (see
10+ # _get_native_arch above), so we need to force DEB_BUILD_* to
11+ # match.
12+ for key in list(dpkg_architecture):
13+ if key.startswith("DEB_HOST_"):
14+ new_key = "DEB_BUILD_" + key[len("DEB_HOST_"):]
15+ dpkg_architecture[new_key] = dpkg_architecture[key]
16 return dpkg_architecture
17
18 def _generate_sources(self, series, native_arch, target_arch, components):
19
20=== modified file 'click/tests/test_chroot.py'
21--- click/tests/test_chroot.py 2014-05-20 11:52:16 +0000
22+++ click/tests/test_chroot.py 2014-06-10 17:42:09 +0000
23@@ -23,6 +23,10 @@
24 ]
25
26
27+import os
28+import subprocess
29+from textwrap import dedent
30+
31 from click.tests.helpers import TestCase
32 from click.chroot import (
33 ClickChroot,
34@@ -30,6 +34,18 @@
35
36
37 class TestClickChroot(TestCase):
38+ def set_dpkg_native_architecture(self, arch):
39+ """Fool dpkg-architecture into selecting a given native arch."""
40+ self.use_temp_dir()
41+ dpkg_script_path = os.path.join(self.temp_dir, "dpkg")
42+ with open(dpkg_script_path, "w") as dpkg_script:
43+ print(dedent("""\
44+ #! /bin/sh
45+ echo %s
46+ """) % arch, file=dpkg_script)
47+ os.chmod(dpkg_script_path, 0o755)
48+ os.environ["PATH"] = "%s:%s" % (self.temp_dir, os.environ["PATH"])
49+
50 def test_get_native_arch_amd64_to_amd64(self):
51 chroot = ClickChroot("amd64", "ubuntu-sdk-14.04", series="trusty")
52 self.assertEqual("amd64", chroot._get_native_arch("amd64", "amd64"))
53@@ -42,6 +58,24 @@
54 chroot = ClickChroot("i386", "ubuntu-sdk-14.04", series="trusty")
55 self.assertEqual("i386", chroot._get_native_arch("amd64", "i386"))
56
57+ def test_dpkg_architecture_amd64_to_armhf(self):
58+ self.set_dpkg_native_architecture("amd64")
59+ chroot = ClickChroot("armhf", "ubuntu-sdk-14.04", series="trusty")
60+ self.assertEqual("amd64", chroot.dpkg_architecture["DEB_BUILD_ARCH"])
61+ self.assertEqual("armhf", chroot.dpkg_architecture["DEB_HOST_ARCH"])
62+
63+ def test_dpkg_architecture_i386_to_armhf(self):
64+ self.set_dpkg_native_architecture("i386")
65+ chroot = ClickChroot("armhf", "ubuntu-sdk-14.04", series="trusty")
66+ self.assertEqual("i386", chroot.dpkg_architecture["DEB_BUILD_ARCH"])
67+ self.assertEqual("armhf", chroot.dpkg_architecture["DEB_HOST_ARCH"])
68+
69+ def test_dpkg_architecture_amd64_to_i386(self):
70+ self.set_dpkg_native_architecture("amd64")
71+ chroot = ClickChroot("i386", "ubuntu-sdk-14.04", series="trusty")
72+ self.assertEqual("i386", chroot.dpkg_architecture["DEB_BUILD_ARCH"])
73+ self.assertEqual("i386", chroot.dpkg_architecture["DEB_HOST_ARCH"])
74+
75 def test_gen_sources_archive_only(self):
76 chroot = ClickChroot("amd64", "ubuntu-sdk-13.10", series="trusty")
77 chroot.native_arch = "i386"
78
79=== modified file 'debian/changelog'
80--- debian/changelog 2014-06-10 17:18:00 +0000
81+++ debian/changelog 2014-06-10 17:42:09 +0000
82@@ -4,6 +4,10 @@
83 * Add basic integration tests, run via autopkgtest.
84 * Add coverage testing.
85
86+ [ Colin Watson ]
87+ * Fix DEB_BUILD_* environment variables when building on amd64 for i386
88+ (LP: #1328486).
89+
90 -- Colin Watson <cjwatson@ubuntu.com> Mon, 09 Jun 2014 11:02:39 +0100
91
92 click (0.4.25) utopic; urgency=medium

Subscribers

People subscribed via source and target branches

to all changes: