Skip to content

Commit

Permalink
chore(merge): 8.3-8.4 into main (#5044)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-cal authored Sep 18, 2024
2 parents 055fb36 + 464bd08 commit 62dacfb
Show file tree
Hide file tree
Showing 28 changed files with 284 additions and 62 deletions.
7 changes: 3 additions & 4 deletions docs/explanation/remote-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ Current
:ref:`lifecycle commands<reference-lifecycle-commands>`.

``--platform`` or ``--build-for`` can only be provided when the ``platforms``
and ``architectures`` keywords are not defined in the project metadata
or ``architectures`` keywords are not defined in the project metadata
(`[12]`_).

These keywords are mutually exclusive and must be a single debian architecture.
A list of comma-separated architectures is not supported (`[11]`_).
These keywords are mutually exclusive and must be a comma-separated list of
debian architectures.

``core22`` snaps can only use ``--build-for``. ``core24`` and newer snaps
can use ``--platform`` or ``--build-for``.
Expand Down Expand Up @@ -180,7 +180,6 @@ Launchpad is not able to parse this notation (`[9]`_).
.. _`[8]`: https://bugs.launchpad.net/snapcraft/+bug/2007789
.. _`[9]`: https://bugs.launchpad.net/snapcraft/+bug/2042167
.. _`[10]`: https://github.com/canonical/snapcraft/issues/4885
.. _`[11]`: https://github.com/canonical/snapcraft/issues/4990
.. _`[12]`: https://github.com/canonical/snapcraft/issues/4992
.. _`[13]`: https://github.com/canonical/snapcraft/issues/4996
.. _`[14]`: https://github.com/canonical/snapcraft/issues/4995
17 changes: 17 additions & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ Changelog

For a complete list of commits, check out the `X.Y.Z`_ release on GitHub.

8.3.4 (2024-Sep-13)
-------------------

Core
====

Plugins
#######

NPM
"""

* Fix a bug where NPM parts fail to build if the ``pull`` and ``build`` steps
did not occur in the same execution of Snapcraft.

For a complete list of commits, check out the `8.3.4`_ release on GitHub.

8.4.0 (2024-Sep-10)
-------------------
Expand Down Expand Up @@ -1171,4 +1187,5 @@ For a complete list of commits, check out the `8.0.0`_ release on GitHub.
.. _8.3.1: https://github.com/canonical/snapcraft/releases/tag/8.3.1
.. _8.3.2: https://github.com/canonical/snapcraft/releases/tag/8.3.2
.. _8.3.3: https://github.com/canonical/snapcraft/releases/tag/8.3.3
.. _8.3.4: https://github.com/canonical/snapcraft/releases/tag/8.3.4
.. _8.4.0: https://github.com/canonical/snapcraft/releases/tag/8.4.0
2 changes: 1 addition & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ craft-application==4.1.2
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-parts==2.1.0
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
Expand Down
2 changes: 1 addition & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ craft-application==4.1.2
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-parts==2.1.0
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ craft-application==4.1.2
craft-archives==2.0.0
craft-cli==2.7.0
craft-grammar==2.0.0
craft-parts==2.1.0
craft-parts==2.1.1
craft-platforms==0.1.1
craft-providers==2.0.1
craft-store==3.0.0
Expand Down
85 changes: 44 additions & 41 deletions snapcraft/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,51 +77,51 @@ class RemoteBuildCommand(ExtensibleCommand):
@overrides
def _fill_parser(self, parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--recover", action="store_true", help="recover an interrupted build"
"--recover", action="store_true", help="Recover an interrupted build"
)
parser.add_argument(
"--launchpad-accept-public-upload",
action="store_true",
help="acknowledge that uploaded code will be publicly available.",
help="Acknowledge that uploaded code will be publicly available",
)
parser.add_argument(
"--launchpad-timeout",
type=int,
default=0,
metavar="<seconds>",
help="Time in seconds to wait for launchpad to build.",
help="Time in seconds to wait for launchpad to build",
)

parser.add_argument(
"--status", action="store_true", help="display remote build status"
"--status", action="store_true", help="Display remote build status"
)
parser.add_argument(
"--build-id", metavar="build-id", help="specific build id to retrieve"
"--build-id", metavar="build-id", help="Specific build ID to retrieve"
)

group = parser.add_mutually_exclusive_group()
group.add_argument(
"--platform",
type=str,
type=lambda arg: [arch.strip() for arch in arg.split(",")],
metavar="name",
default=os.getenv("CRAFT_PLATFORM"),
help="Set platform to build for",
help="Comma-separated list of platforms to build for",
# '--platform' needs to be handled differently since remote-build can
# build for an architecture that is not in the project metadata
dest="remote_build_platform",
dest="remote_build_platforms",
)
group.add_argument(
"--build-for",
type=str,
type=lambda arg: [arch.strip() for arch in arg.split(",")],
metavar="arch",
default=os.getenv("CRAFT_BUILD_FOR"),
help="Set architecture to build for",
help="Comma-separated list of architectures to build for",
# '--build-for' needs to be handled differently since remote-build can
# build for architecture that is not in the project metadata
dest="remote_build_build_for",
dest="remote_build_build_fors",
)
parser.add_argument(
"--project", help="upload to the specified Launchpad project"
"--project", help="Upload to the specified Launchpad project"
)

def _validate(self, parsed_args: argparse.Namespace) -> None:
Expand Down Expand Up @@ -154,9 +154,9 @@ def _validate(self, parsed_args: argparse.Namespace) -> None:
retcode=os.EX_NOPERM,
)

build_for = parsed_args.remote_build_build_for or None
platform = parsed_args.remote_build_platform or None
parameter = "--build-for" if build_for else "--platform" if platform else None
build_fors = parsed_args.remote_build_build_fors or None
platforms = parsed_args.remote_build_platforms or None
parameter = "--build-for" if build_fors else "--platform" if platforms else None
keyword = (
"architectures"
if self.project._architectures_in_yaml
Expand All @@ -171,35 +171,38 @@ def _validate(self, parsed_args: argparse.Namespace) -> None:
retcode=os.EX_CONFIG,
)

if platform:
if platforms:
if self.project.get_effective_base() == "core22":
raise errors.RemoteBuildError(
"'--platform' cannot be used for core22 snaps.",
resolution="Use '--build-for' instead.",
doc_slug="/explanation/remote-build.html",
retcode=os.EX_CONFIG,
)
if platform not in SUPPORTED_ARCHS:
raise errors.RemoteBuildError(
f"Unsupported platform {parsed_args.remote_build_platform!r}.",
resolution=(
"Use a supported debian architecture. Supported "
f"architectures are: {humanize_list(SUPPORTED_ARCHS, 'and')}"
),
doc_slug="/explanation/remote-build.html",
retcode=os.EX_CONFIG,
)

if build_for and build_for not in SUPPORTED_ARCHS:
raise errors.RemoteBuildError(
f"Unsupported build-for architecture {parsed_args.remote_build_build_for!r}.",
resolution=(
"Use a supported debian architecture. Supported "
f"architectures are: {humanize_list(SUPPORTED_ARCHS, 'and')}"
),
doc_slug="/explanation/remote-build.html",
retcode=os.EX_CONFIG,
)
for platform in platforms:
if platform not in SUPPORTED_ARCHS:
raise errors.RemoteBuildError(
f"Unsupported platform {platform!r}.",
resolution=(
"Use a supported debian architecture. Supported "
f"architectures are: {humanize_list(SUPPORTED_ARCHS, 'and')}"
),
doc_slug="/explanation/remote-build.html",
retcode=os.EX_CONFIG,
)

if build_fors:
for build_for in build_fors:
if build_for not in SUPPORTED_ARCHS:
raise errors.RemoteBuildError(
f"Unsupported build-for architecture {build_for!r}.",
resolution=(
"Use a supported debian architecture. Supported "
f"architectures are: {humanize_list(SUPPORTED_ARCHS, 'and')}"
),
doc_slug="/explanation/remote-build.html",
retcode=os.EX_CONFIG,
)

self._validate_single_artifact_per_build_on()

Expand Down Expand Up @@ -271,10 +274,10 @@ def _run( # noqa: PLR0915 [too-many-statements]
emit.trace(f"Project directory: {project_dir}")
self._validate(parsed_args)

if parsed_args.remote_build_build_for:
architectures = [parsed_args.remote_build_build_for]
elif parsed_args.remote_build_platform:
architectures = [parsed_args.remote_build_platform]
if parsed_args.remote_build_build_fors:
architectures = parsed_args.remote_build_build_fors
elif parsed_args.remote_build_platforms:
architectures = parsed_args.remote_build_platforms
else:
architectures = self._get_project_build_fors()

Expand Down
4 changes: 2 additions & 2 deletions snapcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,8 @@ def get_build_plan(self) -> list[BuildInfo]:
)

for platform_entry, platform in self.platforms.items():
for build_for in platform.build_for or [SnapArch(platform_entry)]:
for build_on in platform.build_on or [SnapArch(platform_entry)]:
for build_for in platform.build_for or [SnapArch(platform_entry).value]:
for build_on in platform.build_on or [SnapArch(platform_entry).value]:
build_infos.append(
BuildInfo(
platform=platform_entry,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--build-for amd64,s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-snap-build-for-arg-core22_1.0_amd64.snap
test-snap-build-for-arg-core22_1.0_s390x.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test-snap-build-for-arg-core22
base: core22
version: "1.0"
summary: Test snap for remote build
description: Test snap for remote build

grade: stable
confinement: strict

parts:
my-part:
plugin: nil
9 changes: 8 additions & 1 deletion tests/spread/core22/remote-build/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:
SNAP/all: all
SNAP/no_architectures: no-architectures
SNAP/architectures: architectures
SNAP/build_for_arg: build-for-arg
SNAPCRAFT_REMOTE_BUILD_STRATEGY: disable-fallback
CREDENTIALS_FILE: "$HOME/.local/share/snapcraft/launchpad-credentials"
CREDENTIALS_FILE/new_credentials: "$HOME/.local/share/snapcraft/launchpad-credentials"
Expand Down Expand Up @@ -39,7 +40,13 @@ restore: |
execute: |
cd "./snaps/$SNAP"
snapcraft remote-build --launchpad-accept-public-upload
call_args=""
if [[ -e "arguments.txt" ]]; then
call_args=$(cat "arguments.txt")
fi
# shellcheck disable=SC2086
snapcraft remote-build --launchpad-accept-public-upload $call_args
find . -maxdepth 1 -name "*.snap" | MATCH ".snap"
Expand Down
3 changes: 3 additions & 0 deletions tests/spread/core24/npm-reentrant/hello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log('hello world');
5 changes: 5 additions & 0 deletions tests/spread/core24/npm-reentrant/package-lock.json

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

13 changes: 13 additions & 0 deletions tests/spread/core24/npm-reentrant/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "npm-hello",
"version": "1.0.0",
"description": "Testing grounds for snapcraft integration tests",
"bin": {
"npm-hello": "hello.js"
},
"scripts": {
"npm-hello": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "GPL-3.0"
}
15 changes: 15 additions & 0 deletions tests/spread/core24/npm-reentrant/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: npm-reentrant
version: "1.0"
summary: test the npm plugin
description: Check that the npm plugin works across snapcraft calls

confinement: strict
grade: devel
base: core24

parts:
hello:
source: .
plugin: npm
npm-include-node: true
npm-node-version: 22.1.0
11 changes: 11 additions & 0 deletions tests/spread/core24/npm-reentrant/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
summary: Pull, then Build, a Node snap

execute: |
snapcraft pull
snapcraft build
snapcraft pack
test -f npm-reentrant*.snap
restore: |
snapcraft clean
rm -f ./*.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implicit-build-for_1.0_riscv64.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: implicit-build-for
version: "1.0"
summary: test
description: |
Use the platform name implicitly for the `build-for`.
confinement: strict
base: core24

platforms:
riscv64:
build-on: [amd64]

parts:
my-part:
plugin: nil
1 change: 1 addition & 0 deletions tests/spread/core24/platforms/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
SNAP/env_var_all: env-var-all
SNAP/env_var_match: env-var-match
SNAP/env_var_no_match: env-var-no-match
SNAP/implicit_build_for: implicit-build-for
SNAP/multiple_build_for: multiple-build-for
SNAP/platform_all: platform-all
SNAP/platform_match: platform-match
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--build-for amd64,s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-snap-build-for-arg-core24_1.0_amd64.snap
test-snap-build-for-arg-core24_1.0_s390x.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test-snap-build-for-arg-core24
base: core24
version: "1.0"
summary: Test snap for remote build
description: Test snap for remote build

grade: stable
confinement: strict

parts:
my-part:
plugin: nil
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--platform amd64,s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-snap-platform-arg-core24_1.0_amd64.snap
test-snap-platform-arg-core24_1.0_s390x.snap
12 changes: 12 additions & 0 deletions tests/spread/core24/remote-build/snaps/platform-arg/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test-snap-platform-arg-core24
base: core24
version: "1.0"
summary: Test snap for remote build
description: Test snap for remote build

grade: stable
confinement: strict

parts:
my-part:
plugin: nil
Loading

0 comments on commit 62dacfb

Please sign in to comment.