Skip to content

Commit

Permalink
Allow for architecture-specific packages (#876)
Browse files Browse the repository at this point in the history
This makes it possible to instruct snapcraft to only install some
packages on a given architecture or set of architectures.

LP: #1637282

Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber authored and sergiusens committed Nov 9, 2016
1 parent d817b1d commit 9d6f953
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/snapcraft-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ contain.
be staged before the dependent part starts its lifecycle.*
* `stage-packages` (list of strings)
A list of Ubuntu packages to use that would support the part creation.
To restrict to a specific architecture, use `pkg:arch`.
* `build-packages` (list of strings)
A list of Ubuntu packages to be installed on the host to aid in building
the part. These packages will not go into the final snap.
To restrict to a specific architecture, use `pkg:arch`.
* `filesets` (yaml subsection)
A dictionary with filesets, the key being a recognizable user defined
string and its value a list of strings of files to be included or
Expand Down
10 changes: 10 additions & 0 deletions snapcraft/internal/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,18 @@ def get(self, package_names):

def _get(self, apt_cache, package_names):
manifest_dep_names = self._manifest_dep_names(apt_cache)
deb_arch = snapcraft.ProjectOptions().deb_arch

for name in package_names:
fields = name.split(":", 2)
name = fields[0]

# Skip if the architecture doesn't match deb_arch
if len(fields) == 2 and fields[1] != deb_arch:
logger.debug('Skipping {!r} based on architecture filter'
.format(name))
continue

try:
logger.debug('Marking {!r} as to install'.format(name))
apt_cache[name].mark_install()
Expand Down
12 changes: 10 additions & 2 deletions snapcraft/tests/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def test_get_package(self, mock_apt):
project_options = snapcraft.ProjectOptions(
use_geoip=False)
ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options)
ubuntu.get(['fake-package'])
ubuntu.get(['fake-package', 'fake-package-arch1:test',
'fake-package-arch2:%s' % project_options.deb_arch])

mock_apt.assert_has_calls([
call.apt_pkg.config.set('Dir::Cache::Archives',
Expand All @@ -64,7 +65,14 @@ def test_get_package(self, mock_apt):

# __getitem__ is tricky
self.assertIn(
call('fake-package'), mock_apt.Cache().__getitem__.call_args_list)
call('fake-package'),
mock_apt.Cache().__getitem__.call_args_list)
self.assertNotIn(
call('fake-package-arch1'),
mock_apt.Cache().__getitem__.call_args_list)
self.assertIn(
call('fake-package-arch2'),
mock_apt.Cache().__getitem__.call_args_list)

@patch('snapcraft.repo._get_geoip_country_code_prefix')
def test_sources_is_none_uses_default(self, mock_cc):
Expand Down

0 comments on commit 9d6f953

Please sign in to comment.