From 3bd4003e98a20e0aba39a76fa28dba1a69d400a2 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 3 Jul 2019 13:51:53 +0200 Subject: [PATCH] tools: Fix hex parsing in confgen.py Closes https://github.com/espressif/esp-idf/issues/3568 --- tools/kconfig_new/confgen.py | 4 +++- tools/kconfig_new/test/Kconfig | 6 ++++++ tools/kconfig_new/test/testcases_v1.txt | 4 ++-- tools/kconfig_new/test/testcases_v2.txt | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index d4e8752902..0765c9f890 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -475,7 +475,9 @@ def write_json_menus(deprecated_options, config, filename): # should have one condition which is true for min_range, max_range, cond_expr in sym.ranges: if kconfiglib.expr_value(cond_expr): - greatest_range = [int(min_range.str_value), int(max_range.str_value)] + base = 16 if sym.type == kconfiglib.HEX else 10 + greatest_range = [int(min_range.str_value, base), int(max_range.str_value, base)] + break new_json = { "type": kconfiglib.TYPE_TO_STR[sym.type], diff --git a/tools/kconfig_new/test/Kconfig b/tools/kconfig_new/test/Kconfig index 6462fe82de..8529fd5208 100644 --- a/tools/kconfig_new/test/Kconfig +++ b/tools/kconfig_new/test/Kconfig @@ -41,6 +41,12 @@ menu "Test config" range 0 10 default 1 + config TEST_CONDITIONAL_HEX_RANGES + hex "Something with a hex range" + range 0x00 0xaf if TEST_BOOL + range 0x10 0xaf + default 0xa0 + config SUBMENU_TRIGGER bool "I enable/disable some submenu items" default y diff --git a/tools/kconfig_new/test/testcases_v1.txt b/tools/kconfig_new/test/testcases_v1.txt index 4563d49280..0f68536cc0 100644 --- a/tools/kconfig_new/test/testcases_v1.txt +++ b/tools/kconfig_new/test/testcases_v1.txt @@ -1,6 +1,6 @@ * Set TEST_BOOL, showing child items > { "TEST_BOOL" : true } -< { "values" : { "TEST_BOOL" : true, "TEST_CHILD_STR" : "OHAI!", "TEST_CHILD_BOOL" : true }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 100]} } +< { "values" : { "TEST_BOOL" : true, "TEST_CHILD_STR" : "OHAI!", "TEST_CHILD_BOOL" : true }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 100], "TEST_CONDITIONAL_HEX_RANGES": [0, 175]} } * Set TEST_CHILD_STR > { "TEST_CHILD_STR" : "Other value" } @@ -8,7 +8,7 @@ * Clear TEST_BOOL, hiding child items > { "TEST_BOOL" : false } -< { "values" : { "TEST_BOOL" : false, "TEST_CHILD_STR" : null, "TEST_CHILD_BOOL" : null }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 10]} } +< { "values" : { "TEST_BOOL" : false, "TEST_CHILD_STR" : null, "TEST_CHILD_BOOL" : null }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 10], "TEST_CONDITIONAL_HEX_RANGES": [16, 175]} } * Set TEST_CHILD_BOOL, invalid as parent is disabled > { "TEST_CHILD_BOOL" : false } diff --git a/tools/kconfig_new/test/testcases_v2.txt b/tools/kconfig_new/test/testcases_v2.txt index 77d23bf66a..7a735fd1a6 100644 --- a/tools/kconfig_new/test/testcases_v2.txt +++ b/tools/kconfig_new/test/testcases_v2.txt @@ -1,6 +1,6 @@ * Set TEST_BOOL, showing child items > { "TEST_BOOL" : true } -< { "values" : { "TEST_BOOL" : true, "TEST_CHILD_STR" : "OHAI!", "TEST_CHILD_BOOL" : true }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 100]}, "visible": {"TEST_CHILD_BOOL" : true, "TEST_CHILD_STR" : true} } +< { "values" : { "TEST_BOOL" : true, "TEST_CHILD_STR" : "OHAI!", "TEST_CHILD_BOOL" : true }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 100], "TEST_CONDITIONAL_HEX_RANGES": [0, 175]}, "visible": {"TEST_CHILD_BOOL" : true, "TEST_CHILD_STR" : true} } * Set TEST_CHILD_STR > { "TEST_CHILD_STR" : "Other value" } @@ -8,7 +8,7 @@ * Clear TEST_BOOL, hiding child items > { "TEST_BOOL" : false } -< { "values" : { "TEST_BOOL" : false }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 10]}, "visible": { "TEST_CHILD_BOOL" : false, "TEST_CHILD_STR" : false } } +< { "values" : { "TEST_BOOL" : false }, "ranges": {"TEST_CONDITIONAL_RANGES": [0, 10], "TEST_CONDITIONAL_HEX_RANGES": [16, 175]}, "visible": { "TEST_CHILD_BOOL" : false, "TEST_CHILD_STR" : false } } * Set TEST_CHILD_BOOL, invalid as parent is disabled > { "TEST_CHILD_BOOL" : false }