@@ -834,6 +834,7 @@ class Kconfig(object):
834
834
"n" ,
835
835
"named_choices" ,
836
836
"srctree" ,
837
+ "search_paths" ,
837
838
"syms" ,
838
839
"top_node" ,
839
840
"unique_choices" ,
@@ -865,7 +866,7 @@ class Kconfig(object):
865
866
#
866
867
867
868
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 ):
869
870
"""
870
871
Creates a new Kconfig object by parsing Kconfig files.
871
872
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,
942
943
943
944
Other exceptions besides EnvironmentError and KconfigError are still
944
945
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.
945
960
"""
946
961
try :
947
- self ._init (filename , warn , warn_to_stderr , encoding )
962
+ self ._init (filename , warn , warn_to_stderr , encoding , search_paths )
948
963
except (EnvironmentError , KconfigError ) as e :
949
964
if suppress_traceback :
950
965
cmd = sys .argv [0 ] # Empty string if missing
@@ -956,7 +971,7 @@ def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
956
971
sys .exit (cmd + str (e ).strip ())
957
972
raise
958
973
959
- def _init (self , filename , warn , warn_to_stderr , encoding ):
974
+ def _init (self , filename , warn , warn_to_stderr , encoding , search_paths ):
960
975
# See __init__()
961
976
962
977
self ._encoding = encoding
@@ -966,6 +981,7 @@ def _init(self, filename, warn, warn_to_stderr, encoding):
966
981
# relative to $srctree. relpath() can cause issues for symlinks,
967
982
# because it assumes symlink/../foo is the same as foo/.
968
983
self ._srctree_prefix = realpath (self .srctree ) + os .sep
984
+ self .search_paths = search_paths
969
985
970
986
self .warn = warn
971
987
self .warn_to_stderr = warn_to_stderr
@@ -2972,6 +2988,9 @@ def _parse_block(self, end_token, parent, prev):
2972
2988
# Kconfig symbols, which indirectly ensures a consistent
2973
2989
# ordering in e.g. .config files
2974
2990
filenames = sorted (iglob (join (self ._srctree_prefix , pattern )))
2991
+ if self .search_paths :
2992
+ for prefix in self .search_paths :
2993
+ filenames += sorted (iglob (join (prefix , pattern )))
2975
2994
2976
2995
if not filenames and t0 in _OBL_SOURCE_TOKENS :
2977
2996
raise KconfigError (
0 commit comments