Skip to content

Commit

Permalink
kernel plugin: properly generate Ubuntu kernel .config (#4210)
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 authored Aug 23, 2023
1 parent 7f8d4cf commit da90067
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 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
19 changes: 11 additions & 8 deletions tests/legacy/unit/plugins/v2/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
),
Expand Down
19 changes: 11 additions & 8 deletions tests/unit/parts/plugins/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
),
Expand Down

0 comments on commit da90067

Please sign in to comment.