From 8f6333af61f86a1d284dd79f009df15205b41e2e Mon Sep 17 00:00:00 2001 From: Ondrej Kubik Date: Mon, 5 Jun 2023 18:20:36 +0100 Subject: [PATCH] kernel plugin: change location where snapd deb is unpacked `ubnutu-core-initramfs` tool changed where `snap-boostrap` is fetched from. It assumes `snap-bootstrap` from passed `--root` to be used. Unpack the downloaded snapd debian package to the same directory where "ubnutu-core-initramfs" debian package is unpacked. This directory is already passed to the `ubnutu-core-initramfs` tool as `--root` Signed-off-by: Ondrej Kubik --- snapcraft/parts/plugins/kernel.py | 1 - snapcraft_legacy/plugins/v2/_kernel_build.py | 10 +++++----- snapcraft_legacy/plugins/v2/kernel.py | 1 - tests/legacy/unit/plugins/v2/test_kernel.py | 17 +++++++---------- tests/unit/parts/plugins/test_kernel.py | 17 +++++++---------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/snapcraft/parts/plugins/kernel.py b/snapcraft/parts/plugins/kernel.py index 514657ec52..8dbc63a787 100644 --- a/snapcraft/parts/plugins/kernel.py +++ b/snapcraft/parts/plugins/kernel.py @@ -447,7 +447,6 @@ def get_build_environment(self) -> Dict[str, str]: "ARCH": self._kernel_arch, "DEB_ARCH": "${CRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${CRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${CRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{CRAFT_PART_BUILD}}/arch/{self._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": self.kernel_image_target, } diff --git a/snapcraft_legacy/plugins/v2/_kernel_build.py b/snapcraft_legacy/plugins/v2/_kernel_build.py index 5179090646..38cb062f1e 100644 --- a/snapcraft_legacy/plugins/v2/_kernel_build.py +++ b/snapcraft_legacy/plugins/v2/_kernel_build.py @@ -211,8 +211,8 @@ def _download_snap_bootstrap_cmd(target_arch: str) -> List[str]: echo "Getting snapd deb for snap bootstrap..." # only download again if files does not exist, otherwise # assume we are re-running build - if [ ! -e ${{SNAPD_UNPACKED_SNAP}} ]; then - download_snap_bootstrap {arch} ${{SNAPD_UNPACKED_SNAP}} + if [ ! -e ${{UC_INITRD_DEB}}/usr/lib/snapd ]; then + download_snap_bootstrap {arch} ${{UC_INITRD_DEB}} fi """.format( arch=target_arch @@ -709,7 +709,7 @@ def _make_initrd_cmd( " ".join( [ "link_files", - '"${SNAPD_UNPACKED_SNAP}"', + '"${UC_INITRD_DEB}"', '"usr/lib/snapd/snap-bootstrap"', '"${uc_initrd_feature_snap_bootstratp}"', ] @@ -717,7 +717,7 @@ def _make_initrd_cmd( " ".join( [ "link_files", - '"${SNAPD_UNPACKED_SNAP}"', + '"${UC_INITRD_DEB}"', '"usr/lib/snapd/info"', '"${uc_initrd_feature_snap_bootstratp}"', ] @@ -725,7 +725,7 @@ def _make_initrd_cmd( " ".join( [ "cp", - "${SNAPD_UNPACKED_SNAP}/usr/lib/snapd/info", + "${UC_INITRD_DEB}/usr/lib/snapd/info", f"{install_dir}/snapd-info", ] ), diff --git a/snapcraft_legacy/plugins/v2/kernel.py b/snapcraft_legacy/plugins/v2/kernel.py index 1ece2957d1..aaee65c33c 100644 --- a/snapcraft_legacy/plugins/v2/kernel.py +++ b/snapcraft_legacy/plugins/v2/kernel.py @@ -490,7 +490,6 @@ def get_build_environment(self) -> Dict[str, str]: "ARCH": self._kernel_arch, "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${SNAPCRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${SNAPCRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{SNAPCRAFT_PART_BUILD}}/arch/{self._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": self.kernel_image_target, } diff --git a/tests/legacy/unit/plugins/v2/test_kernel.py b/tests/legacy/unit/plugins/v2/test_kernel.py index 1bc95d9eeb..3344862804 100644 --- a/tests/legacy/unit/plugins/v2/test_kernel.py +++ b/tests/legacy/unit/plugins/v2/test_kernel.py @@ -503,7 +503,6 @@ def test_check_get_build_environment(self): "ARCH": plugin._kernel_arch, "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${SNAPCRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${SNAPCRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{SNAPCRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, }, @@ -524,7 +523,6 @@ def test_check_get_build_environment_compiler_paths_cross(self): "ARCH": "arm", "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${SNAPCRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${SNAPCRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": "${SNAPCRAFT_PART_BUILD}/arch/arm/boot", "KERNEL_IMAGE_TARGET": "Image.gz", "PATH": "${SNAPCRAFT_STAGE}/gcc-11/bin:${PATH}", @@ -544,7 +542,6 @@ def test_check_get_build_environment_compiler_paths(self): "ARCH": plugin._kernel_arch, "DEB_ARCH": "${SNAPCRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${SNAPCRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${SNAPCRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{SNAPCRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, "PATH": "${SNAPCRAFT_STAGE}/gcc-11/bin:${SNAPCRAFT_STAGE}/gcc-11/sbin:${PATH}", @@ -1237,8 +1234,8 @@ def _is_sub_array(array, sub_array): echo "Getting snapd deb for snap bootstrap..." # only download again if files does not exist, otherwise # assume we are re-running build - if [ ! -e ${{SNAPD_UNPACKED_SNAP}} ]; then - download_snap_bootstrap {arch} ${{SNAPD_UNPACKED_SNAP}} + if [ ! -e ${{UC_INITRD_DEB}}/usr/lib/snapd ]; then + download_snap_bootstrap {arch} ${{UC_INITRD_DEB}} fi """.format( arch=_DEB_ARCH_TRANSLATIONS[platform.machine()] @@ -1252,8 +1249,8 @@ def _is_sub_array(array, sub_array): echo "Getting snapd deb for snap bootstrap..." # only download again if files does not exist, otherwise # assume we are re-running build - if [ ! -e ${{SNAPD_UNPACKED_SNAP}} ]; then - download_snap_bootstrap {arch} ${{SNAPD_UNPACKED_SNAP}} + if [ ! -e ${{UC_INITRD_DEB}}/usr/lib/snapd ]; then + download_snap_bootstrap {arch} ${{UC_INITRD_DEB}} fi """.format( arch="armhf" @@ -1662,12 +1659,12 @@ def _is_sub_array(array, sub_array): " ".join( [ "link_files", - '"${SNAPD_UNPACKED_SNAP}" "usr/lib/snapd/snap-bootstrap"', + '"${UC_INITRD_DEB}" "usr/lib/snapd/snap-bootstrap"', '"${uc_initrd_feature_snap_bootstratp}"', ], ), - 'link_files "${SNAPD_UNPACKED_SNAP}" "usr/lib/snapd/info" "${uc_initrd_feature_snap_bootstratp}"', - "cp ${SNAPD_UNPACKED_SNAP}/usr/lib/snapd/info ${SNAPCRAFT_PART_INSTALL}/snapd-info", + 'link_files "${UC_INITRD_DEB}" "usr/lib/snapd/info" "${uc_initrd_feature_snap_bootstratp}"', + "cp ${UC_INITRD_DEB}/usr/lib/snapd/info ${SNAPCRAFT_PART_INSTALL}/snapd-info", ] _clean_old_initrd_cmd = [ diff --git a/tests/unit/parts/plugins/test_kernel.py b/tests/unit/parts/plugins/test_kernel.py index c49b01fc8f..ec04c31daa 100644 --- a/tests/unit/parts/plugins/test_kernel.py +++ b/tests/unit/parts/plugins/test_kernel.py @@ -382,7 +382,6 @@ def test_check_get_build_environment(self, setup_method_fixture, new_dir): "ARCH": plugin._kernel_arch, "DEB_ARCH": "${CRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${CRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${CRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{CRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, } @@ -404,7 +403,6 @@ def test_check_get_build_environment_compiler_paths_cross( "ARCH": "arm", "DEB_ARCH": "${CRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${CRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${CRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": "${CRAFT_PART_BUILD}/arch/arm/boot", "KERNEL_IMAGE_TARGET": "Image.gz", "PATH": "${CRAFT_STAGE}/gcc-11/bin:${PATH}", @@ -426,7 +424,6 @@ def test_check_get_build_environment_compiler_paths( "ARCH": plugin._kernel_arch, "DEB_ARCH": "${CRAFT_TARGET_ARCH}", "UC_INITRD_DEB": "${CRAFT_PART_BUILD}/ubuntu-core-initramfs", - "SNAPD_UNPACKED_SNAP": "${CRAFT_PART_BUILD}/unpacked_snapd", "KERNEL_BUILD_ARCH_DIR": f"${{CRAFT_PART_BUILD}}/arch/{plugin._kernel_arch}/boot", "KERNEL_IMAGE_TARGET": plugin.kernel_image_target, "PATH": "${CRAFT_STAGE}/gcc-11/bin:${CRAFT_STAGE}/gcc-11/sbin:${PATH}", @@ -1340,8 +1337,8 @@ def _is_sub_array(array, sub_array): echo "Getting snapd deb for snap bootstrap..." # only download again if files does not exist, otherwise # assume we are re-running build - if [ ! -e ${{SNAPD_UNPACKED_SNAP}} ]; then - download_snap_bootstrap {_machine_arch} ${{SNAPD_UNPACKED_SNAP}} + if [ ! -e ${{UC_INITRD_DEB}}/usr/lib/snapd ]; then + download_snap_bootstrap {_machine_arch} ${{UC_INITRD_DEB}} fi """ ) @@ -1353,8 +1350,8 @@ def _is_sub_array(array, sub_array): echo "Getting snapd deb for snap bootstrap..." # only download again if files does not exist, otherwise # assume we are re-running build - if [ ! -e ${SNAPD_UNPACKED_SNAP} ]; then - download_snap_bootstrap armhf ${SNAPD_UNPACKED_SNAP} + if [ ! -e ${UC_INITRD_DEB}/usr/lib/snapd ]; then + download_snap_bootstrap armhf ${UC_INITRD_DEB} fi """ ) @@ -1772,13 +1769,13 @@ def _is_sub_array(array, sub_array): " ".join( [ "link_files", - '"${SNAPD_UNPACKED_SNAP}" "usr/lib/snapd/snap-bootstrap"', + '"${UC_INITRD_DEB}" "usr/lib/snapd/snap-bootstrap"', '"${uc_initrd_feature_snap_bootstratp}"', ], ), - 'link_files "${SNAPD_UNPACKED_SNAP}" "usr/lib/snapd/info"' + 'link_files "${UC_INITRD_DEB}" "usr/lib/snapd/info"' ' "${uc_initrd_feature_snap_bootstratp}"', - "cp ${SNAPD_UNPACKED_SNAP}/usr/lib/snapd/info ${CRAFT_PART_INSTALL}/snapd-info", + "cp ${UC_INITRD_DEB}/usr/lib/snapd/info ${CRAFT_PART_INSTALL}/snapd-info", ] _clean_old_initrd_cmd = [