Skip to content

Commit

Permalink
plugins: initrd: error out with message if stage contains more than o…
Browse files Browse the repository at this point in the history
…ne kernel build

Signed-off-by: Ondrej Kubik <[email protected]>
  • Loading branch information
kubiko committed Nov 28, 2024
1 parent 39c5567 commit 9437485
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
13 changes: 11 additions & 2 deletions snapcraft_legacy/plugins/v2/_initrd_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,17 @@ def get_build_commands(
def _parse_kernel_release_cmd() -> List[str]:
"""Set kernel release from module/<release> directory name."""
return [
'echo "Parsing kernel release..."',
'KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")',
textwrap.dedent(
"""
echo "Parsing kernel release..."
KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")
space_regex="[[:space:]]+"
if [[ ${KERNEL_RELEASE} =~ ${space_regex} ]]; then
echo "ERROR: ${CRAFT_STAGE}/modules contains more than one kernel version, clean up your build environment!"
exit 1
fi
"""
)
]


Expand Down
12 changes: 11 additions & 1 deletion tests/legacy/unit/plugins/v2/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,17 @@ def _is_sub_array(array, sub_array):
]

_parse_kernel_release_cmd = [
'KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")',
textwrap.dedent(
"""
echo "Parsing kernel release..."
KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")
space_regex="[[:space:]]+"
if [[ ${KERNEL_RELEASE} =~ ${space_regex} ]]; then
echo "ERROR: ${CRAFT_STAGE}/modules contains more than one kernel version, clean up your build environment!"
exit 1
fi
"""
)
]

_install_initrd_modules_cmd = [
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/parts/plugins/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,17 @@ def _is_sub_array(array, sub_array):
]

_parse_kernel_release_cmd = [
'KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")',
textwrap.dedent(
"""
echo "Parsing kernel release..."
KERNEL_RELEASE=$(ls "${CRAFT_STAGE}/modules")
space_regex="[[:space:]]+"
if [[ ${KERNEL_RELEASE} =~ ${space_regex} ]]; then
echo "ERROR: ${CRAFT_STAGE}/modules contains more than one kernel version, clean up your build environment!"
exit 1
fi
"""
)
]

_install_initrd_modules_cmd = [
Expand Down

0 comments on commit 9437485

Please sign in to comment.