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

fix(package): use correct legacy bases architectures #1792

Closed
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
15 changes: 13 additions & 2 deletions charmcraft/services/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""Service class for packing."""
from __future__ import annotations

import itertools
import json
import os
import pathlib
Expand Down Expand Up @@ -193,7 +192,19 @@ def get_manifest(self, lint_results: Iterable[lint.CheckResult]) -> Manifest:
def get_manifest_bases(self) -> list[models.Base]:
"""Get the bases used for a charm manifest from the project."""
if isinstance(self._project, BasesCharm):
return list(itertools.chain.from_iterable(base.run_on for base in self._project.bases))
run_on_bases = []
for project_base in self._project.bases:
for build_base in project_base.build_on:
if build_base.name != self._build_plan[0].base.name:
continue
if build_base.channel != self._build_plan[0].base.version:
continue
if self._build_plan[0].build_on not in build_base.architectures:
continue
run_on_bases.extend(project_base.run_on)
if not run_on_bases:
raise RuntimeError("Could not determine run-on bases.")
return run_on_bases
if isinstance(self._project, PlatformCharm):
if not self._platform:
architectures = [util.get_host_architecture()]
Expand Down
68 changes: 62 additions & 6 deletions tests/unit/services/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"""Tests for package service."""

import datetime
import pathlib
import sys
import zipfile

import craft_cli.pytest_plugin
import pytest
import pytest_check
from craft_application import util
from craft_application.models import BuildInfo
from craft_providers.bases import BaseName

from charmcraft import const, models, services
from charmcraft.application.main import APP_METADATA
Expand Down Expand Up @@ -135,10 +138,16 @@ def test_do_not_overwrite_metadata_yaml(

# region Tests for getting bases for manifest.yaml
@pytest.mark.parametrize(
("bases", "expected"),
("bases", "build_item", "expected"),
[
(
[{"name": "ubuntu", "channel": "20.04"}],
BuildInfo(
platform=util.get_host_architecture(),
build_for=util.get_host_architecture(),
build_on=util.get_host_architecture(),
base=BaseName("ubuntu", "20.04"),
),
[
{
"name": "ubuntu",
Expand All @@ -149,27 +158,74 @@ def test_do_not_overwrite_metadata_yaml(
),
(
[
{"name": "ubuntu", "channel": "22.04", "architectures": ["all"]},
{"name": "ubuntu", "channel": "20.04", "architectures": ["riscv64"]},
{
"build-on": [
{"name": "ubuntu", "channel": "22.04", "architectures": ["riscv64"]}
],
"run-on": [
{"name": "ubuntu", "channel": "22.04", "architectures": ["all"]},
],
},
],
BuildInfo(
platform="riscv64",
build_for="riscv64",
build_on="riscv64",
base=BaseName("ubuntu", "22.04"),
),
[
{"name": "ubuntu", "channel": "22.04", "architectures": ["all"]},
{"name": "ubuntu", "channel": "20.04", "architectures": ["riscv64"]},
],
),
(
[{"name": "centos", "channel": "7"}],
BuildInfo(
platform=util.get_host_architecture(),
build_on=util.get_host_architecture(),
build_for=util.get_host_architecture(),
base=BaseName("centos", "7"),
),
[{"name": "centos", "channel": "7", "architectures": [util.get_host_architecture()]}],
),
pytest.param(
[
{"name": "centos", "channel": "7"},
{
"build-on": [{"name": "ubuntu", "channel": "20.04"}],
"run-on": [{"name": "ubuntu", "channel": "20.04", "architectures": ["all"]}],
},
{
"build-on": [
{"name": "ubuntu", "channel": "22.04", "architectures": ["amd64", "arm64"]}
],
"run-on": [{"name": "ubuntu", "channel": "22.04", "architectures": ["arm64"]}],
},
],
BuildInfo(
platform="amd64",
build_on="amd64",
build_for="arm64",
base=BaseName("ubuntu", "22.04"),
),
[{"name": "ubuntu", "channel": "22.04", "architectures": ["arm64"]}],
id="cross-compile",
),
],
)
def test_get_manifest_bases_from_bases(fake_path, package_service, bases, expected):
def test_get_manifest_bases_from_bases(
fake_path: pathlib.Path, package_service: services.PackageService, bases, build_item, expected
):
charm = models.BasesCharm.parse_obj(
{
"name": "my-charm",
"description": "",
"summary": "",
"type": "charm",
"bases": [{"build-on": bases, "run-on": bases}],
"bases": bases,
}
)
package_service._project = charm
package_service._build_plan = [build_item]

assert package_service.get_manifest_bases() == [models.Base.parse_obj(b) for b in expected]

Expand Down
Loading