From 888e416b6096e21ffc8ce14e8304fa7eaa623fe0 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Wed, 23 Aug 2023 15:09:27 +0200 Subject: [PATCH] kernel plugin: properly generate Ubuntu kernel .config (#4210) Recent Ubuntu kernels (>= Jammy) are now using a new format to store their .config, called annotations [1]. The kernel plugin is trying to assemble a .config using the old config chunks stored in `debian./config/*` that are not available anymore in the kernels that are using this new annotations model. Instead of trying to manually assemble the config we should rely on `debian/rules genconfigs` that is more portable across different Ubuntu kernels and releases. [1] https://lists.ubuntu.com/archives/kernel-team/2023-June/140230.html Signed-off-by: Andrea Righi --- snapcraft_legacy/plugins/v2/_kernel_build.py | 19 +++++++++++-------- tests/legacy/unit/plugins/v2/test_kernel.py | 19 +++++++++++-------- tests/unit/parts/plugins/test_kernel.py | 19 +++++++++++-------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/snapcraft_legacy/plugins/v2/_kernel_build.py b/snapcraft_legacy/plugins/v2/_kernel_build.py index 38cb062f1ec..b04e3e0eb14 100644 --- a/snapcraft_legacy/plugins/v2/_kernel_build.py +++ b/snapcraft_legacy/plugins/v2/_kernel_build.py @@ -278,17 +278,20 @@ def _do_base_config_cmd( logger.info("Using ubuntu config flavour %s", config_flavour) conf_cmd = textwrap.dedent( """ echo "Assembling Ubuntu config..." - branch=$(cut -d'.' -f 2- < ${{KERNEL_SRC}}/debian/debian.env) - baseconfigdir=${{KERNEL_SRC}}/debian.${{branch}}/config - archconfigdir=${{KERNEL_SRC}}/debian.${{branch}}/config/${{DEB_ARCH}} - ubuntuconfig=${{baseconfigdir}}/config.common.ubuntu - archconfig=${{archconfigdir}}/config.common.${{DEB_ARCH}} - flavourconfig=${{archconfigdir}}/config.flavour.{config_flavour} - cat ${{ubuntuconfig}} ${{archconfig}} ${{flavourconfig}} \ -> {dest_dir}/.config 2>/dev/null || true if [ -f ${{KERNEL_SRC}}/debian/rules ] && [ -x ${{KERNEL_SRC}}/debian/rules ]; then + # Generate Ubuntu kernel configs + pushd ${{KERNEL_SRC}} + fakeroot debian/rules clean genconfigs || true + popd + + # Pick the right kernel .config for the target arch and flavour + ubuntuconfig=${{KERNEL_SRC}}/CONFIGS/${{DEB_ARCH}}-config.flavour.{config_flavour} + cat ${{ubuntuconfig}} > {dest_dir}/.config + + # Clean up kernel source directory pushd ${{KERNEL_SRC}} fakeroot debian/rules clean + rm -rf CONFIGS/ popd fi""".format( config_flavour=config_flavour, dest_dir=dest_dir diff --git a/tests/legacy/unit/plugins/v2/test_kernel.py b/tests/legacy/unit/plugins/v2/test_kernel.py index 81dd38910f1..939316c14b3 100644 --- a/tests/legacy/unit/plugins/v2/test_kernel.py +++ b/tests/legacy/unit/plugins/v2/test_kernel.py @@ -1302,17 +1302,20 @@ def _is_sub_array(array, sub_array): "if [ ! -e ${SNAPCRAFT_PART_BUILD}/.config ]; then", textwrap.dedent( """ echo "Assembling Ubuntu config..." - branch=$(cut -d'.' -f 2- < ${KERNEL_SRC}/debian/debian.env) - baseconfigdir=${KERNEL_SRC}/debian.${branch}/config - archconfigdir=${KERNEL_SRC}/debian.${branch}/config/${DEB_ARCH} - ubuntuconfig=${baseconfigdir}/config.common.ubuntu - archconfig=${archconfigdir}/config.common.${DEB_ARCH} - flavourconfig=${archconfigdir}/config.flavour.raspi - cat ${ubuntuconfig} ${archconfig} ${flavourconfig} \ -> ${SNAPCRAFT_PART_BUILD}/.config 2>/dev/null || true if [ -f ${KERNEL_SRC}/debian/rules ] && [ -x ${KERNEL_SRC}/debian/rules ]; then + # Generate Ubuntu kernel configs + pushd ${KERNEL_SRC} + fakeroot debian/rules clean genconfigs || true + popd + + # Pick the right kernel .config for the target arch and flavour + ubuntuconfig=${KERNEL_SRC}/CONFIGS/${DEB_ARCH}-config.flavour.raspi + cat ${ubuntuconfig} > ${SNAPCRAFT_PART_BUILD}/.config + + # Clean up kernel source directory pushd ${KERNEL_SRC} fakeroot debian/rules clean + rm -rf CONFIGS/ popd fi""" ), diff --git a/tests/unit/parts/plugins/test_kernel.py b/tests/unit/parts/plugins/test_kernel.py index db708ba3d88..180676276f9 100644 --- a/tests/unit/parts/plugins/test_kernel.py +++ b/tests/unit/parts/plugins/test_kernel.py @@ -1401,17 +1401,20 @@ def _is_sub_array(array, sub_array): "if [ ! -e ${CRAFT_PART_BUILD}/.config ]; then", textwrap.dedent( """ echo "Assembling Ubuntu config..." - branch=$(cut -d'.' -f 2- < ${KERNEL_SRC}/debian/debian.env) - baseconfigdir=${KERNEL_SRC}/debian.${branch}/config - archconfigdir=${KERNEL_SRC}/debian.${branch}/config/${DEB_ARCH} - ubuntuconfig=${baseconfigdir}/config.common.ubuntu - archconfig=${archconfigdir}/config.common.${DEB_ARCH} - flavourconfig=${archconfigdir}/config.flavour.raspi - cat ${ubuntuconfig} ${archconfig} ${flavourconfig} \ -> ${CRAFT_PART_BUILD}/.config 2>/dev/null || true if [ -f ${KERNEL_SRC}/debian/rules ] && [ -x ${KERNEL_SRC}/debian/rules ]; then + # Generate Ubuntu kernel configs + pushd ${KERNEL_SRC} + fakeroot debian/rules clean genconfigs || true + popd + + # Pick the right kernel .config for the target arch and flavour + ubuntuconfig=${KERNEL_SRC}/CONFIGS/${DEB_ARCH}-config.flavour.raspi + cat ${ubuntuconfig} > ${CRAFT_PART_BUILD}/.config + + # Clean up kernel source directory pushd ${KERNEL_SRC} fakeroot debian/rules clean + rm -rf CONFIGS/ popd fi""" ),