Skip to content

Commit

Permalink
fix(lifecycle): return correct base when using devel for build-base
Browse files Browse the repository at this point in the history
get_effective_base() should not return "devel" and pass it to the
PartsLifecycle(), which make the parts think the coreXX is "devel".
Thus checking the wrong path for dynamic linking.
  • Loading branch information
syu-w committed Jan 16, 2024
1 parent ffbdabf commit 02fb2ce
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions snapcraft/parts/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _run_command( # noqa PLR0913 # pylint: disable=too-many-branches, too-many-
project.parts,
work_dir=work_dir,
assets_dir=assets_dir,
base=project.get_effective_base(),
base=project.get_effective_base(allow_return_devel=(project.type == "base")),
project_base=project.base or "",
confinement=project.confinement,
package_repositories=project.package_repositories,
Expand Down Expand Up @@ -429,7 +429,7 @@ def _run_in_provider( # noqa PLR0915
build_for=project.get_build_for(),
)

snapcraft_base = project.get_effective_base()
snapcraft_base = project.get_effective_base(allow_return_devel=True)
build_base = providers.SNAPCRAFT_BASE_TO_PROVIDER_BASE[snapcraft_base]

if snapcraft_base == "devel":
Expand Down
13 changes: 12 additions & 1 deletion snapcraft/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def get_extra_build_snaps(self) -> List[str]:

return extra_build_snaps

def get_effective_base(self) -> str:
def get_effective_base(self, allow_return_devel=False) -> str:
"""Return the base to use to create the snap."""
base = get_effective_base(
base=self.base,
Expand All @@ -713,6 +713,17 @@ def get_effective_base(self) -> str:
if base is None:
raise RuntimeError("cannot determine build base")

# "devel" is not a valid base but a valid build-base that may returned.
# the actual base is the same as the base defined in the project.
if base == "devel":
if allow_return_devel:
return base

if self.base is None:
raise RuntimeError("cannot determine base")

return self.base

return base

def get_build_on(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion snapcraft/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def get_effective_base(
Returns build-base if set, but if not, name is returned if the
snap is of type base. For all other snaps, the base is returned
as the build-base.
as the build-base. This may return "devel" if the build-base is
set it to "devel".
"""
if build_base is not None:
return build_base
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/parts/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1860,3 +1860,39 @@ def test_lifecycle_write_metadata(
primed_stage_packages=[],
)
]


@pytest.mark.parametrize(
"base,build_base,grade,allow_return_devel,expected_base",
[
["coreXX", None, "stable", False, "coreXX"],
["coreXX", None, "stable", True, "coreXX"],
["coreXX", None, "devel", False, "coreXX"],
["coreXX", None, "devel", True, "coreXX"],
["coreXX", "coreYY", "stable", False, "coreYY"],
["coreXX", "coreYY", "stable", True, "coreYY"],
["coreXX", "coreYY", "devel", False, "coreYY"],
["coreXX", "coreYY", "devel", True, "coreYY"],
["coreXX", "devel", "devel", False, "coreXX"],
["coreXX", "devel", "devel", True, "devel"],
],
)
def test_lifecycle_get_effective_base(
emitter,
mocker,
snapcraft_yaml,
tmp_path,
base,
build_base,
grade,
allow_return_devel,
expected_base,
):
"""Get the effective base from the project."""
project = Project.unmarshal(
snapcraft_yaml(base=base, build_base=build_base, grade=grade)
)
assert (
project.get_effective_base(allow_return_devel=allow_return_devel)
== expected_base
)

0 comments on commit 02fb2ce

Please sign in to comment.