Skip to content

Commit 16ceb81

Browse files
committed
kconfig: Support a list of search paths
Projects such as Zephyr OS have a module system, where Kconfig files can exist in multiple directories that are effectively merged together by the build system. In other words, one project directory can refer to subdir/Kconfig where subdir/ is actually in another project directory. As an example: zephyr/ - main source directory Kconfig - main Kconfig file module/ec - module directory motion/ - motion subsystem Kconfig - Kconfig file for motion subsystem Wtih the above, we might have, in zephyr/Kconfig: source "motion/Kconfig" and it automatically locates the file in the module/ec directory. Add support for this, by allowing a list of search paths to be supplied to Kconfiglib. Signed-off-by: Simon Glass <[email protected]>
1 parent a3c60eb commit 16ceb81

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

tools/kconfig/kconfiglib.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,7 @@ class Kconfig(object):
834834
"n",
835835
"named_choices",
836836
"srctree",
837+
"search_paths",
837838
"syms",
838839
"top_node",
839840
"unique_choices",
@@ -865,7 +866,7 @@ class Kconfig(object):
865866
#
866867

867868
def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
868-
encoding="utf-8", suppress_traceback=False):
869+
encoding="utf-8", suppress_traceback=False, search_paths=None):
869870
"""
870871
Creates a new Kconfig object by parsing Kconfig files.
871872
Note that Kconfig files are not the same as .config files (which store
@@ -942,9 +943,23 @@ def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
942943
943944
Other exceptions besides EnvironmentError and KconfigError are still
944945
propagated when suppress_traceback is True.
946+
947+
search_paths (default: None):
948+
List of paths to search for Kconfig files. This is needed when the
949+
files are split between two project directories, as is done with
950+
Zephyr OS, for example. It allows files in one project to reference
951+
files in another.
952+
953+
This argument affects the operation of commands which include other
954+
Kconfig files, such as `source` and `rsource`.
955+
956+
When not None, it should be a list of paths to directories to search.
957+
Each search path is prepended to the relative filename to assist in
958+
finding the file. The proeect directories should have distinct
959+
filenames and/or subdirectory structures, so avoid ambiguity.
945960
"""
946961
try:
947-
self._init(filename, warn, warn_to_stderr, encoding)
962+
self._init(filename, warn, warn_to_stderr, encoding, search_paths)
948963
except (EnvironmentError, KconfigError) as e:
949964
if suppress_traceback:
950965
cmd = sys.argv[0] # Empty string if missing
@@ -956,7 +971,7 @@ def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
956971
sys.exit(cmd + str(e).strip())
957972
raise
958973

959-
def _init(self, filename, warn, warn_to_stderr, encoding):
974+
def _init(self, filename, warn, warn_to_stderr, encoding, search_paths):
960975
# See __init__()
961976

962977
self._encoding = encoding
@@ -966,6 +981,7 @@ def _init(self, filename, warn, warn_to_stderr, encoding):
966981
# relative to $srctree. relpath() can cause issues for symlinks,
967982
# because it assumes symlink/../foo is the same as foo/.
968983
self._srctree_prefix = realpath(self.srctree) + os.sep
984+
self.search_paths = search_paths
969985

970986
self.warn = warn
971987
self.warn_to_stderr = warn_to_stderr
@@ -2983,6 +2999,9 @@ def _parse_block(self, end_token, parent, prev):
29832999
# Kconfig symbols, which indirectly ensures a consistent
29843000
# ordering in e.g. .config files
29853001
filenames = sorted(iglob(join(self._srctree_prefix, pattern)))
3002+
if self.search_paths:
3003+
for prefix in self.search_paths:
3004+
filenames += sorted(iglob(join(prefix, pattern)))
29863005

29873006
if not filenames and t0 in _OBL_SOURCE_TOKENS:
29883007
raise KconfigError(

0 commit comments

Comments
 (0)