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
  • Loading branch information
syu-w committed Jan 24, 2024
1 parent bbf8ae0 commit d75fdaf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion snapcraft/parts/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def _run_in_provider( # noqa PLR0915
snapcraft_base = project.get_effective_base()
build_base = providers.SNAPCRAFT_BASE_TO_PROVIDER_BASE[snapcraft_base]

if snapcraft_base == "devel":
if snapcraft_base in ("devel", "core24"):
emit.progress(
"Running snapcraft with a devel instance is for testing purposes only.",
permanent=True,
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/parts/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_CORE_PART_NAME = "snapcraft/core"

# All bases recognized by snapcraft
BASES = {"core", "core18", "core20", "core22", "devel"}
BASES = {"core", "core18", "core20", "core22", "core24", "devel"}
# Bases no longer supported by the current version of snapcraft
ESM_BASES = {"core", "core18"}
# Bases handled by the legacy snapcraft codebase
Expand Down
9 changes: 9 additions & 0 deletions snapcraft/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,15 @@ def _validate_grade_and_build_base(cls, values):
raise ValueError("grade must be 'devel' when build-base is 'devel'")
return values

@pydantic.validator("base", always=True)
@classmethod
def _validate_base(cls, base, values):
"""Not allowed to use unstable base without devel build-base."""
if values.get("base") == "core24" and values.get("build_base") != "devel":
raise ValueError("build-base must be 'devel' when base is 'core24'")

return base

@pydantic.validator("build_base", always=True)
@classmethod
def _validate_build_base(cls, build_base, values):
Expand Down
1 change: 1 addition & 0 deletions snapcraft/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"core18": bases.BuilddBaseAlias.BIONIC,
"core20": bases.BuilddBaseAlias.FOCAL,
"core22": bases.BuilddBaseAlias.JAMMY,
"core24": bases.BuilddBaseAlias.DEVEL,
"devel": bases.BuilddBaseAlias.DEVEL,
}

Expand Down
14 changes: 10 additions & 4 deletions snapcraft/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,20 @@ def get_effective_base(
) -> Optional[str]:
"""Return the base to use to create the snap.
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.
Return the build-base if set.
Exception:
"base" snaps will return name if build-base is not set.
"devel" snaps, return the base, where the true base is, except "base" snaps.
"""
if project_type == "base":
return build_base if build_base else name

if build_base is not None:
if build_base == "devel":
return base
return build_base

return name if project_type == "base" else base
return base


def get_parallel_build_count() -> int:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/commands/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ def test_get_effective_base_with_build_base(

cli.run()

mock_run_new_or_fallback_remote_build.assert_called_once_with(build_base)
if build_base == "devel":
mock_run_new_or_fallback_remote_build.assert_called_once_with(base)
else:
mock_run_new_or_fallback_remote_build.assert_called_once_with(build_base)


@pytest.mark.usefixtures("mock_argv", "mock_confirm")
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def test_strtobool_value_error(value: str):
(None, None, "other", "name", None),
("base", "build_base", "other", "name", "build_base"),
("base", None, "other", "name", "base"),
("base", "devel", "other", "name", "base"),
("base", "devel", "base", "name", "devel"),
],
)
def test_get_effective_base(base, build_base, project_type, name, expected_base):
Expand Down

0 comments on commit d75fdaf

Please sign in to comment.