summaryrefslogtreecommitdiff
path: root/examples/eval_expr.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-11-09 11:43:13 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2017-11-09 11:43:13 +0100
commit395c2db0e9761def8eb992e3e8068ba2d3ab179c (patch)
tree7b14ac791dbf9d4b9354f1c6149444e090068309 /examples/eval_expr.py
parent8c978ee0b9c0f7f8406f58d24478a73330512056 (diff)
parent4bffd653148d6fa1c8e626872ae4f445e2b0a24c (diff)
Make Kconfiglib 2 official
Merge in the 'kconfiglib-2-backup' branch.
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)))