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

meta: include project provided assumes in snapd.yaml #4152

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion snapcraft/meta/snap_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ def write(project: Project, prime_dir: Path, *, arch: str, arch_triplet: str):
environment = _populate_environment(project.environment, prime_dir, arch_triplet)
version = process_version(project.version)

# project provided assumes and computed assumes
total_assumes = sorted(project.assumes + list(assumes))

snap_metadata = SnapMetadata(
name=project.name,
title=project.title,
Expand All @@ -378,7 +381,7 @@ def write(project: Project, prime_dir: Path, *, arch: str, arch_triplet: str):
type=project.type,
architectures=[arch],
base=cast(str, project.base),
assumes=list(assumes) if assumes else None,
assumes=total_assumes if total_assumes else None,
epoch=project.epoch,
apps=snap_apps or None,
confinement=project.confinement,
Expand Down
80 changes: 80 additions & 0 deletions tests/unit/meta/test_snap_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ def test_simple_snap_yaml(simple_project, new_dir):
)


def test_assumes(simple_project, new_dir):
snap_yaml.write(
simple_project(assumes=["foossumes"]),
prime_dir=Path(new_dir),
arch="amd64",
arch_triplet="x86_64-linux-gnu",
)
yaml_file = Path("meta/snap.yaml")
assert yaml_file.is_file()

content = yaml_file.read_text()
assert content == textwrap.dedent(
"""\
name: mytest
version: 1.29.3
summary: Single-line elevator pitch for your amazing snap
description: test-description
architectures:
- amd64
base: core22
assumes:
- foossumes
apps:
app1:
command: bin/mytest
confinement: strict
grade: stable
environment:
LD_LIBRARY_PATH: ${SNAP_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
"""
)


@pytest.fixture
def complex_project():
snapcraft_yaml = textwrap.dedent(
Expand Down Expand Up @@ -395,6 +429,52 @@ def test_hook_command_chain_assumes(simple_project, new_dir):
)


def test_hook_command_chain_assumes_with_existing_assumes(simple_project, new_dir):
hooks = {
"hook": {
"command-chain": ["c1"],
},
}

snap_yaml.write(
simple_project(hooks=hooks, assumes=["foossumes", "barssumes"]),
prime_dir=Path(new_dir),
arch="amd64",
arch_triplet="x86_64-linux-gnu",
)
yaml_file = Path("meta/snap.yaml")
assert yaml_file.is_file()

content = yaml_file.read_text()
assert content == textwrap.dedent(
"""\
name: mytest
version: 1.29.3
summary: Single-line elevator pitch for your amazing snap
description: test-description
architectures:
- amd64
base: core22
assumes:
- barssumes
- command-chain
- foossumes
apps:
app1:
command: bin/mytest
confinement: strict
grade: stable
environment:
LD_LIBRARY_PATH: ${SNAP_LIBRARY_PATH}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
hooks:
hook:
command-chain:
- c1
"""
)


def test_project_environment_ld_library_path_and_path_defined(simple_project, new_dir):
"""Test behavior of defining LD_LIBRARY_PATH and PATH variables."""
environment = {
Expand Down