From e08b6957ca935fc97eddd1afda933715016b9b11 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 18 Jul 2018 03:05:37 +0200 Subject: Add def_int, def_hex, and def_string keywords Analogous to def_bool and def_tristate, setting the type and adding a default at the same time. This is a Kconfiglib extension. These keywords can be useful in projects that make use of symbols defined in multiple locations, and remove some Kconfig inconsistency. --- README.rst | 7 +++++++ kconfiglib.py | 14 ++++++++++++-- tests/Kstr | 11 ++++++++--- testsuite.py | 12 +++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index fe62da8..93d1367 100644 --- a/README.rst +++ b/README.rst @@ -205,6 +205,13 @@ The following Kconfig extensions are available: - A relative ``source`` statement (``rsource``) is available, where file paths are specified relative to the directory of the current Kconfig file. An ``orsource`` statement is available as well, analogous to ``osource``. + +- ``def_int``, ``def_hex``, and ``def_string`` are available in addition to + ``def_bool`` and ``def_tristate``, allowing ``int``, ``hex``, and ``string`` + symbols to be given a type and a default at the same time. + + These can be useful in projects that make use of symbols defined in multiple + locations, and remove some Kconfig inconsistency. - Environment variables are expanded directly in e.g. ``source`` and ``mainmenu`` statements, meaning ``option env`` symbols are redundant. diff --git a/kconfiglib.py b/kconfiglib.py index 2306d46..ee3bb7a 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2394,7 +2394,8 @@ class Kconfig(object): node.defaults.append((self._parse_expr(False), self._parse_cond())) - elif t0 in (_T_DEF_BOOL, _T_DEF_TRISTATE): + elif t0 in (_T_DEF_BOOL, _T_DEF_TRISTATE, _T_DEF_INT, _T_DEF_HEX, + _T_DEF_STRING): self._set_type(node, _TOKEN_TO_TYPE[t0]) node.defaults.append((self._parse_expr(False), self._parse_cond())) @@ -5607,6 +5608,9 @@ _IS_PY2 = sys.version_info[0] < 3 _T_DEFAULT, _T_DEFCONFIG_LIST, _T_DEF_BOOL, + _T_DEF_HEX, + _T_DEF_INT, + _T_DEF_STRING, _T_DEF_TRISTATE, _T_DEPENDS, _T_ENDCHOICE, @@ -5644,7 +5648,7 @@ _IS_PY2 = sys.version_info[0] < 3 _T_TRISTATE, _T_UNEQUAL, _T_VISIBLE, -) = range(1, 48) +) = range(1, 51) # Public integers representing expression types # @@ -5671,6 +5675,9 @@ _get_keyword = { "comment": _T_COMMENT, "config": _T_CONFIG, "def_bool": _T_DEF_BOOL, + "def_hex": _T_DEF_HEX, + "def_int": _T_DEF_INT, + "def_string": _T_DEF_STRING, "def_tristate": _T_DEF_TRISTATE, "default": _T_DEFAULT, "defconfig_list": _T_DEFCONFIG_LIST, @@ -5791,6 +5798,9 @@ _conf_string_match = _re_match(r'"((?:[^\\"]|\\.)*)"') _TOKEN_TO_TYPE = { _T_BOOL: BOOL, _T_DEF_BOOL: BOOL, + _T_DEF_HEX: HEX, + _T_DEF_INT: INT, + _T_DEF_STRING: STRING, _T_DEF_TRISTATE: TRISTATE, _T_HEX: HEX, _T_INT: INT, diff --git a/tests/Kstr b/tests/Kstr index e3f4746..25c14db 100644 --- a/tests/Kstr +++ b/tests/Kstr @@ -53,18 +53,23 @@ config ONLY_DIRECT_DEPS depends on DEP2 config STRING - string - default "foo" + def_string "foo" default "bar" if DEP default STRING2 default STRING3 if DEP config INT - int + def_int 7 if DEP range 1 2 range FOO BAR range BAZ QAZ if DEP +config HEX + def_hex 0x123 + range 0x100 0x200 + range FOO BAR + range BAZ QAZ if DEP + config MODULES bool "MODULES" option modules diff --git a/testsuite.py b/testsuite.py index 0f42d69..f70c7e9 100644 --- a/testsuite.py +++ b/testsuite.py @@ -467,7 +467,7 @@ def run_selftests(): verify_eval_bad("|| X") - print("Testing Symbol.__str__()") + print("Testing Symbol.__str__() and def_{int,hex,string}") def verify_str(item, s): verify_equal(str(item), s[1:]) @@ -545,6 +545,16 @@ config INT range 1 2 range FOO BAR range BAZ QAZ if DEP + default 7 if DEP +""") + + verify_str(c.syms["HEX"], """ +config HEX + hex + range 0x100 0x200 + range FOO BAR + range BAZ QAZ if DEP + default 0x123 """) verify_str(c.modules, """ -- cgit v1.2.3