Skip to content
Open
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
5 changes: 5 additions & 0 deletions docs/release-notes/snapcraft-9-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ sources.
Minor features
--------------

Custom build paths for remote build
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The remote-build command now supports a ``--project-dir`` option to specify custom build paths for monorepo setups (`#6287`).

Snapcraft 9.0 brings the following minor changes.

Promote edge channels with ``--yes``
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dynamic = ["version"]
dependencies = [
"catkin-pkg==1.1.0; sys_platform == 'linux'",
"click>=8.3.3",
"craft-application[remote]>=7.1.0",
"craft-application[remote] @ git+https://github.com/canonical/craft-application.git@main",
"craft-archives>=2.2.0",
"craft-cli>=3.4.0",
"craft-grammar>=2.3.0",
Expand Down
15 changes: 14 additions & 1 deletion snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def _fill_parser(self, parser: argparse.ArgumentParser) -> None:
dest="remote_build_build_fors",
)

parser.add_argument(
"--project-dir",
type=str,
metavar="path",
help="Directory containing the snap project to build",
dest="project_dir",
)

@override
def _pre_build(self, parsed_args: argparse.Namespace):
"""Perform pre-build validation.
Expand Down Expand Up @@ -179,4 +187,9 @@ def _get_build_args(self, parsed_args: argparse.Namespace) -> dict[str, Any]:
)

emit.debug(f"Architectures to build for: {humanize_list(archs, 'and')}")
return {"architectures": archs}
build_args: dict[str, Any] = {"architectures": archs}

if getattr(parsed_args, "project_dir", None):
build_args["build_path"] = parsed_args.project_dir

return build_args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--project-dir my-subdir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my-remote-snap_0.1_amd64.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: my-remote-snap
base: core24
version: '0.1'
summary: Test snap for project-dir remote build
description: A minimal project to test remote builds using project-dir.
grade: devel
confinement: devmode

parts:
my-part:
plugin: nil
14 changes: 9 additions & 5 deletions tests/spread/core24/remote-build/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ environment:
SNAP/build_for: build-for
SNAP/build_for_with_platforms: build-for-with-platforms
SNAP/build_for_with_shorthand_platforms: build-for-with-shorthand-platforms
SNAP/project_dir: project-dir
CREDENTIALS_FILE: "$HOME/.local/share/snapcraft/launchpad-credentials"

prepare: |
Expand All @@ -24,18 +25,20 @@ prepare: |
exit 1
fi

# commit the project
git config --global --add safe.directory "$PWD"
git init
git add snapcraft.yaml

if [[ -d "my-subdir" ]]; then
git add my-subdir/snapcraft.yaml
else
git add snapcraft.yaml
fi

git commit -m "Initial Commit"

# set up launchpad token
mkdir -p "$(dirname "$CREDENTIALS_FILE")"
echo -e "$LAUNCHPAD_TOKEN" > "$CREDENTIALS_FILE"

# build ids are based on the project contents
# adding a date ensures each test has a unique build id
date > date.txt

restore: |
Expand Down Expand Up @@ -81,3 +84,4 @@ execute: |
exit 1
fi
fi
1
36 changes: 35 additions & 1 deletion tests/unit/commands/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def test_unknown_build_for_error(
],
)
@pytest.mark.usefixtures("emitter", "mock_argv", "mock_remote_start_builds")
def test_multiple_artifacts_per_build_on(
def test_multiple_artifacts_per_build_on( # noqa: PLR0917
default_project,
fake_services,
setup_project,
Expand Down Expand Up @@ -567,3 +567,37 @@ def test_multiple_artifacts_per_build_on(
)
for message in error_messages:
check.is_in(message, err)


@pytest.mark.usefixtures("emitter")
def test_project_dir_argument(
default_project,
fake_services,
setup_project,
mock_remote_start_builds,
fake_app,
mocker,
):
"""Test that `--project-dir` passes the build_path argument."""
mocker.patch.object(
sys,
"argv",
[
"snapcraft",
"remote-build",
"--launchpad-accept-public-upload",
"--project-dir",
"my-subdir",
],
)
setup_project(
fake_services,
{**default_project.marshal(), "base": "core24"},
write_project=True,
)

fake_app.run()

mock_remote_start_builds.assert_called_once_with(
ANY, architectures=[str(DebianArchitecture.from_host())], build_path="my-subdir"
)
10 changes: 3 additions & 7 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading