From patchwork Mon Jan 16 16:58:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1727168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=eJUPv4a9; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NwdXF6FTXz23fT for ; Tue, 17 Jan 2023 03:58:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pHSof-00016m-Hc; Mon, 16 Jan 2023 16:58:37 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pHSoc-00016a-NI for kernel-team@lists.ubuntu.com; Mon, 16 Jan 2023 16:58:34 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 011F83F328 for ; Mon, 16 Jan 2023 16:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1673888312; bh=t0F1C6keueV7GNUmQHdWGQCOfM/ATTTz03ckfYcG4Kg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=eJUPv4a9lsgQHoDYooGzh953hO+/rLwOAxAt+WlFckOpq+4c6A+uODvLmN0aWRgEy ukfh0VccvgHiKIrI7dvKBWSghq9zprPpRD3Z4fZQNoIuyp1brfl/8DphSMOZqXJapP zN1wDyoYkuS0GEaloWNJU8VlCM4WJwZvNbjVVliTPoMMmcWrV6oVPSarSZgwur7JHV yoKOstiWGaYwbZTFu+t/rVgf08RpQSDfhfLK5SltBX5ICCwuGnv0mVtpwE1DrHhv3D FgfgrisL2Mn1FMmqzsPIpR2+IWyiCfIvVCuo473j0QZkwTERQuhvG6rOuTawRyQXTV pMMSg/L5wbbCg== Received: by mail-ej1-f70.google.com with SMTP id nc27-20020a1709071c1b00b0086dae705676so3771966ejc.12 for ; Mon, 16 Jan 2023 08:58:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t0F1C6keueV7GNUmQHdWGQCOfM/ATTTz03ckfYcG4Kg=; b=i20Z6FQozUgObUVKCz2WWKIHynO57+xbbBnOgUkJcve17SpXIoPwY1zzt5tDdIUGVm qZNe88MSAYtVn0FEUJVNo8iT2N7yE2S8CoZRHmazukVxKDHLw9lrwwE5AP1+lokPbu+8 GdPfam9FNrXajyf7+kyfqPmbBOxYk4OZsq+qyi7bhxWHHPE3FYW+Evfqzmev7R0GJzng b6bKwJ/NrieOr20e79ReBfZS4H4LKzqPpyqOjGytPPvlFGhULXa2jom6z8cBjN+tfy5W DHb3/Gu1zs6CgirmzvsastcCaKDF+I9ZPcKpngzZk1QR5bclH+Ji9UWjWRcNzd8igJPK 9ZvQ== X-Gm-Message-State: AFqh2kr0FUU1sKth3Om2nu7j//ZLkowsS7IGYzvufEsNGC/xNYUTvMaZ yhAaDJwst6g/1Y2LLYdSdt9/ybndWTrv2p4nvnIxlfGzZq4Hey97rpODpf0/dOvAjo1LbsgRknG 5hjGq7KhMaW64pSI7P85E6twgHP2a4gJyVCgSiSISdQ== X-Received: by 2002:aa7:d642:0:b0:499:d208:e8f4 with SMTP id v2-20020aa7d642000000b00499d208e8f4mr20237722edr.19.1673888311194; Mon, 16 Jan 2023 08:58:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXv4SBEGGhFS7G8JHsvkjc+8x5AJqQWhDU5GrHeE+zGrIB5CSOGP1xGCWnpKbbQSkAeQKDP8Lg== X-Received: by 2002:aa7:d642:0:b0:499:d208:e8f4 with SMTP id v2-20020aa7d642000000b00499d208e8f4mr20237708edr.19.1673888310946; Mon, 16 Jan 2023 08:58:30 -0800 (PST) Received: from localhost.localdomain ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id a3-20020aa7cf03000000b0049019b48373sm11673046edy.85.2023.01.16.08.58.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:58:30 -0800 (PST) From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [Unstable/Lunar][PATCH] UBUNTU: [Packaging] scripts/misc/kernelconfig: Rewrite Date: Mon, 16 Jan 2023 17:58:27 +0100 Message-Id: <20230116165827.501424-1-juerg.haefliger@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" The kernelconfig script evolved over a long time and accumulated quite some cruft. With the switch to using annotations only, that got even worse so it's time for a major overhaul. Rather than sending tons of little patches, just rewrite the whole script and also ensure shellcheck is happy. No functional changes intended. Signed-off-by: Juerg Haefliger --- debian/scripts/misc/kernelconfig | 219 +++++++++++++++---------------- 1 file changed, 107 insertions(+), 112 deletions(-) diff --git a/debian/scripts/misc/kernelconfig b/debian/scripts/misc/kernelconfig index 37ad900a205c..0c412af2ec8e 100755 --- a/debian/scripts/misc/kernelconfig +++ b/debian/scripts/misc/kernelconfig @@ -1,157 +1,152 @@ -#!/bin/bash +#!/bin/bash -u -. debian/debian.env +function cleanup() +{ + rm -rf build "${TMP_DIR}" +} -# We have to be in the top level kernel source directory -if [ ! -f MAINTAINERS ] || [ ! -f Makefile ]; then - echo "This does not appear to be the kernel source directory." 1>&2 +# We have to be in the top level Ubuntu kernel source directory +if ! [ -e debian/debian.env ] ; then + echo "ERROR: This is not an Ubuntu kernel source directory" >&2 exit 1 fi -mode=${1:?"Usage: $0 (updateconfigs|defaultconfigs|genconfigs)"} -yes=0 -genconfigs=0 -case "$mode" in - update*configs) mode='syncconfig' ;; - default*configs) mode='oldconfig'; yes=1 ;; - gen*configs) mode='genconfigs'; genconfigs=1 ;; - *) echo "$0 called with invalid mode" 1>&2 - exit 1 ;; -esac - -if [ -z "$gcc" ]; then - echo "ERROR: gcc environment variable must be set" - exit 1 +if [ -z "${gcc:-}" ] ; then + echo "ERROR: 'gcc' environment variable must be set" >&2 + exit 1 fi -kerneldir="`pwd`" -confdir="$kerneldir/${DEBIAN}/config" -variant="$2" - -# TODO: Drop this once all derivatives have migrated to the new annotations -# scheme -if [ -e $DEBIAN/etc/kernelconfig ] ; then - . $DEBIAN/etc/kernelconfig +if [ ${#} -ne 1 ] ; then + echo "Usage: $0 updateconfigs|defaultconfigs|genconfigs" + exit 2 fi -bindir="`pwd`/${DROOT}/scripts/misc" -tmpdir=`mktemp -d` +mode=${1} -if [ "$genconfigs" == "1" ]; then - mode="oldconfig" -fi +case "${mode}" in + updateconfigs) target="syncconfig" ;; + defaultconfigs) target="olddefconfig" ;; + genconfigs) target="oldconfig" ;; + *) echo "ERROR: Invalid mode: ${1}" >&2 + exit 1 ;; +esac -warning_partial= +. debian/debian.env -# Use annotations to generate configs -ARCHES=$(sed -ne 's/^# ARCH: \(.*\)/\1/p' < ${confdir}/annotations) -FLAVOURS=$(sed -ne 's/^# FLAVOUR: \(.*\)/\1/p' < ${confdir}/annotations) +annotations_file=${DEBIAN}/config/annotations +warning_partial=() -for flavour in ${FLAVOURS}; do - arch=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\1/') - flavour=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\2/') - conf_file=${arch}-config.flavour.${flavour} +TMP_DIR=$(mktemp -d) +trap cleanup EXIT - rm -rf build - mkdir build +# Use annotations to generate configs +FLAVOURS=$(sed -ne 's/^# FLAVOUR: //p' "${annotations_file}") - # Generate .config from annotations (if a previosly generate config is - # available use that). - if [ -e "${tmpdir}/${conf_file}" ]; then - cat ${tmpdir}/${conf_file} > build/.config - else - python3 ${bindir}/annotations -f ${confdir}/annotations --arch ${arch} --flavour ${flavour} --export > build/.config - fi +for arch_flavour in ${FLAVOURS} ; do + arch=${arch_flavour%%-*} + flavour=${arch_flavour#*-} + tmp_conf_file=${TMP_DIR}/${arch}-config.flavour.${flavour} # Map debian archs to kernel archs - case "$arch" in - ppc64|ppc64el) kernarch="powerpc" ;; - amd64) kernarch="x86_64" ;; - lpia) kernarch="x86" ;; - sparc) kernarch="sparc64" ;; - armel|armhf) kernarch="arm" ;; - s390x) kernarch="s390" ;; - riscv64) kernarch="riscv" ;; - *) kernarch="$arch" ;; + case "${arch}" in + amd64) kern_arch="x86_64" ;; + arm64) kern_arch="arm64" ;; + armhf) kern_arch="arm" ;; + ppc64el) kern_arch="powerpc" ;; + riscv64) kern_arch="riscv" ;; + s390x) kern_arch="s390" ;; + *) echo "WARNING: Unsupported architecture: ${arch}" + warning_partial+=("${arch}") + continue ;; esac # Determine cross toolchain to use for Kconfig compiler tests - cross_compile="$(dpkg-architecture -qDEB_HOST_GNU_TYPE -a$arch 2>/dev/null)-" + cross_compile="$(dpkg-architecture -qDEB_HOST_GNU_TYPE -a"${arch}" 2>/dev/null)-" # Arch-specific compiler, if any - archgcc=$(echo -e "show-%:\n\t@echo \$(\$*)\ninclude $DEBIAN/rules.d/$arch.mk" | make -s -f - show-gcc) - - # Environment variables for 'make *config'. We omit CROSS_COMPILE - # for i386 since it is no longer supported after 19.04, however - # we maintain the configs for hwe. - modify_config=true - env="ARCH=$kernarch DEB_ARCH=$arch" - compiler_path=$(which "${cross_compile}${archgcc:-$gcc}" || true) - if [ "$compiler_path" != '' ]; then - env="$env CROSS_COMPILE=$cross_compile CC=$compiler_path" - else - echo "WARNING: ${cross_compile}gcc not installed" - modify_config= - warning_partial="$warning_partial $arch" + arch_gcc=$(cat < build/.config + + # Environment variables for 'make *config' + env=(ARCH="${kern_arch}" + DEB_ARCH="${arch}" + CROSS_COMPILE="${cross_compile}" + CC="${gcc_path}") + + # Concurrency level + if [ -n "${conc_level:-}" ] ; then + env+=("${conc_level}") fi - # Export config for config-check (or genconfigs) - cat build/.config > ${tmpdir}/${conf_file} + # Call config target + echo + echo "* Run ${target} on ${arch}/${flavour} ..." + make O=build "${env[@]}" "${target}" + + # Move config for further processing + mv build/.config "${tmp_conf_file}" done -echo "" +echo echo "Running config-check for all configurations ..." -echo "" fail=0 -for flavour in ${FLAVOURS}; do - arch=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\1/') - flavour=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\2/') - conf_file=${arch}-config.flavour.${flavour} - - echo "Running config-check for ${arch}-${flavour}" - python3 ${bindir}/annotations -f ${confdir}/annotations --arch ${arch} --flavour ${flavour} --check ${tmpdir}/${conf_file} || let "fail=$fail+1" +for arch_flavour in ${FLAVOURS} ; do + arch=${arch_flavour%%-*} + flavour=${arch_flavour#*-} + tmp_conf_file=${TMP_DIR}/${arch}-config.flavour.${flavour} + + echo + echo "* Run config-check for ${arch}-${flavour} ..." + python3 debian/scripts/misc/annotations -f "${annotations_file}" \ + --arch "${arch}" --flavour "${flavour}" --check "${tmp_conf_file}" || \ + fail=$((fail + 1)) done rc=0 -if [ "$fail" != 0 ]; then +if [ ${fail} -gt 0 ] ; then rc=1 - echo "" - echo "*** ERROR: $fail config-check failures detected" - echo "" + echo "ERROR: ${fail} config-check failures detected" >&2 fi -rm -rf build - -if [ "$warning_partial" ]; then +if [ ${#warning_partial[@]} -gt 0 ] ; then rc=1 - echo "" - echo "WARNING: configuration operation applied only to a subset of architectures (skipped$warning_partial)" 1>&2 - echo "" + echo "ERROR: Config operation not applied to all architectures (skipped ${warning_partial[*]})" >&2 fi -if [ "$genconfigs" == "1" ]; then +# Recreate the annotations file +if [ "${mode}" = "genconfigs" ] ; then rm -rf CONFIGS - mv ${tmpdir} CONFIGS + mv "${TMP_DIR}" CONFIGS else - # Automatically import configs back into annotations - for flavour in ${FLAVOURS}; do - arch=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\1/') - flavour=$(echo $flavour | sed 's/\([^-]*\)-\(.*\)/\2/') - conf_file=${arch}-config.flavour.${flavour} - - python3 ${bindir}/annotations -f ${confdir}/annotations --arch ${arch} --flavour ${flavour} --import ${tmpdir}/${conf_file} + echo + echo "Importing all configurations ..." + echo + for arch_flavour in ${FLAVOURS} ; do + arch=${arch_flavour%%-*} + flavour=${arch_flavour#*-} + tmp_conf_file=${TMP_DIR}/${arch}-config.flavour.${flavour} + + echo "* Import configs for ${arch}-${flavour} ..." + python3 debian/scripts/misc/annotations -f "${annotations_file}" \ + --arch "${arch}" --flavour "${flavour}" --import "${tmp_conf_file}" done - rm -rf ${tmpdir} fi exit "${rc}"