Skip to content

Commit

Permalink
kernel plugin: properly generate Ubuntu kernel .config
Browse files Browse the repository at this point in the history
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.<kernel>/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 <andrea.righi@canonical.com>
  • Loading branch information
Andrea Righi committed Jul 12, 2023
1 parent 7c80a05 commit c96d021
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
19 changes: 11 additions & 8 deletions snapcraft_legacy/plugins/v2/_kernel_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions tests/legacy/unit/plugins/v2/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,18 +1302,14 @@ 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
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.${flavourconfig}
cat ${ubuntuconfig} > ${SNAPCRAFT_PART_BUILD}/.config
fi"""
),
"fi",
Expand Down
14 changes: 5 additions & 9 deletions tests/unit/parts/plugins/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,18 +1401,14 @@ 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
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.${flavourconfig}
cat ${ubuntuconfig} > ${CRAFT_PART_BUILD}/.config
fi"""
),
"fi",
Expand Down

0 comments on commit c96d021

Please sign in to comment.