@@ -817,6 +817,7 @@ class Kconfig(object):
817
817
"_srctree_prefix" ,
818
818
"_unset_match" ,
819
819
"_warn_assign_no_prompt" ,
820
+ "allow_empty_macros" ,
820
821
"choices" ,
821
822
"comments" ,
822
823
"config_header" ,
@@ -866,7 +867,8 @@ class Kconfig(object):
866
867
#
867
868
868
869
def __init__ (self , filename = "Kconfig" , warn = True , warn_to_stderr = True ,
869
- encoding = "utf-8" , suppress_traceback = False , search_paths = None ):
870
+ encoding = "utf-8" , suppress_traceback = False , search_paths = None ,
871
+ allow_empty_macros = False ):
870
872
"""
871
873
Creates a new Kconfig object by parsing Kconfig files.
872
874
Note that Kconfig files are not the same as .config files (which store
@@ -957,9 +959,21 @@ def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
957
959
Each search path is prepended to the relative filename to assist in
958
960
finding the file. The proeect directories should have distinct
959
961
filenames and/or subdirectory structures, so avoid ambiguity.
962
+
963
+ allow_empty_macros (default: False):
964
+ Normally when macros expand to empty it means that the macro is not
965
+ defined. This is considered an error and parsing of the Kconfig files
966
+ aborts with an exception. In some cases it is useful to continue
967
+ parsing, to obtain what information is available.
968
+
969
+ An example is where the value of various macros is not known but the
970
+ caller simply wants to get a list of the available Kconfig options.
971
+
972
+ Pass True here to allow empty / undefined macros.
960
973
"""
961
974
try :
962
- self ._init (filename , warn , warn_to_stderr , encoding , search_paths )
975
+ self ._init (filename , warn , warn_to_stderr , encoding , search_paths ,
976
+ allow_empty_macros )
963
977
except (EnvironmentError , KconfigError ) as e :
964
978
if suppress_traceback :
965
979
cmd = sys .argv [0 ] # Empty string if missing
@@ -971,7 +985,8 @@ def __init__(self, filename="Kconfig", warn=True, warn_to_stderr=True,
971
985
sys .exit (cmd + str (e ).strip ())
972
986
raise
973
987
974
- def _init (self , filename , warn , warn_to_stderr , encoding , search_paths ):
988
+ def _init (self , filename , warn , warn_to_stderr , encoding , search_paths ,
989
+ allow_empty_macros ):
975
990
# See __init__()
976
991
977
992
self ._encoding = encoding
@@ -982,6 +997,7 @@ def _init(self, filename, warn, warn_to_stderr, encoding, search_paths):
982
997
# because it assumes symlink/../foo is the same as foo/.
983
998
self ._srctree_prefix = realpath (self .srctree ) + os .sep
984
999
self .search_paths = search_paths
1000
+ self .allow_empty_macros = allow_empty_macros
985
1001
986
1002
self .warn = warn
987
1003
self .warn_to_stderr = warn_to_stderr
@@ -2712,7 +2728,8 @@ def _expand_name(self, s, i):
2712
2728
if not name .strip ():
2713
2729
# Avoid creating a Kconfig symbol with a blank name. It's almost
2714
2730
# guaranteed to be an error.
2715
- self ._parse_error ("macro expanded to blank string" )
2731
+ if not self .allow_empty_macros :
2732
+ self ._parse_error ("macro expanded to blank string" )
2716
2733
2717
2734
# Skip trailing whitespace
2718
2735
while end_i < len (s ) and s [end_i ].isspace ():
0 commit comments