Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pluginhandler: support more complex stage-packages. (#1059)
Currently snapcraft only supports a flat list of stage packages to be staged regardless of target architecture. This commit introduces a more complex grammar that allows one to filter stage packages depending on various selectors (target arch for right now), as well as specify optional packages. The grammar is made up of two statements: `on` and `try`. - on <selector>[,<selector>...] - ... - else[ fail]: - ... The body of the `on` clause is taken into account if every (AND, not OR) selector is true for the target build environment. Currently the only selectors supported are target architectures (e.g. amd64). If the `on` clause doesn't match and it's immediately followed by an `else` clause, the `else` clause must be satisfied. An `on` clause without an `else` clause is considered satisfied even if no selector matched. The `else fail` form allows erroring out if an `on` clause was not matched. - try: - ... - else: - ... The body of the `try` clause is taken into account only when all packages contained within it are valid. If not, if it's immediately followed by `else` clauses they are tried in order, and one of them must be satisfied. A `try` clause with no `else` clause is considered satisfied even if it contains invalid packages. LP: #1637282 Signed-off-by: Kyle Fazzari <kyle@canonical.com>
- Loading branch information
1 parent
49b39ef
commit 9e00ffc
Showing
26 changed files
with
1,732 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
integration_tests/snaps/stage-package-grammar/snapcraft.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: stage-package-grammar | ||
version: '0.1' | ||
summary: Test the stage package grammar | ||
description: A few different parts that exercise the grammar differently | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
simple: | ||
plugin: nil | ||
stage-packages: | ||
- hello | ||
|
||
try: | ||
plugin: nil | ||
stage-packages: | ||
- try: | ||
- hello | ||
|
||
try-skipped: | ||
plugin: nil | ||
stage-packages: | ||
- try: | ||
- invalid-package | ||
|
||
try-else: | ||
plugin: nil | ||
stage-packages: | ||
- try: | ||
- invalid-package | ||
- else: | ||
- hello | ||
|
||
on-other-arch: | ||
plugin: nil | ||
stage-packages: | ||
- on other-arch: | ||
- foo | ||
|
||
on-other-arch-else: | ||
plugin: nil | ||
stage-packages: | ||
- on other-arch: | ||
- foo | ||
- else: | ||
- hello | ||
|
||
on-other-arch-else-fail: | ||
plugin: nil | ||
stage-packages: | ||
- on other-arch: | ||
- foo | ||
- else fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2017 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import os | ||
import subprocess | ||
|
||
import integration_tests | ||
from testtools.matchers import ( | ||
Contains, | ||
FileExists, | ||
Not | ||
) | ||
|
||
|
||
class StagePackageGrammarTestCase(integration_tests.TestCase): | ||
|
||
def test_simple(self): | ||
"""Test that 'simple' fetches stage package.""" | ||
|
||
self.run_snapcraft(['prime', 'simple'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
FileExists()) | ||
|
||
def test_try(self): | ||
"""Test that 'try' fetches stage package.""" | ||
|
||
self.run_snapcraft(['prime', 'try'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
FileExists()) | ||
|
||
def test_try_skipped(self): | ||
"""Test that 'try-skipped' fetches nothing.""" | ||
|
||
self.run_snapcraft(['prime', 'try-skipped'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
Not(FileExists())) | ||
|
||
def test_try_else(self): | ||
"""Test that 'try-else' fetches stage package.""" | ||
|
||
self.run_snapcraft(['prime', 'try-else'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
FileExists()) | ||
|
||
def test_on_other_arch(self): | ||
"""Test that 'on-other-arch' fetches nothing.""" | ||
|
||
self.run_snapcraft(['prime', 'on-other-arch'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
Not(FileExists())) | ||
|
||
def test_on_other_arch_else(self): | ||
"""Test that 'on-other-arch-else' fetches stage package.""" | ||
|
||
self.run_snapcraft( | ||
['prime', 'on-other-arch-else'], 'stage-package-grammar') | ||
|
||
self.assertThat( | ||
os.path.join('prime', 'usr', 'bin', 'hello'), | ||
FileExists()) | ||
|
||
def test_on_other_arch_else_fail(self): | ||
"""Test that 'on-other-arch-else-fail' fails with an error.""" | ||
|
||
exception = self.assertRaises( | ||
subprocess.CalledProcessError, self.run_snapcraft, | ||
['prime', 'on-other-arch-else-fail'], 'stage-package-grammar') | ||
|
||
self.assertThat(exception.output, Contains( | ||
"Unable to satisfy 'on other-arch', failure forced")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.