-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
project: introduce build-snaps #1518
Changes from all commits
c4a835a
e2add95
cff356b
9e7897e
3f756d9
bc658cf
f4fec13
c9449ae
bb00790
6c48791
b7189e1
01fd337
ff6a36d
9e76582
6a20af3
5060e0d
0a2831d
d806dd7
0efff71
f9129d1
a211b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: build-snap-grammar-fail | ||
version: '0.1' | ||
summary: Test build snap grammar failures | ||
description: Make sure the build snap grammar handles `else fail` as expected | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- on other-arch: | ||
- foo | ||
- else fail |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: build-snap-grammar-on-else | ||
version: '0.1' | ||
summary: Test build snap grammar on statement else | ||
description: Verify that the on statement moves to else on other architectures | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- on other-arch: | ||
- foo | ||
- else: | ||
- hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: build-snap-grammar-on | ||
version: '0.1' | ||
summary: Test build snap grammar on statement | ||
description: Verify that the on statement skips other architecture branches | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- on other-arch: | ||
- hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: build-snap-grammar-try-else | ||
version: '0.1' | ||
summary: Test build snap grammar try statement else | ||
description: Verify that the try statement moves to the else if invalid | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- try: | ||
- invalid-snap | ||
- else: | ||
- hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: build-snap-grammar-try | ||
version: '0.1' | ||
summary: Test build snap grammar try statement | ||
description: Verify that the try statement results in an optional build snap | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- try: | ||
- invalid-snap |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: build-snap-grammar-try | ||
version: '0.1' | ||
summary: Test build snap grammar try statement | ||
description: Verify that the try statement results in an optional build snap | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- try: | ||
- hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: build-snap-grammar | ||
version: '0.1' | ||
summary: Test the build snap grammar | ||
description: Simple, standalone build-snap | ||
grade: devel | ||
confinement: strict | ||
|
||
parts: | ||
my-part: | ||
plugin: nil | ||
build-snaps: | ||
- hello |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# -*- 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 fileinput | ||
import subprocess | ||
|
||
import testscenarios | ||
from testtools.matchers import Contains, Equals | ||
|
||
import integration_tests | ||
import snapcraft | ||
|
||
|
||
def _construct_scenarios(): | ||
main_scenarios = { | ||
'build-snap-grammar': True, | ||
'build-snap-grammar-try': True, | ||
'build-snap-grammar-try-skip': False, | ||
'build-snap-grammar-try-else': True, | ||
'build-snap-grammar-on': False, | ||
'build-snap-grammar-on-else': True, | ||
} | ||
|
||
# Just some combinations | ||
channel_scenarios = [ | ||
'', '/stable', '/latest/stable'] | ||
|
||
all_scenarios = [] | ||
for project, expected_install in main_scenarios.items(): | ||
for channel in channel_scenarios: | ||
d = dict(project=project, hello_installed=expected_install, | ||
channel=channel) | ||
scenario = ('{}{}'.format(project, channel), d) | ||
all_scenarios.append(scenario) | ||
|
||
return all_scenarios | ||
|
||
|
||
class BuildSnapGrammarTestCase(testscenarios.WithScenarios, | ||
integration_tests.TestCase): | ||
|
||
scenarios = _construct_scenarios() | ||
|
||
def setUp(self): | ||
super().setUp() | ||
if self._hello_is_installed(): | ||
self.fail( | ||
'This integration test cannot run if you already have the ' | ||
"'hello' snap installed. Please uninstall it " | ||
"by running 'sudo snap remove hello'.") | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
|
||
# Remove hello. This is safe since the test fails if hello was already | ||
# installed. | ||
try: | ||
subprocess.check_output( | ||
['sudo', 'snap', 'remove', 'hello'], | ||
stderr=subprocess.STDOUT) | ||
except subprocess.CalledProcessError as e: | ||
self.fail("unable to remove 'hello': {}".format(e.output)) | ||
|
||
def _hello_is_installed(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I replicated what was in |
||
return snapcraft.repo.snaps.SnapPackage.is_snap_installed('hello') | ||
|
||
def _add_channel_information_to_hello(self): | ||
replacement = '- hello{}'.format(self.channel) | ||
with fileinput.input('snapcraft.yaml', inplace=True) as input_file: | ||
for line in input_file: | ||
print(line.replace('- hello', replacement), end='') | ||
|
||
def test_grammar(self): | ||
self.copy_project_to_cwd(self.project) | ||
self._add_channel_information_to_hello() | ||
|
||
self.run_snapcraft('pull') | ||
|
||
self.assertThat(self._hello_is_installed(), | ||
Equals(self.hello_installed)) | ||
|
||
|
||
class BuildSnapGrammarErrorsTestCase(integration_tests.TestCase): | ||
|
||
def test_on_other_arch_else_fail(self): | ||
"""Test that 'on' fails with an error if it hits an 'else fail'.""" | ||
|
||
exception = self.assertRaises( | ||
subprocess.CalledProcessError, self.run_snapcraft, | ||
['pull'], 'build-snap-grammar-fail') | ||
|
||
self.assertThat(exception.output, Contains( | ||
"Unable to satisfy 'on other-arch', failure forced")) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,9 @@ properties: | |
stage-packages: | ||
$ref: "#/definitions/grammar-array" | ||
default: [] # For some reason this doesn't work if in the ref | ||
build-snaps: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ¡viva! this is the end of compiling go1.8 on every build. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go 1.9 now, already... |
||
$ref: "#/definitions/grammar-array" | ||
default: [] # For some reason this doesn't work if in the ref | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hum, I haven't seen this before. It's ok to leave a comment, but it needs more information. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I initially wrote the grammar back in the day I wasn't sure what was happening, and decided it was a jsonschema quirk. However, now that you ask I looked into it with a fresh mind and I think I know what's actually happening: a jsonschema ref isn't expanded in any fancy way by the YAML (which is why I'd like to use a recursive YAML anchor for this, but jsonschema causes things to explode that way since it wants to walk the whole thing). This means that we can't actually access the chunk of YAML representing that bit of the schema very easily in code. Like we do here to expand defaults. So this is kind of an ugly hack to allow specifying the defaults to continue actually resulting in defaults. Thankfully that's the only field for which I imagine we'll need this hack. |
||
build-packages: | ||
$ref: "#/definitions/grammar-array" | ||
default: [] # For some reason this doesn't work if in the ref | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ def __init__(self, project_options=None): | |
if project_options is None: | ||
project_options = snapcraft.ProjectOptions() | ||
|
||
self.build_snaps = set() | ||
self.build_tools = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have I said how much I hate this build_tools? :D |
||
self._project_options = project_options | ||
|
||
|
@@ -115,11 +116,12 @@ def __init__(self, project_options=None): | |
self.build_tools = grammar_processor.get_build_packages() | ||
self.build_tools |= set(project_options.additional_build_packages) | ||
|
||
self.parts = PartsConfig(self.data, | ||
self._project_options, | ||
self._validator, | ||
self.build_tools, | ||
self.snapcraft_yaml_path) | ||
self.parts = PartsConfig(parts=self.data, | ||
project_options=self._project_options, | ||
validator=self._validator, | ||
build_snaps=self.build_snaps, | ||
build_tools=self.build_tools, | ||
snapcraft_yaml=self.snapcraft_yaml_path) | ||
|
||
if 'architectures' not in self.data: | ||
self.data['architectures'] = [self._project_options.deb_arch] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I would use multiply here, but if this makes you happy, ok :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I saw multiply, this feels much more readable IMO, the other options was as @sparkiegeek mentioned,
subTest
but iirc,testscenarios
had issues with that, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right: testing-cabal/testtools#235