@@ -1060,19 +1060,30 @@ def replace(v: str) -> str:
10601060
10611061 return changed
10621062
1063- def set_option_maybe_root (self , o : OptionKey , new_value : str ) -> bool :
1063+ def set_option_maybe_root (self , o : OptionKey , new_value : ElementaryOptionValues , first_invocation : bool = False ) -> bool :
10641064 if not self .is_cross and o .is_for_build ():
10651065 return False
10661066
1067+ # This is complicated by the fact that a string can have two meanings:
1068+ #
1069+ # default_options: 'foo=bar'
1070+ #
1071+ # can be either
1072+ #
1073+ # A) a system option in which case the subproject is None
1074+ # B) a project option, in which case the subproject is '' (this method is only called from top level)
1075+ #
1076+ # The key parsing function can not handle the difference between the two
1077+ # and defaults to A.
10671078 if o in self .options :
1068- return self .set_option (o , new_value )
1069- if self .accept_as_pending_option (o ):
1079+ return self .set_option (o , new_value , first_invocation )
1080+ if self .accept_as_pending_option (o , first_invocation = first_invocation ):
10701081 old_value = self .pending_options .get (o , None )
10711082 self .pending_options [o ] = new_value
10721083 return old_value is None or str (old_value ) == new_value
10731084 else :
10741085 o = o .as_root ()
1075- return self .set_option (o , new_value )
1086+ return self .set_option (o , new_value , first_invocation )
10761087
10771088 def set_from_configure_command (self , D_args : T .List [str ], U_args : T .List [str ]) -> bool :
10781089 dirty = False
@@ -1289,22 +1300,10 @@ def initialize_from_top_level_project_call(self,
12891300 project_default_options_in : OptionDict ,
12901301 cmd_line_options_in : OptionDict ,
12911302 machine_file_options_in : T .Mapping [OptionKey , ElementaryOptionValues ]) -> None :
1292- first_invocation = True
12931303 (project_default_options , cmd_line_options , machine_file_options ) = self .first_handle_prefix (project_default_options_in ,
12941304 cmd_line_options_in ,
12951305 machine_file_options_in )
12961306 for keystr , valstr in project_default_options .items ():
1297- # Ths is complicated by the fact that a string can have two meanings:
1298- #
1299- # default_options: 'foo=bar'
1300- #
1301- # can be either
1302- #
1303- # A) a system option in which case the subproject is None
1304- # B) a project option, in which case the subproject is '' (this method is only called from top level)
1305- #
1306- # The key parsing function can not handle the difference between the two
1307- # and defaults to A.
13081307 if isinstance (keystr , str ):
13091308 key = OptionKey .from_string (keystr )
13101309 else :
@@ -1315,33 +1314,21 @@ def initialize_from_top_level_project_call(self,
13151314 continue
13161315 if key .subproject :
13171316 self .augments [key ] = valstr
1318- elif key in self .options :
1319- self .set_option (key , valstr , first_invocation )
13201317 else :
1321- # Setting a project option with default_options.
1322- # Argubly this should be a hard error, the default
1318+ # Setting a project option with default_options
1319+ # should arguably be a hard error; the default
13231320 # value of project option should be set in the option
13241321 # file, not in the project call.
1325- proj_key = key .as_root ()
1326- if self .is_project_option (proj_key ):
1327- self .set_option (proj_key , valstr )
1328- else :
1329- self .pending_options [key ] = valstr
1322+ self .set_option_maybe_root (key , valstr , True )
13301323 for key , valstr in machine_file_options .items ():
13311324 # Due to backwards compatibility we ignore all build-machine options
13321325 # when building natively.
13331326 if not self .is_cross and key .is_for_build ():
13341327 continue
13351328 if key .subproject :
13361329 self .augments [key ] = valstr
1337- elif key in self .options :
1338- self .set_option (key , valstr , first_invocation )
13391330 else :
1340- proj_key = key .as_root ()
1341- if proj_key in self .options :
1342- self .set_option (proj_key , valstr , first_invocation )
1343- else :
1344- self .pending_options [key ] = valstr
1331+ self .set_option_maybe_root (key , valstr , True )
13451332 for keystr , valstr in cmd_line_options .items ():
13461333 if isinstance (keystr , str ):
13471334 key = OptionKey .from_string (keystr )
@@ -1353,14 +1340,8 @@ def initialize_from_top_level_project_call(self,
13531340 continue
13541341 if key .subproject :
13551342 self .augments [key ] = valstr
1356- elif key in self .options :
1357- self .set_option (key , valstr , True )
13581343 else :
1359- proj_key = key .as_root ()
1360- if proj_key in self .options :
1361- self .set_option (proj_key , valstr , True )
1362- else :
1363- self .pending_options [key ] = valstr
1344+ self .set_option_maybe_root (key , valstr , True )
13641345
13651346 def accept_as_pending_option (self , key : OptionKey , known_subprojects : T .Optional [T .Container [str ]] = None ,
13661347 first_invocation : bool = False ) -> bool :
0 commit comments