summaryrefslogtreecommitdiff
path: root/examples/eval_expr.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/eval_expr.py')
-rw-r--r--examples/eval_expr.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/examples/eval_expr.py b/examples/eval_expr.py
index edb33e6..36a7e6a 100644
--- a/examples/eval_expr.py
+++ b/examples/eval_expr.py
@@ -1,8 +1,24 @@
-# Evaluates an expression in the context of a configuration. (Here we could
-# load a .config as well.)
+# Evaluates an expression (e.g. "X86_64 || (X86_32 && X86_LOCAL_APIC)") in the
+# context of a configuration. Note that this always yields a tristate value (n,
+# m, or y).
+#
+# Usage:
+#
+# $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/eval_expr.py SCRIPT_ARG=<expr>
import kconfiglib
import sys
-conf = kconfiglib.Config(sys.argv[1])
-print(conf.eval("(TRACE_IRQFLAGS_SUPPORT || PPC32) && STACKTRACE_SUPPORT"))
+if len(sys.argv) < 3:
+ print('Pass symbol name (without "CONFIG_" prefix) with SCRIPT_ARG=NAME')
+ sys.exit(1)
+
+expr = sys.argv[2]
+
+kconf = kconfiglib.Kconfig(sys.argv[1])
+
+# Enable modules so that m doesn't get demoted to n
+kconf.syms["MODULES"].set_value(2)
+
+print("the expression '{}' evaluates to {}"
+ .format(expr, kconf.eval_string(expr)))