@@ -1305,30 +1305,31 @@ def initialize_from_top_level_project_call(self,
13051305 if not self .is_cross and key .is_for_build ():
13061306 continue
13071307 if key .subproject :
1308- self .augments [key ] = valstr
1308+ # do apply project() default_options for subprojects here, because
1309+ # they have low priority
1310+ self .pending_options [key ] = valstr
13091311 else :
13101312 # Setting a project option with default_options
13111313 # should arguably be a hard error; the default
13121314 # value of project option should be set in the option
13131315 # file, not in the project call.
13141316 self .set_option_maybe_root (key , valstr , True )
1317+
1318+ # ignore subprojects for now for machine file and command line
1319+ # options; they are applied later
13151320 for key , valstr in machine_file_options .items ():
13161321 # Due to backwards compatibility we ignore all build-machine options
13171322 # when building natively.
13181323 if not self .is_cross and key .is_for_build ():
13191324 continue
1320- if key .subproject :
1321- self .augments [key ] = valstr
1322- else :
1325+ if not key .subproject :
13231326 self .set_option_maybe_root (key , valstr , True )
13241327 for key , valstr in cmd_line_options .items ():
13251328 # Due to backwards compatibility we ignore all build-machine options
13261329 # when building natively.
13271330 if not self .is_cross and key .is_for_build ():
13281331 continue
1329- if key .subproject :
1330- self .augments [key ] = valstr
1331- else :
1332+ if not key .subproject :
13321333 self .set_option_maybe_root (key , valstr , True )
13331334
13341335 def accept_as_pending_option (self , key : OptionKey , known_subprojects : T .Optional [T .Container [str ]] = None ,
@@ -1362,26 +1363,37 @@ def initialize_from_subproject_call(self,
13621363 subproject : str ,
13631364 spcall_default_options : OptionDict ,
13641365 project_default_options : OptionDict ,
1365- cmd_line_options : OptionDict ) -> None :
1366+ cmd_line_options : OptionDict ,
1367+ machine_file_options : OptionDict ) -> None :
1368+ # pick up pending per-project settings from the toplevel project() invocation
1369+ options = {k : v for k , v in self .pending_options .items () if k .subproject == subproject }
1370+
1371+ # apply project() and subproject() default_options
13661372 for key , valstr in itertools .chain (project_default_options .items (), spcall_default_options .items ()):
13671373 if key .subproject is None :
13681374 key = key .evolve (subproject = subproject )
13691375 elif key .subproject == subproject :
13701376 without_subp = key .evolve (subproject = None )
13711377 raise MesonException (f'subproject name not needed in default_options; use "{ without_subp } " instead of "{ key } "' )
1372- # If the key points to a project option, set the value from that.
1373- # Otherwise set an augment.
1374- if key in self .project_options :
1375- self .set_option (key , valstr , True )
1376- else :
1377- self .pending_options .pop (key , None )
1378- self .augments [key ] = valstr
1379- # Check for pending options
1380- for key , valstr in cmd_line_options .items ():
1381- if key .subproject != subproject :
1382- continue
1378+ options [key ] = valstr
1379+
1380+ # then global settings from machine file and command line
1381+ for key , valstr in itertools .chain (machine_file_options .items (), cmd_line_options .items ()):
1382+ if key .subproject is None :
1383+ subp_key = key .evolve (subproject = subproject )
1384+ self .pending_options .pop (subp_key , None )
1385+ options .pop (subp_key , None )
1386+
1387+ # then finally per project augments from machine file and command line
1388+ for key , valstr in itertools .chain (machine_file_options .items (), cmd_line_options .items ()):
1389+ if key .subproject == subproject :
1390+ options [key ] = valstr
1391+
1392+ # merge everything that has been computed above, while giving self.augments priority
1393+ for key , valstr in options .items ():
13831394 self .pending_options .pop (key , None )
1384- if key in self .options :
1395+ valstr = self .augments .pop (key , valstr )
1396+ if key in self .project_options :
13851397 self .set_option (key , valstr , True )
13861398 else :
13871399 self .augments [key ] = valstr
0 commit comments