From 9f665a92b8563f172a803a0fb6995cf1f35cb925 Mon Sep 17 00:00:00 2001 From: Graham Roff Date: Wed, 8 Oct 2025 08:32:34 -0700 Subject: [PATCH] Support conditional deps using "depends on A if B" Extend the "depends on" syntax to support conditional dependencies using "depends on A if B". While functionally equivalent to "depends on !B || A", "depends on A if B" is much more readable. This change is implemented by converting the "A if B" syntax into the "!B || A" syntax during "depends on" token processing. Signed-off-by: Graham Roff --- kconfiglib.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/kconfiglib.py b/kconfiglib.py index a50312e..b7c137f 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -3117,6 +3117,36 @@ def _parse_cond(self): return expr + def _parse_depends(self): + # Parses conditional dependencies with syntax "depends on if " + # Returns the appropriate expression that represents the conditional dependency + + # Parse the main dependency expression + main_expr = self._parse_expr(True) + + # Check if there's an optional "if " clause + if self._check_token(_T_IF): + # Parse the condition expression + condition = self._parse_expr(True) + + # Check for end of line + if self._tokens[self._tokens_i] is not None: + self._trailing_tokens_error() + + # Create conditional dependency: "depends on A if B" becomes "!B || A" + # This means: if B is false, the dependency is satisfied (y) + # if B is true, the dependency becomes A + return self._make_or( + (NOT, condition), + main_expr + ) + else: + # No conditional clause, just return the main expression + if self._tokens[self._tokens_i] is not None: + self._trailing_tokens_error() + + return main_expr + def _parse_props(self, node): # Parses and adds properties to the MenuNode 'node' (type, 'prompt', # 'default's, etc.) Properties are later copied up to symbols and @@ -3152,7 +3182,7 @@ def _parse_props(self, node): self._parse_error("expected 'on' after 'depends'") node.dep = self._make_and(node.dep, - self._expect_expr_and_eol()) + self._parse_depends()) elif t0 is _T_HELP: self._parse_help(node)