summaryrefslogtreecommitdiff
path: root/zephyr/zmake
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-06-08 23:47:15 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-09 17:55:12 +0000
commit629f84562924610a6fc4dd726b1054fe3ecd6d79 (patch)
tree01b282d3eebdd33bbe32cd82f7ce5d2c9764615d /zephyr/zmake
parentae1b0032c195c28e0f8132f4133ed361f6a2ff90 (diff)
downloadchrome-ec-629f84562924610a6fc4dd726b1054fe3ecd6d79.tar.gz
zmake: Add utility for getting value from autoconf.h
Kconfig generates an autoconf.h header from the various Kconfig files. These values (such as CONFIG_FLASH_SIZE) may not be obvious to find. This is especially true since some Kconfig values are passed in from zmake while others reside in Kconfig files. Add a utility to get the #define value from the autoconf.h that's generated during the build. BRANCH=none BUG=b:190435084 TEST=Added unit tests Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: Id2c1f05a809e17f67a435209e35606ffd7245174 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2948168 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'zephyr/zmake')
-rw-r--r--zephyr/zmake/tests/test_util.py10
-rw-r--r--zephyr/zmake/zmake/util.py17
2 files changed, 27 insertions, 0 deletions
diff --git a/zephyr/zmake/tests/test_util.py b/zephyr/zmake/tests/test_util.py
index 823b198e91..b656b1318f 100644
--- a/zephyr/zmake/tests/test_util.py
+++ b/zephyr/zmake/tests/test_util.py
@@ -73,3 +73,13 @@ def test_read_zephyr_version(version_tuple):
f.write('{} = {}\n'.format(name, value))
assert util.read_zephyr_version(zephyr_base) == version_tuple
+
+@hypothesis.given(st.integers())
+@hypothesis.settings(deadline=60000)
+def test_read_kconfig_autoconf_value(value):
+ with tempfile.TemporaryDirectory() as dir:
+ path = pathlib.Path(dir)
+ with open(path / 'autoconf.h', 'w') as f:
+ f.write('#define TEST {}'.format(value))
+ read_value = util.read_kconfig_autoconf_value(path, 'TEST')
+ assert int(read_value) == value
diff --git a/zephyr/zmake/zmake/util.py b/zephyr/zmake/zmake/util.py
index 1f052a3688..ca38831ef6 100644
--- a/zephyr/zmake/zmake/util.py
+++ b/zephyr/zmake/zmake/util.py
@@ -73,6 +73,23 @@ def read_kconfig_file(path):
result[name.strip()] = value.strip()
return result
+def read_kconfig_autoconf_value(path, key):
+ """Parse an autoconf.h file for a resolved kconfig value
+
+ Args:
+ path: The path to the autoconf.h file.
+ key: The define key to lookup.
+
+ Returns:
+ The value associated with the key or nothing if the key wasn't found.
+ """
+ prog = re.compile(r'^#define\s{}\s(\S+)$'.format(key))
+ with open(path / 'autoconf.h') as f:
+ for line in f:
+ m = prog.match(line)
+ if m:
+ return m.group(1)
+
def write_kconfig_file(path, config, only_if_changed=True):
"""Write out a dictionary to Kconfig format.