Skip to content

Commit

Permalink
feat(remotebuild): allow build-for all
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal committed Jul 6, 2024
1 parent c1c70a2 commit 3325af0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 41 deletions.
15 changes: 0 additions & 15 deletions snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from pathlib import Path
from typing import Any, cast

import craft_cli
import lazr.restfulclient.errors
from craft_application import errors
from craft_application.application import filter_plan
Expand Down Expand Up @@ -147,20 +146,6 @@ def _validate(self, parsed_args: argparse.Namespace) -> None:
reportable=False,
retcode=77,
)
project = cast(models.Project, self._services.project)
if project.architectures:
for arch in project.architectures:
if (
isinstance(arch, models.Architecture)
and arch.build_for
and "all" in arch.build_for
):
raise craft_cli.CraftError(
message="Remote build does not support architecture 'all'.",
resolution="Reconfigure your snap for architecture-dependent builds.",
reportable=False,
retcode=78, # Configuration error
)

def _run(self, parsed_args: argparse.Namespace, **kwargs: Any) -> int | None:
"""Run the remote-build command.
Expand Down
83 changes: 57 additions & 26 deletions tests/unit/commands/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Remote-build command tests."""

import argparse
import os
import shutil
import subprocess
Expand All @@ -25,15 +24,14 @@
from pathlib import Path
from unittest.mock import ANY, Mock

import craft_cli
import pytest
from craft_application import launchpad
from craft_application.errors import RemoteBuildError
from craft_application.launchpad.models import BuildState
from craft_application.remote.git import GitRepo
from craft_application.remote.utils import get_build_id

from snapcraft import application, commands, const, models
from snapcraft import application, const
from snapcraft.errors import ClassicFallback
from snapcraft.utils import get_host_architecture

Expand Down Expand Up @@ -412,29 +410,6 @@ def test_run_in_shallow_repo_unsupported(
######################


def test_no_architecture_all(
mocker, snapcraft_yaml, fake_services, mock_remote_builder_fake_build_process
):
"""Test that remote builds error out early with an architecture 'all'."""
project = snapcraft_yaml(
base="core22", architectures=[{"build-on": "amd64", "build-for": "all"}]
)
fake_services.project = models.Project.unmarshal(project)
cmd = commands.RemoteBuildCommand(
{"app": application.APP_METADATA, "services": fake_services}
)

with pytest.raises(
craft_cli.CraftError, match="Remote build does not support architecture 'all'"
):
cmd.run(
argparse.Namespace(
project=None,
launchpad_accept_public_upload=True,
)
)


@pytest.mark.parametrize("base", const.CURRENT_BASES)
def test_no_platform_defined_no_platform_or_build_for(
mocker,
Expand Down Expand Up @@ -467,6 +442,62 @@ def test_no_platform_defined_no_platform_or_build_for(
)


@pytest.mark.parametrize("base", const.CURRENT_BASES - {"core22"})
def test_platform_build_for_all(
mocker,
snapcraft_yaml,
base,
fake_services,
mock_confirm,
mock_remote_builder_fake_build_process,
):
snapcraft_yaml_dict = {
"base": base,
"build-base": "devel",
"grade": "devel",
"platforms": {
"test-platform": {"build-on": "arm64", "build-for": "all"},
},
}
snapcraft_yaml(**snapcraft_yaml_dict)
mocker.patch.object(sys, "argv", ["snapcraft", "remote-build"])
mock_start_builds = mocker.patch(
"craft_application.services.remotebuild.RemoteBuildService.start_builds"
)
app = application.create_app()
app.run()

mock_start_builds.assert_called_once()
assert mock_start_builds.call_args[1]["architectures"] == ["all"]


def test_platform_build_for_all_core22(
mocker,
snapcraft_yaml,
fake_services,
mock_confirm,
mock_remote_builder_fake_build_process,
):
"""remote-build command uses all platforms if no platform or build-for is given."""
snapcraft_yaml_dict = {
"base": "core22",
"grade": "devel",
"architectures": [
{"build-on": ["arm64"], "build-for": ["all"]},
],
}
snapcraft_yaml(**snapcraft_yaml_dict)
mocker.patch.object(sys, "argv", ["snapcraft", "remote-build"])
mock_start_builds = mocker.patch(
"craft_application.services.remotebuild.RemoteBuildService.start_builds"
)
app = application.create_app()
app.run()

mock_start_builds.assert_called_once()
assert mock_start_builds.call_args[1]["architectures"] == ["all"]


@pytest.mark.parametrize("base", const.CURRENT_BASES - {"core22"})
def test_platform_defined_no_platform_or_build_for(
mocker,
Expand Down

0 comments on commit 3325af0

Please sign in to comment.