@@ -1305,30 +1305,31 @@ def initialize_from_top_level_project_call(self,
1305
1305
if not self .is_cross and key .is_for_build ():
1306
1306
continue
1307
1307
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
1309
1311
else :
1310
1312
# Setting a project option with default_options
1311
1313
# should arguably be a hard error; the default
1312
1314
# value of project option should be set in the option
1313
1315
# file, not in the project call.
1314
1316
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
1315
1320
for key , valstr in machine_file_options .items ():
1316
1321
# Due to backwards compatibility we ignore all build-machine options
1317
1322
# when building natively.
1318
1323
if not self .is_cross and key .is_for_build ():
1319
1324
continue
1320
- if key .subproject :
1321
- self .augments [key ] = valstr
1322
- else :
1325
+ if not key .subproject :
1323
1326
self .set_option_maybe_root (key , valstr , True )
1324
1327
for key , valstr in cmd_line_options .items ():
1325
1328
# Due to backwards compatibility we ignore all build-machine options
1326
1329
# when building natively.
1327
1330
if not self .is_cross and key .is_for_build ():
1328
1331
continue
1329
- if key .subproject :
1330
- self .augments [key ] = valstr
1331
- else :
1332
+ if not key .subproject :
1332
1333
self .set_option_maybe_root (key , valstr , True )
1333
1334
1334
1335
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,
1362
1363
subproject : str ,
1363
1364
spcall_default_options : OptionDict ,
1364
1365
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
1366
1372
for key , valstr in itertools .chain (project_default_options .items (), spcall_default_options .items ()):
1367
1373
if key .subproject is None :
1368
1374
key = key .evolve (subproject = subproject )
1369
1375
elif key .subproject == subproject :
1370
1376
without_subp = key .evolve (subproject = None )
1371
1377
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 ():
1383
1394
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 :
1385
1397
self .set_option (key , valstr , True )
1386
1398
else :
1387
1399
self .augments [key ] = valstr
0 commit comments