Skip to content
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

lifecycle: only warn when a default provider snap is missing #2885

Merged
merged 5 commits into from Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions snapcraft/internal/lifecycle/_runner.py
Expand Up @@ -82,23 +82,32 @@ def execute(
"The repo backend is not returning the list of installed packages"
)

build_snaps = project_config.build_snaps
content_snaps = project_config.project._get_content_snaps()
required_snaps = project_config.build_snaps | content_snaps

if common.is_process_container():
if common.is_process_container() and build_snaps:
installed_snaps: List[str] = []
logger.warning(
(
"The following snaps are required but not installed as snapcraft "
"is running inside docker or podman container: {}.\n"
"Please ensure the environment is properly setup before continuing.\n"
"Ignore this message if the appropriate measures have already been taken".format(
", ".join(required_snaps)
", ".join(build_snaps)
)
)
)
else:
installed_snaps = repo.snaps.install_snaps(required_snaps)
installed_snaps = repo.snaps.install_snaps(build_snaps)
for content_snap in content_snaps:
try:
installed_snaps += repo.snaps.install_snaps([content_snap])
except repo.snaps.errors.SnapUnavailableError:
logger.warning(
f"Could not install snap defined in a plug {content_snap!r}. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/in a plug/in plug/

"The missing library report may have false positives listed if those "
"libraries were to be provided by the content snap."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/were to be/are

)

try:
global_state = states.GlobalState.load(
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/internal/repo/snaps.py
@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2017-2019 Canonical Ltd
# Copyright (C) 2017-2020 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
Expand Down
@@ -0,0 +1,20 @@
name: content-test
version: '0.1'
summary: snap using a plug with a content interface should install
description: |
Defining a plug using the content interface should install the snap
listed under default-provider.
grade: devel
confinement: devmode

plugs:
content-interface:
content: content-interface
interface: content
target: $SNAP/content
default-provider: hello

parts:
empty:
plugin: nil
28 changes: 28 additions & 0 deletions tests/spread/general/content-interface-provider-found/task.yaml
@@ -0,0 +1,28 @@
summary: Build a snap that uses the content interface

environment:
SNAP_DIR: snaps/provider

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
set_base "$SNAP_DIR/snap/snapcraft.yaml"

restore: |
cd "$SNAP_DIR"
snapcraft clean

#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
restore_yaml "snap/snapcraft.yaml"

execute: |
cd "$SNAP_DIR"

snapcraft prime

if ! snap list hello; then
echo "snap listed as default provider was not installed"
exit 1
fi

@@ -0,0 +1,20 @@
name: content-test
version: '0.1'
summary: snap using a plug with a content interface that cannot be found
description: |
Defining a plug using the content interface should only warn when it
cannot find the snap listed under default-provider.
grade: devel
confinement: devmode

plugs:
content-interface:
content: content-interface
interface: content
target: $SNAP/content
default-provider: unknown-content-snap

parts:
empty:
plugin: nil
@@ -0,0 +1,22 @@
summary: Build a snap that uses the content interface with a non published snap

environment:
SNAP_DIR: snaps/provider

prepare: |
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
set_base "$SNAP_DIR/snap/snapcraft.yaml"

restore: |
cd "$SNAP_DIR"
snapcraft clean

#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
. "$TOOLS_DIR/snapcraft-yaml.sh"
restore_yaml "snap/snapcraft.yaml"

execute: |
cd "$SNAP_DIR"

snapcraft prime | MATCH "Could not install snap defined in a plug"