From cfb582cba05b089e72eb2456e64a9885dae8ff58 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 16 Mar 2023 21:49:12 +0100 Subject: [PATCH] CI: kconfig: don't print unrelated warnings (MR 3961) Run the "pmbootstrap kconfig check" only on the kernels that have been modified. [ci:skip-build] already built successfully in CI --- .ci/kconfig.sh | 12 ++--- .ci/lib/check_changed_kernels.py | 83 ++++++++++++++++++++++++++++++++ .ci/lib/common.py | 8 +++ 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100755 .ci/lib/check_changed_kernels.py diff --git a/.ci/kconfig.sh b/.ci/kconfig.sh index f51ff6c60..4a8e03133 100755 --- a/.ci/kconfig.sh +++ b/.ci/kconfig.sh @@ -1,5 +1,5 @@ #!/bin/sh -e -# Description: check all kernel configs with 'pmbootstrap kconfig check' +# Description: check modified kernel configs # Options: native # Use 'native' because it requires running pmbootstrap. # https://postmarketos.org/pmb-ci @@ -11,12 +11,6 @@ if [ "$(id -u)" = 0 ]; then exec su "${TESTUSER:-pmos}" -c "sh -e $0" fi -# Wrap pmbootstrap to use this repository for --aports -pmaports="$(cd "$(dirname "$0")"/..; pwd -P)" -_pmbootstrap="$(command -v pmbootstrap)" -pmbootstrap() { - "$_pmbootstrap" --aports="$pmaports" "$@" -} +export PYTHONUNBUFFERED=1 -set -x -pmbootstrap kconfig check +.ci/lib/check_changed_kernels.py diff --git a/.ci/lib/check_changed_kernels.py b/.ci/lib/check_changed_kernels.py new file mode 100755 index 000000000..3bcce8266 --- /dev/null +++ b/.ci/lib/check_changed_kernels.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# Copyright 2023 Oliver Smith +# SPDX-License-Identifier: GPL-3.0-or-later + +import glob +import tempfile +import sys +import subprocess + +# Same dir +import common + +# pmbootstrap +import add_pmbootstrap_to_import_path # noqa +import pmb.parse +import pmb.helpers.logging + + +def check_kconfig(args, pkgnames): + last_failed = None + for i in range(len(pkgnames)): + pkgname = pkgnames[i] + print(f" ({i+1}/{len(pkgnames)}) {pkgname}") + + apkbuild_path = pmb.helpers.pmaports.find(args, pkgname) + apkbuild = pmb.parse._apkbuild.apkbuild(f"{apkbuild_path}/APKBUILD") + + options = [] + + for opt in apkbuild["options"]: + if "pmb:kconfigcheck" in opt: + options += [opt] + + if len(options): + options.sort() + print(f'options="{" ".join(options)}"') + + if "!pmb:kconfigcheck" in apkbuild["options"]: + print("skipped (!pmb:kconfigcheck)") + continue + + if not pmb.parse.kconfig.check(args, pkgname, details=True): + last_failed = pkgname + + return last_failed + + +def show_error(last_failed): + print("") + print("Please adjust your kernel config. This is required for getting your" + " patch merged.") + print("") + print("Edit your kernel config:") + print(f" pmbootstrap kconfig edit {last_failed}") + print("") + print("Test this kernel config again:") + print(f" pmbootstrap kconfig check {last_failed}") + print("") + print("Run this check again (on all kernels you modified):") + print(" pmbootstrap ci kconfig") + print("") + + +if __name__ == "__main__": + common.add_upstream_git_remote() + pkgnames = common.get_changed_kernels() + print(f"Changed kernels: {pkgnames}") + + if len(pkgnames) == 0: + print("No kernels changed in this branch") + exit(0) + + # Initialize args (so we can use pmbootstrap's kconfig parsing) + sys.argv = ["pmbootstrap", "kconfig", "check"] + args = pmb.parse.arguments() + pmb.helpers.logging.init(args) + + print("Running kconfig check on changed kernels...") + last_failed = check_kconfig(args, pkgnames) + + if last_failed: + show_error(last_failed) + exit(1) diff --git a/.ci/lib/common.py b/.ci/lib/common.py index aae9e679b..51d91003e 100755 --- a/.ci/lib/common.py +++ b/.ci/lib/common.py @@ -190,3 +190,11 @@ def get_changed_packages(): ret.add(os.path.basename(dirname)) return ret + + +def get_changed_kernels(): + ret = [] + for pkgname in get_changed_packages(): + if pkgname.startswith("linux-"): + ret += [pkgname] + return ret