@@ -515,7 +515,8 @@ public ActionOwner getActionOwner(String execGroup) {
515
515
aspectDescriptors ,
516
516
getConfiguration (),
517
517
getExecProperties (execGroup , execProperties ),
518
- getExecutionPlatform (execGroup ));
518
+ getExecutionPlatform (execGroup ),
519
+ ImmutableSet .of (execGroup ));
519
520
actionOwners .put (execGroup , actionOwner );
520
521
return actionOwner ;
521
522
}
@@ -622,12 +623,31 @@ public ImmutableList<Artifact> getBuildInfo(BuildInfoKey key) throws Interrupted
622
623
AnalysisUtils .isStampingEnabled (this , getConfiguration ()), key , getConfiguration ());
623
624
}
624
625
626
+ /**
627
+ * Computes a map of exec properties given the execution platform, taking only properties in exec
628
+ * groups that are applicable to this action. Properties for specific exec groups take precedence
629
+ * over properties that don't specify an exec group.
630
+ */
625
631
private static ImmutableMap <String , String > computeExecProperties (
626
- Map <String , String > targetExecProperties , @ Nullable PlatformInfo executionPlatform ) {
632
+ Map <String , String > targetExecProperties ,
633
+ @ Nullable PlatformInfo executionPlatform ,
634
+ Set <String > execGroups ) {
627
635
Map <String , String > execProperties = new HashMap <>();
628
636
629
637
if (executionPlatform != null ) {
630
- execProperties .putAll (executionPlatform .execProperties ());
638
+ Map <String , Map <String , String >> execPropertiesPerGroup =
639
+ parseExecGroups (executionPlatform .execProperties ());
640
+
641
+ if (execPropertiesPerGroup .containsKey (DEFAULT_EXEC_GROUP_NAME )) {
642
+ execProperties .putAll (execPropertiesPerGroup .get (DEFAULT_EXEC_GROUP_NAME ));
643
+ execPropertiesPerGroup .remove (DEFAULT_EXEC_GROUP_NAME );
644
+ }
645
+
646
+ for (Map .Entry <String , Map <String , String >> execGroup : execPropertiesPerGroup .entrySet ()) {
647
+ if (execGroups .contains (execGroup .getKey ())) {
648
+ execProperties .putAll (execGroup .getValue ());
649
+ }
650
+ }
631
651
}
632
652
633
653
// If the same key occurs both in the platform and in target-specific properties, the
@@ -643,7 +663,8 @@ public static ActionOwner createActionOwner(
643
663
ImmutableList <AspectDescriptor > aspectDescriptors ,
644
664
BuildConfiguration configuration ,
645
665
Map <String , String > targetExecProperties ,
646
- @ Nullable PlatformInfo executionPlatform ) {
666
+ @ Nullable PlatformInfo executionPlatform ,
667
+ Set <String > execGroups ) {
647
668
return ActionOwner .create (
648
669
rule .getLabel (),
649
670
aspectDescriptors ,
@@ -653,7 +674,7 @@ public static ActionOwner createActionOwner(
653
674
configuration .checksum (),
654
675
configuration .toBuildEvent (),
655
676
configuration .isHostConfiguration () ? HOST_CONFIGURATION_PROGRESS_TAG : null ,
656
- computeExecProperties (targetExecProperties , executionPlatform ),
677
+ computeExecProperties (targetExecProperties , executionPlatform , execGroups ),
657
678
executionPlatform );
658
679
}
659
680
@@ -1389,20 +1410,18 @@ private ImmutableMap<String, ImmutableMap<String, String>> parseExecProperties(
1389
1410
return ImmutableMap .of (DEFAULT_EXEC_GROUP_NAME , ImmutableMap .of ());
1390
1411
} else {
1391
1412
return parseExecProperties (
1392
- execProperties ,
1393
- toolchainContexts == null ? ImmutableSet .of () : toolchainContexts .getExecGroups ());
1413
+ execProperties , toolchainContexts == null ? null : toolchainContexts .getExecGroups ());
1394
1414
}
1395
1415
}
1396
1416
1397
1417
/**
1398
1418
* Parse raw exec properties attribute value into a map of exec group names to their properties.
1399
1419
* The raw map can have keys of two forms: (1) 'property' and (2) 'exec_group_name.property'. The
1400
- * former get parsed into the target's default exec group, the latter get parsed into their
1401
- * relevant exec groups.
1420
+ * former get parsed into the default exec group, the latter get parsed into their relevant exec
1421
+ * groups.
1402
1422
*/
1403
- private static ImmutableMap <String , ImmutableMap <String , String >> parseExecProperties (
1404
- Map <String , String > rawExecProperties , Set <String > execGroups )
1405
- throws InvalidExecGroupException {
1423
+ private static Map <String , Map <String , String >> parseExecGroups (
1424
+ Map <String , String > rawExecProperties ) {
1406
1425
Map <String , Map <String , String >> consolidatedProperties = new HashMap <>();
1407
1426
consolidatedProperties .put (DEFAULT_EXEC_GROUP_NAME , new HashMap <>());
1408
1427
for (Map .Entry <String , String > execProperty : rawExecProperties .entrySet ()) {
@@ -1415,14 +1434,30 @@ private static ImmutableMap<String, ImmutableMap<String, String>> parseExecPrope
1415
1434
} else {
1416
1435
String execGroup = rawProperty .substring (0 , delimiterIndex );
1417
1436
String property = rawProperty .substring (delimiterIndex + 1 );
1418
- if (!execGroups .contains (execGroup )) {
1437
+ consolidatedProperties .putIfAbsent (execGroup , new HashMap <>());
1438
+ consolidatedProperties .get (execGroup ).put (property , execProperty .getValue ());
1439
+ }
1440
+ }
1441
+ return consolidatedProperties ;
1442
+ }
1443
+
1444
+ /**
1445
+ * Parse raw exec properties attribute value into a map of exec group names to their properties.
1446
+ * If given a set of exec groups, validates all the exec groups in the map are applicable to the
1447
+ * action.
1448
+ */
1449
+ private static ImmutableMap <String , ImmutableMap <String , String >> parseExecProperties (
1450
+ Map <String , String > rawExecProperties , @ Nullable Set <String > execGroups )
1451
+ throws InvalidExecGroupException {
1452
+ Map <String , Map <String , String >> consolidatedProperties = parseExecGroups (rawExecProperties );
1453
+ if (execGroups != null ) {
1454
+ for (Map .Entry <String , Map <String , String >> execGroup : consolidatedProperties .entrySet ()) {
1455
+ String execGroupName = execGroup .getKey ();
1456
+ if (!execGroupName .equals (DEFAULT_EXEC_GROUP_NAME ) && !execGroups .contains (execGroupName )) {
1419
1457
throw new InvalidExecGroupException (
1420
1458
String .format (
1421
- "Tried to set exec property '%s' for non-existent exec group '%s'." ,
1422
- property , execGroup ));
1459
+ "Tried to set properties for non-existent exec group '%s'." , execGroupName ));
1423
1460
}
1424
- consolidatedProperties .putIfAbsent (execGroup , new HashMap <>());
1425
- consolidatedProperties .get (execGroup ).put (property , execProperty .getValue ());
1426
1461
}
1427
1462
}
1428
1463
0 commit comments