From 9437485c838ee9d35611966152daad56f1008b4e Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Tue, 19 Nov 2024 22:23:01 +0000 Subject: [PATCH] plugins: initrd: error out with message if stage contains more than one kernel build Signed-off-by: Ondrej Kubik --- snapcraft_legacy/plugins/v2/_initrd_build.py | 13 +++++++++++-- tests/legacy/unit/plugins/v2/test_initrd.py | 12 +++++++++++- tests/unit/parts/plugins/test_initrd.py | 12 +++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/snapcraft_legacy/plugins/v2/_initrd_build.py b/snapcraft_legacy/plugins/v2/_initrd_build.py index 719f07eee9..b21c8702d2 100644 --- a/snapcraft_legacy/plugins/v2/_initrd_build.py +++ b/snapcraft_legacy/plugins/v2/_initrd_build.py @@ -687,8 +687,17 @@ def get_build_commands( def _parse_kernel_release_cmd() -> List[str]: """Set kernel release from module/ 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 + """ + ) ] diff --git a/tests/legacy/unit/plugins/v2/test_initrd.py b/tests/legacy/unit/plugins/v2/test_initrd.py index 7fff0df9a5..1a42533ece 100755 --- a/tests/legacy/unit/plugins/v2/test_initrd.py +++ b/tests/legacy/unit/plugins/v2/test_initrd.py @@ -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 = [ diff --git a/tests/unit/parts/plugins/test_initrd.py b/tests/unit/parts/plugins/test_initrd.py index 019fc3d118..2588534b5a 100644 --- a/tests/unit/parts/plugins/test_initrd.py +++ b/tests/unit/parts/plugins/test_initrd.py @@ -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 = [