Skip to content

Commit

Permalink
Merge 7.3 hotfixes (#4154)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiusens committed May 19, 2023
2 parents 6f62368 + 4f442d3 commit e52221b
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
5 changes: 4 additions & 1 deletion snapcraft/meta/snap_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,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 @@ -408,7 +411,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

0 comments on commit e52221b

Please sign in to comment.