summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-09-20 13:33:59 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-09-23 17:31:20 +0200
commit6156041560c75831e003202b790ab3f435bbb388 (patch)
tree8bb3de3561d87e4faeb73dfef098d8e3726db363 /tests
parent3df532b8d4cdf6915eaf079ee8082f792ab9b0cb (diff)
Add support for user-defined Python preprocessor functions
Allow preprocessor functions to be defined in Python by putting a module called 'kconfigfunctions' into sys.path. Internally, this simply adds the functions to the predefined functions in Kconfig._functions. User-defined Python functions make it simple to integrate information from existing Python tools into Kconfig, e.g. to have Kconfig symbols depend on hardware information stored in some other format. This might be used to get device tree information into Kconfig in Zephyr. Piggyback module docstring documentation for some extensions that were previously only mentioned in the README.
Diffstat (limited to 'tests')
-rw-r--r--tests/Kuserfunctions11
-rw-r--r--tests/kconfigfunctions.py14
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/Kuserfunctions b/tests/Kuserfunctions
new file mode 100644
index 0000000..99ef23a
--- /dev/null
+++ b/tests/Kuserfunctions
@@ -0,0 +1,11 @@
+add-zero = $(add)
+add-one = $(add,1)
+add-three = $(add,1,-1,2,1)
+
+one-zero = $(one)
+one-one = $(one,foo bar)
+one-two = $(one,foo bar,baz)
+
+one-or-more-zero = $(one-or-more)
+one-or-more-one = $(one-or-more,foo)
+one-or-more-three = $(one-or-more,foo,bar,baz)
diff --git a/tests/kconfigfunctions.py b/tests/kconfigfunctions.py
new file mode 100644
index 0000000..e760468
--- /dev/null
+++ b/tests/kconfigfunctions.py
@@ -0,0 +1,14 @@
+def add(kconf, name, *args):
+ return str(sum(map(int, args)))
+
+def one(kconf, name, s):
+ return name + 2*s
+
+def one_or_more(kconf, name, arg, *args):
+ return arg + " + " + ",".join(args)
+
+functions = {
+ "add": (add, 0, None),
+ "one": (one, 1, 1),
+ "one-or-more": (one_or_more, 1, None),
+}