From: "Ahmed S. Darwish" <darwi@linutronix.de>
To: Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>
Cc: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"John Ogness" <john.ogness@linutronix.de>,
"Derek Barbosa" <debarbos@redhat.com>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@amutable.com>,
"Daan De Meyer" <daan.j.demeyer@gmail.com>,
"Luca Boccassi" <luca.boccassi@gmail.com>,
linux-rt-devel@lists.linux.dev, debian-kernel@lists.debian.org,
linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Ahmed S. Darwish" <darwi@linutronix.de>
Subject: [PATCH v1 06/10] kconfig-checker: Split schema to support component reuse
Date: Fri, 6 Nov 2026 10:19:18 +0100 [thread overview]
Message-ID: <20261106091922.7560-7-darwi@linutronix.de> (raw)
In-Reply-To: <20261106091922.7560-1-darwi@linutronix.de>
Normal rule files require every rule to define both 'expected' and
'severity'. Overlay files are different: an overlay may update only
selected fields of an existing rule, so a future overlay schema will permit
these fields to be omitted.
Move the common rule definitions into schemas/base.yml and add a strict
schemas/rules.yml wrapper for complete rule files.
Teach the checker to build a Draft7Validator with local file:// URIs so
that rules.yml can resolve base.yml.
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
---
tools/kconfig-checker/check.py | 52 ++++++++++++++++---
.../{schema.yml => schemas/base.yml} | 3 +-
tools/kconfig-checker/schemas/rules.yml | 20 +++++++
3 files changed, 65 insertions(+), 10 deletions(-)
rename tools/kconfig-checker/{schema.yml => schemas/base.yml} (97%)
create mode 100644 tools/kconfig-checker/schemas/rules.yml
diff --git a/tools/kconfig-checker/check.py b/tools/kconfig-checker/check.py
index ef49c28b9dab..4f79ec487da7 100755
--- a/tools/kconfig-checker/check.py
+++ b/tools/kconfig-checker/check.py
@@ -80,6 +80,8 @@ except ModuleNotFoundError as e:
# Actual script:
#
+from jsonschema import Draft7Validator
+
class KernelConfig:
""".config file parser"""
@@ -133,9 +135,9 @@ class Helpers:
error(f'Invalid YAML syntax at {yaml_f}:\n {e}', os.EX_DATAERR)
@staticmethod
- def validate_yaml(yaml: YamlDict, schema: YamlDict, f_name: str) -> None:
+ def validate_yaml(yaml: YamlDict, validator: Draft7Validator, f_name: str) -> None:
try:
- jsonschema.validate(yaml, schema)
+ validator.validate(yaml)
except jsonschema.exceptions.ValidationError as e:
error(
f'{f_name} does not match its schema\n'
@@ -144,12 +146,45 @@ class Helpers:
)
class Schema:
- """Rules file schema, in json-schema.org format"""
+ """Rules file schema, in json-schema.org draft-07 format"""
+
+ # Rules schema refer to definitions from this base schema
+ BASE_SCHEMA = 'base.yml'
def __init__(self, schema_f: Path):
- self.schema = Helpers.load_yaml(schema_f)
- # Validate the schema itself against draft-07 metaschema
- jsonschema.Draft7Validator.check_schema(self.schema)
+ base_schema_f = schema_f.parent / self.BASE_SCHEMA
+
+ # Use file:// URIs so jsonschema can resolve local '$ref' entries
+ base_schema_uri = base_schema_f.resolve().as_uri()
+ schema_uri = schema_f.resolve().as_uri()
+
+ base_schema = self._load(base_schema_f)
+ self.schema = self._load(schema_f)
+
+ self.validator = self._create_validator(
+ base_schema_uri, base_schema,
+ schema_uri, self.schema,
+ )
+
+ @staticmethod
+ def _create_validator(base_schema_uri: str, base_schema: YamlDict,
+ schema_uri: str, schema: YamlDict) -> Draft7Validator:
+ """Create a schema validator which can resolve local '$ref' URIs"""
+ resolver = jsonschema.RefResolver(
+ base_uri=schema_uri,
+ referrer=schema,
+ store={ base_schema_uri: base_schema },
+ )
+
+ return Draft7Validator(schema, resolver=resolver)
+
+ @staticmethod
+ def _load(path: Path) -> YamlDict:
+ """Load and validate the schema itself against its metaschema"""
+ schema = Helpers.load_yaml(path)
+
+ Draft7Validator.check_schema(schema)
+ return schema
def as_dict(self) -> YamlDict:
return self.schema
@@ -273,7 +308,7 @@ class RulesFile:
def __init__(self, yaml_f: Path, schema: Schema):
self.yaml = Helpers.load_yaml(yaml_f)
- Helpers.validate_yaml(self.yaml, schema.as_dict(), yaml_f.name)
+ Helpers.validate_yaml(self.yaml, schema.validator, yaml_f.name)
def parse(self) -> Rules:
"""Parse the YAML rules into a python Rules object"""
@@ -533,6 +568,7 @@ def parse_args(rules: list[str]) -> argparse.Namespace:
def main() -> None:
base_dir = Path(__file__).resolve().parent
rules_dir = base_dir / 'rules'
+ schema_dir = base_dir / 'schemas'
rules_l = sorted(path.stem for path in rules_dir.glob('*.yml'))
args = parse_args(rules_l)
@@ -544,7 +580,7 @@ def main() -> None:
kconfig_f = args.config.resolve()
kconfig = KernelConfig(kconfig_f)
- schema_f = base_dir / 'schema.yml'
+ schema_f = schema_dir / 'rules.yml'
schema = Schema(schema_f)
rules_f = rules_dir / f'{args.rules}.yml'
diff --git a/tools/kconfig-checker/schema.yml b/tools/kconfig-checker/schemas/base.yml
similarity index 97%
rename from tools/kconfig-checker/schema.yml
rename to tools/kconfig-checker/schemas/base.yml
index a7f1b0a78cc7..1cc19752ebd6 100644
--- a/tools/kconfig-checker/schema.yml
+++ b/tools/kconfig-checker/schemas/base.yml
@@ -2,7 +2,7 @@
"$schema": "https://json-schema.org/draft-07/schema"
-title: Schema for kconfig-checker rule files
+title: Base schema for kconfig-checker rule files
type: object
required: [rules]
additionalProperties: false
@@ -24,7 +24,6 @@ properties:
oneOf:
- required: [name]
- required: [name_pattern]
- required: [expected, severity]
additionalProperties: false
properties:
diff --git a/tools/kconfig-checker/schemas/rules.yml b/tools/kconfig-checker/schemas/rules.yml
new file mode 100644
index 000000000000..90f0eeef497f
--- /dev/null
+++ b/tools/kconfig-checker/schemas/rules.yml
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+"$schema": "https://json-schema.org/draft-07/schema#"
+
+title: Schema for kconfig-checker rule files
+
+allOf:
+ - $ref: "base.yml"
+
+ #
+ # The base schema leaves 'expected' and 'severity' optional so that
+ # overlay files can override only selected fields. In a full rules
+ # file though, these fields are mandatory for each rule.
+ #
+ - type: object
+ properties:
+ rules:
+ type: array
+ items:
+ required: [expected, severity]
--
2.56.0
next prev parent reply other threads:[~2026-11-06 9:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 9:19 [PATCH v1 00/10] tools: Introduce a kernel configuration checker Ahmed S. Darwish
2026-11-06 9:19 ` [PATCH v1 01/10] kconfig-checker: Add schema for rule files Ahmed S. Darwish
2026-11-06 9:19 ` [PATCH v1 02/10] kconfig-checker: Introduce PREEMPT_RT configuration rules Ahmed S. Darwish
2026-11-07 9:20 ` sashiko-bot
2026-11-06 9:19 ` [PATCH v1 03/10] kconfig-checker: Add the configuration checker code Ahmed S. Darwish
2026-11-07 9:20 ` sashiko-bot
2026-11-06 9:19 ` [PATCH v1 04/10] kconfig: Introduce checkconfig target Ahmed S. Darwish
2026-11-07 9:20 ` sashiko-bot
2026-11-06 9:19 ` [PATCH v1 05/10] Documentation: Describe kconfig-checker usage and design Ahmed S. Darwish
2026-11-06 9:19 ` Ahmed S. Darwish [this message]
2026-11-07 9:20 ` [PATCH v1 06/10] kconfig-checker: Split schema to support component reuse sashiko-bot
2026-11-06 9:19 ` [PATCH v1 07/10] kconfig-checker: Introduce overlays schema Ahmed S. Darwish
2026-11-07 9:20 ` sashiko-bot
2026-11-06 9:19 ` [PATCH v1 08/10] kconfig-checker: Add support for rule overlays Ahmed S. Darwish
2026-11-06 9:19 ` [PATCH v1 09/10] Documentation: Describe kconfig-checker overlays Ahmed S. Darwish
2026-11-07 9:20 ` sashiko-bot
2026-11-06 9:19 ` [PATCH v1 10/10] kconfig: Introduce OVERLAY= for make checkconfig Ahmed S. Darwish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106091922.7560-7-darwi@linutronix.de \
--to=darwi@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=corbet@lwn.net \
--cc=daan.j.demeyer@gmail.com \
--cc=debarbos@redhat.com \
--cc=debian-kernel@lists.debian.org \
--cc=frederic@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=luca.boccassi@gmail.com \
--cc=mingo@redhat.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=rostedt@goodmis.org \
--cc=zbyszek@amutable.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®