Skip to content

Commit

Permalink
feat: package component hooks for core22 (#4722)
Browse files Browse the repository at this point in the history
Package component hooks for core22.

The code was already completed via #4717, it just needed to be enabled.

Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal authored Apr 11, 2024
1 parent 3d12a68 commit 9a5dbfa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
5 changes: 1 addition & 4 deletions snapcraft/parts/setup_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def setup_assets(
copy_assets(assets_dir, prime_dir, meta_directory_handler)
setup_hooks(project.hooks, prime_dir)

# core22 doesn't provide a meta_directory_handler, which means that core22 component
# hooks would be handled like core22 snap hooks (with hook wrappers).
# This behavior is not desired, so component hooks are currently ignored for core22.
if project.components and project.get_effective_base() != "core22":
if project.components:
for component_name, component in project.components.items():
copy_assets(
assets_dir / "component" / component_name,
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions tests/spread/core22/components/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ parts:
prime:
# exclude a file in a partition
- -(component/share)/other-file-in-component

# 'install' is a project hook (in 'snap/component/share/hooks/')
# 'remove' is generated at build time
hooks:
source: .
plugin: dump
override-build: |
touch ${CRAFT_PART_INSTALL}/remove
chmod +x ${CRAFT_PART_INSTALL}/remove
craftctl default
organize:
remove: (component/share)/meta/hooks/remove
18 changes: 16 additions & 2 deletions tests/spread/core22/components/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,22 @@ execute: |
exit 1
fi
# assert contents of component metadata
if ! diff -u component-contents/meta/component.yaml expected-component.yaml; then
component_meta_dir="component-contents/meta"
# assert component metadata
if ! diff -u "${component_meta_dir}/component.yaml" expected-component.yaml; then
echo "Metadata for the share component is incorrect."
exit 1
fi
# assert component hooks
if [ ! -f "${component_meta_dir}/hooks/install" ] || [ ! -f "${component_meta_dir}/hooks/remove" ]; then
echo "Expected component hooks to be present."
exit 1
fi
# assert project hook has a hook wrapper
if [ ! -f component-contents/snap/hooks/install ]; then
echo "Expected hook wrapper to be present."
exit 1
fi

0 comments on commit 9a5dbfa

Please sign in to comment.