From bf9f758691ed5fd6dd2eb6cfcf256272e09f9596 Mon Sep 17 00:00:00 2001 From: Oliver Smith <ollieparanoid@postmarketos.org> Date: Thu, 26 Sep 2024 21:10:46 +0200 Subject: [PATCH] lint: generate options from kconfigcheck.toml (MR 2412) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we have moved the kconfigcheck configuration into pmaports branches via kconfigcheck.toml, it is time to get rid of the hardcoded list of valid "pmb:kconfigcheck-…" options for APKBUILDs. Generate it from the kconfigcheck.toml of the current branch, too. These options are passed from "pmbootstrap lint" to "apkbuild-lint", which we run in pmaports CI. --- pmb/config/__init__.py | 11 +++-------- pmb/helpers/lint.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index bae4fe79b..12c106235 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -283,17 +283,12 @@ apkbuild_attributes = { } # Reference: https://postmarketos.org/apkbuild-options +# In addition to these, pmbootstrap adds "pmb:kconfigcheck-community" etc. +# dynamically based on kconfigcheck.toml in the currently checked out pmaports +# branch apkbuild_custom_valid_options = [ "!pmb:crossdirect", "!pmb:kconfigcheck", - "pmb:kconfigcheck-community", - "pmb:kconfigcheck-containers", - "pmb:kconfigcheck-iwd", - "pmb:kconfigcheck-netboot", - "pmb:kconfigcheck-nftables", - "pmb:kconfigcheck-uefi", - "pmb:kconfigcheck-waydroid", - "pmb:kconfigcheck-zram", "pmb:cross-native", "pmb:gpu-accel", "pmb:strict", diff --git a/pmb/helpers/lint.py b/pmb/helpers/lint.py index 7b226569b..4da48bc61 100644 --- a/pmb/helpers/lint.py +++ b/pmb/helpers/lint.py @@ -5,6 +5,7 @@ from pmb.core.chroot import Chroot from pmb.core.pkgrepo import pkgrepo_iter_package_dirs, pkgrepo_names, pkgrepo_relative_path from pmb.helpers import logging from pmb.helpers.exceptions import NonBugError +from pmb.helpers.toml import load_toml_file import os import pmb.chroot @@ -14,6 +15,33 @@ import pmb.helpers.run import pmb.helpers.pmaports +def get_custom_valid_options() -> list[str]: + """Build a list of custom valid APKBUILD options that apkbuild-lint should + not complain about. The list consists of hardcoded options from + pmb.config.apkbuild_custom_valid_options like pmb:gpu-accel, as well as + dynamically generated options from kconfigcheck.toml + (pmb:kconfigcheck-libcamera etc.).""" + ret = list(pmb.config.apkbuild_custom_valid_options) + + # Load kconfigcheck.toml from current branch + kconfigcheck_toml = load_toml_file(pmb.parse.kconfigcheck.get_path()) + pmb.parse.kconfigcheck.sanity_check(kconfigcheck_toml) + + # Add options like "pmb:kconfigcheck-libcamera" + for section in kconfigcheck_toml.keys(): + if not section.startswith("category:"): + continue + # section looks like: "category:input.>=0.0.0.all" + category = section.split(".")[0].replace("category:", "", 1) + ret += [f"pmb:kconfigcheck-{category}"] + + # Add aliases like "pmb:kconfigcheck-community" + for alias in kconfigcheck_toml["aliases"].keys(): + ret += [f"pmb:kconfigcheck-{alias}"] + + return ret + + # FIXME: dest_paths[repo], repo expected to be a Literal. # We should really make Config.mirrors not a TypedDict. # mypy: disable-error-code="index" @@ -55,7 +83,6 @@ def check(pkgnames: Sequence[str]): # each violation. pkgstr = ", ".join(pkgnames) logging.info(f"(native) linting {pkgstr} with apkbuild-lint") - options = pmb.config.apkbuild_custom_valid_options # apkbuild-lint output is not colorized, make it easier to spot logging.info("*** apkbuild-lint output ***") @@ -68,7 +95,7 @@ def check(pkgnames: Sequence[str]): check=False, output="stdout", working_dir=dest_paths[repo.name], - env={"CUSTOM_VALID_OPTIONS": " ".join(options)}, + env={"CUSTOM_VALID_OPTIONS": " ".join(get_custom_valid_options())}, ): has_failed = True -- GitLab