28
28
import com .google .common .collect .ImmutableMap ;
29
29
import com .google .common .collect .ImmutableSet ;
30
30
import com .google .common .collect .ImmutableSortedSet ;
31
+ import com .google .common .collect .ImmutableTable ;
31
32
import com .google .common .collect .Iterables ;
32
33
import com .google .common .collect .ListMultimap ;
33
34
import com .google .common .collect .Lists ;
@@ -217,7 +218,7 @@ public ImmutableList<TransitiveInfoCollection> getFiles() {
217
218
private final ConstraintSemantics <RuleContext > constraintSemantics ;
218
219
private final ImmutableSet <String > requiredConfigFragments ;
219
220
private final List <Expander > makeVariableExpanders = new ArrayList <>();
220
- private final ImmutableMap <String , ImmutableMap < String , String > > execProperties ;
221
+ private final ImmutableTable <String , String , String > execProperties ;
221
222
222
223
/** Map of exec group names to ActionOwners. */
223
224
private final Map <String , ActionOwner > actionOwners = new HashMap <>();
@@ -635,17 +636,16 @@ private static ImmutableMap<String, String> computeExecProperties(
635
636
Map <String , String > execProperties = new HashMap <>();
636
637
637
638
if (executionPlatform != null ) {
638
- Map <String , Map < String , String > > execPropertiesPerGroup =
639
+ ImmutableTable <String , String , String > execPropertiesPerGroup =
639
640
parseExecGroups (executionPlatform .execProperties ());
640
641
641
- if (execPropertiesPerGroup .containsKey (DEFAULT_EXEC_GROUP_NAME )) {
642
- execProperties .putAll (execPropertiesPerGroup .get (DEFAULT_EXEC_GROUP_NAME ));
643
- execPropertiesPerGroup .remove (DEFAULT_EXEC_GROUP_NAME );
642
+ if (execPropertiesPerGroup .containsRow (DEFAULT_EXEC_GROUP_NAME )) {
643
+ execProperties .putAll (execPropertiesPerGroup .row (DEFAULT_EXEC_GROUP_NAME ));
644
644
}
645
645
646
- for (Map . Entry < String , Map < String , String >> execGroup : execPropertiesPerGroup .entrySet ()) {
647
- if (execGroups .contains (execGroup . getKey () )) {
648
- execProperties .putAll (execGroup . getValue ( ));
646
+ for (String execGroup : execPropertiesPerGroup .rowKeySet ()) {
647
+ if (execGroups .contains (execGroup )) {
648
+ execProperties .putAll (execPropertiesPerGroup . row ( execGroup ));
649
649
}
650
650
}
651
651
}
@@ -1404,10 +1404,10 @@ public ImmutableSortedSet<String> getRequiredConfigFragments() {
1404
1404
return ans .build ();
1405
1405
}
1406
1406
1407
- private ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1407
+ private ImmutableTable <String , String , String > parseExecProperties (
1408
1408
Map <String , String > execProperties ) throws InvalidExecGroupException {
1409
1409
if (execProperties .isEmpty ()) {
1410
- return ImmutableMap .of (DEFAULT_EXEC_GROUP_NAME , ImmutableMap . of () );
1410
+ return ImmutableTable .of ();
1411
1411
} else {
1412
1412
return parseExecProperties (
1413
1413
execProperties , toolchainContexts == null ? null : toolchainContexts .getExecGroups ());
@@ -1420,39 +1420,35 @@ private ImmutableMap<String, ImmutableMap<String, String>> parseExecProperties(
1420
1420
* former get parsed into the default exec group, the latter get parsed into their relevant exec
1421
1421
* groups.
1422
1422
*/
1423
- private static Map <String , Map < String , String > > parseExecGroups (
1423
+ private static ImmutableTable <String , String , String > parseExecGroups (
1424
1424
Map <String , String > rawExecProperties ) {
1425
- Map <String , Map <String , String >> consolidatedProperties = new HashMap <>();
1426
- consolidatedProperties .put (DEFAULT_EXEC_GROUP_NAME , new HashMap <>());
1425
+ ImmutableTable .Builder <String , String , String > execProperties = ImmutableTable .builder ();
1427
1426
for (Map .Entry <String , String > execProperty : rawExecProperties .entrySet ()) {
1428
1427
String rawProperty = execProperty .getKey ();
1429
1428
int delimiterIndex = rawProperty .indexOf ('.' );
1430
1429
if (delimiterIndex == -1 ) {
1431
- consolidatedProperties
1432
- .get (DEFAULT_EXEC_GROUP_NAME )
1433
- .put (rawProperty , execProperty .getValue ());
1430
+ execProperties .put (DEFAULT_EXEC_GROUP_NAME , rawProperty , execProperty .getValue ());
1434
1431
} else {
1435
1432
String execGroup = rawProperty .substring (0 , delimiterIndex );
1436
1433
String property = rawProperty .substring (delimiterIndex + 1 );
1437
- consolidatedProperties .putIfAbsent (execGroup , new HashMap <>());
1438
- consolidatedProperties .get (execGroup ).put (property , execProperty .getValue ());
1434
+ execProperties .put (execGroup , property , execProperty .getValue ());
1439
1435
}
1440
1436
}
1441
- return consolidatedProperties ;
1437
+ return execProperties . build () ;
1442
1438
}
1443
1439
1444
1440
/**
1445
1441
* Parse raw exec properties attribute value into a map of exec group names to their properties.
1446
1442
* If given a set of exec groups, validates all the exec groups in the map are applicable to the
1447
1443
* action.
1448
1444
*/
1449
- private static ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1445
+ private static ImmutableTable <String , String , String > parseExecProperties (
1450
1446
Map <String , String > rawExecProperties , @ Nullable Set <String > execGroups )
1451
1447
throws InvalidExecGroupException {
1452
- Map <String , Map <String , String >> consolidatedProperties = parseExecGroups (rawExecProperties );
1448
+ ImmutableTable <String , String , String > consolidatedProperties =
1449
+ parseExecGroups (rawExecProperties );
1453
1450
if (execGroups != null ) {
1454
- for (Map .Entry <String , Map <String , String >> execGroup : consolidatedProperties .entrySet ()) {
1455
- String execGroupName = execGroup .getKey ();
1451
+ for (String execGroupName : consolidatedProperties .rowKeySet ()) {
1456
1452
if (!execGroupName .equals (DEFAULT_EXEC_GROUP_NAME ) && !execGroups .contains (execGroupName )) {
1457
1453
throw new InvalidExecGroupException (
1458
1454
String .format (
@@ -1461,14 +1457,7 @@ private static ImmutableMap<String, ImmutableMap<String, String>> parseExecPrope
1461
1457
}
1462
1458
}
1463
1459
1464
- // Copy everything to immutable maps.
1465
- ImmutableMap .Builder <String , ImmutableMap <String , String >> execProperties =
1466
- new ImmutableMap .Builder <>();
1467
- for (Map .Entry <String , Map <String , String >> execGroupMap : consolidatedProperties .entrySet ()) {
1468
- execProperties .put (execGroupMap .getKey (), ImmutableMap .copyOf (execGroupMap .getValue ()));
1469
- }
1470
-
1471
- return execProperties .build ();
1460
+ return consolidatedProperties ;
1472
1461
}
1473
1462
1474
1463
/**
@@ -1480,16 +1469,16 @@ private static ImmutableMap<String, ImmutableMap<String, String>> parseExecPrope
1480
1469
* @param execProperties Map of exec group name to map of properties and values
1481
1470
*/
1482
1471
private static ImmutableMap <String , String > getExecProperties (
1483
- String execGroup , Map <String , ImmutableMap < String , String > > execProperties ) {
1484
- if (!execProperties .containsKey (execGroup ) || execGroup .equals (DEFAULT_EXEC_GROUP_NAME )) {
1485
- return execProperties .get (DEFAULT_EXEC_GROUP_NAME );
1472
+ String execGroup , ImmutableTable <String , String , String > execProperties ) {
1473
+ if (!execProperties .containsRow (execGroup ) || execGroup .equals (DEFAULT_EXEC_GROUP_NAME )) {
1474
+ return execProperties .row (DEFAULT_EXEC_GROUP_NAME );
1486
1475
}
1487
1476
1488
1477
// Use a HashMap to build here because we expect duplicate keys to happen
1489
1478
// (and rewrite previous entries).
1490
1479
Map <String , String > targetAndGroupProperties =
1491
- new HashMap <>(execProperties .get (DEFAULT_EXEC_GROUP_NAME ));
1492
- targetAndGroupProperties .putAll (execProperties .get (execGroup ));
1480
+ new HashMap <>(execProperties .row (DEFAULT_EXEC_GROUP_NAME ));
1481
+ targetAndGroupProperties .putAll (execProperties .row (execGroup ));
1493
1482
return ImmutableMap .copyOf (targetAndGroupProperties );
1494
1483
}
1495
1484
@@ -1510,11 +1499,6 @@ public DetailedExitCode getDetailedExitCode() {
1510
1499
}
1511
1500
}
1512
1501
1513
- @ VisibleForTesting
1514
- public ImmutableMap <String , ImmutableMap <String , String >> getExecPropertiesForTesting () {
1515
- return execProperties ;
1516
- }
1517
-
1518
1502
private void checkAttributeIsDependency (String attributeName ) {
1519
1503
Attribute attributeDefinition = attributes .getAttributeDefinition (attributeName );
1520
1504
if (attributeDefinition == null ) {
0 commit comments