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 ;
32
31
import com .google .common .collect .Iterables ;
33
32
import com .google .common .collect .ListMultimap ;
34
33
import com .google .common .collect .Lists ;
@@ -211,7 +210,7 @@ public ImmutableList<TransitiveInfoCollection> getFiles() {
211
210
private final ConstraintSemantics <RuleContext > constraintSemantics ;
212
211
private final ImmutableSet <String > requiredConfigFragments ;
213
212
private final List <Expander > makeVariableExpanders = new ArrayList <>();
214
- private final ImmutableTable <String , String , String > execProperties ;
213
+ private final ImmutableMap <String , ImmutableMap < String , String > > execProperties ;
215
214
216
215
/** Map of exec group names to ActionOwners. */
217
216
private final Map <String , ActionOwner > actionOwners = new HashMap <>();
@@ -604,16 +603,17 @@ private static ImmutableMap<String, String> computeExecProperties(
604
603
Map <String , String > execProperties = new HashMap <>();
605
604
606
605
if (executionPlatform != null ) {
607
- ImmutableTable <String , String , String > execPropertiesPerGroup =
606
+ Map <String , Map < String , String > > execPropertiesPerGroup =
608
607
parseExecGroups (executionPlatform .execProperties ());
609
608
610
- if (execPropertiesPerGroup .containsRow (DEFAULT_EXEC_GROUP_NAME )) {
611
- execProperties .putAll (execPropertiesPerGroup .row (DEFAULT_EXEC_GROUP_NAME ));
609
+ if (execPropertiesPerGroup .containsKey (DEFAULT_EXEC_GROUP_NAME )) {
610
+ execProperties .putAll (execPropertiesPerGroup .get (DEFAULT_EXEC_GROUP_NAME ));
611
+ execPropertiesPerGroup .remove (DEFAULT_EXEC_GROUP_NAME );
612
612
}
613
613
614
- for (String execGroup : execPropertiesPerGroup .rowKeySet ()) {
615
- if (execGroups .contains (execGroup )) {
616
- execProperties .putAll (execPropertiesPerGroup . row ( execGroup ));
614
+ for (Map . Entry < String , Map < String , String >> execGroup : execPropertiesPerGroup .entrySet ()) {
615
+ if (execGroups .contains (execGroup . getKey () )) {
616
+ execProperties .putAll (execGroup . getValue ( ));
617
617
}
618
618
}
619
619
}
@@ -1273,10 +1273,10 @@ public ImmutableSortedSet<String> getRequiredConfigFragments() {
1273
1273
return ans .build ();
1274
1274
}
1275
1275
1276
- private ImmutableTable <String , String , String > parseExecProperties (
1276
+ private ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1277
1277
Map <String , String > execProperties ) throws InvalidExecGroupException {
1278
1278
if (execProperties .isEmpty ()) {
1279
- return ImmutableTable .of ();
1279
+ return ImmutableMap .of (DEFAULT_EXEC_GROUP_NAME , ImmutableMap . of () );
1280
1280
} else {
1281
1281
return parseExecProperties (
1282
1282
execProperties , toolchainContexts == null ? null : toolchainContexts .getExecGroups ());
@@ -1289,35 +1289,39 @@ private ImmutableTable<String, String, String> parseExecProperties(
1289
1289
* former get parsed into the default exec group, the latter get parsed into their relevant exec
1290
1290
* groups.
1291
1291
*/
1292
- private static ImmutableTable <String , String , String > parseExecGroups (
1292
+ private static Map <String , Map < String , String > > parseExecGroups (
1293
1293
Map <String , String > rawExecProperties ) {
1294
- ImmutableTable .Builder <String , String , String > execProperties = ImmutableTable .builder ();
1294
+ Map <String , Map <String , String >> consolidatedProperties = new HashMap <>();
1295
+ consolidatedProperties .put (DEFAULT_EXEC_GROUP_NAME , new HashMap <>());
1295
1296
for (Map .Entry <String , String > execProperty : rawExecProperties .entrySet ()) {
1296
1297
String rawProperty = execProperty .getKey ();
1297
1298
int delimiterIndex = rawProperty .indexOf ('.' );
1298
1299
if (delimiterIndex == -1 ) {
1299
- execProperties .put (DEFAULT_EXEC_GROUP_NAME , rawProperty , execProperty .getValue ());
1300
+ consolidatedProperties
1301
+ .get (DEFAULT_EXEC_GROUP_NAME )
1302
+ .put (rawProperty , execProperty .getValue ());
1300
1303
} else {
1301
1304
String execGroup = rawProperty .substring (0 , delimiterIndex );
1302
1305
String property = rawProperty .substring (delimiterIndex + 1 );
1303
- execProperties .put (execGroup , property , execProperty .getValue ());
1306
+ consolidatedProperties .putIfAbsent (execGroup , new HashMap <>());
1307
+ consolidatedProperties .get (execGroup ).put (property , execProperty .getValue ());
1304
1308
}
1305
1309
}
1306
- return execProperties . build () ;
1310
+ return consolidatedProperties ;
1307
1311
}
1308
1312
1309
1313
/**
1310
1314
* Parse raw exec properties attribute value into a map of exec group names to their properties.
1311
1315
* If given a set of exec groups, validates all the exec groups in the map are applicable to the
1312
1316
* action.
1313
1317
*/
1314
- private static ImmutableTable <String , String , String > parseExecProperties (
1318
+ private static ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1315
1319
Map <String , String > rawExecProperties , @ Nullable Set <String > execGroups )
1316
1320
throws InvalidExecGroupException {
1317
- ImmutableTable <String , String , String > consolidatedProperties =
1318
- parseExecGroups (rawExecProperties );
1321
+ Map <String , Map <String , String >> consolidatedProperties = parseExecGroups (rawExecProperties );
1319
1322
if (execGroups != null ) {
1320
- for (String execGroupName : consolidatedProperties .rowKeySet ()) {
1323
+ for (Map .Entry <String , Map <String , String >> execGroup : consolidatedProperties .entrySet ()) {
1324
+ String execGroupName = execGroup .getKey ();
1321
1325
if (!execGroupName .equals (DEFAULT_EXEC_GROUP_NAME ) && !execGroups .contains (execGroupName )) {
1322
1326
throw new InvalidExecGroupException (
1323
1327
String .format (
@@ -1326,7 +1330,14 @@ private static ImmutableTable<String, String, String> parseExecProperties(
1326
1330
}
1327
1331
}
1328
1332
1329
- return consolidatedProperties ;
1333
+ // Copy everything to immutable maps.
1334
+ ImmutableMap .Builder <String , ImmutableMap <String , String >> execProperties =
1335
+ new ImmutableMap .Builder <>();
1336
+ for (Map .Entry <String , Map <String , String >> execGroupMap : consolidatedProperties .entrySet ()) {
1337
+ execProperties .put (execGroupMap .getKey (), ImmutableMap .copyOf (execGroupMap .getValue ()));
1338
+ }
1339
+
1340
+ return execProperties .build ();
1330
1341
}
1331
1342
1332
1343
/**
@@ -1338,16 +1349,16 @@ private static ImmutableTable<String, String, String> parseExecProperties(
1338
1349
* @param execProperties Map of exec group name to map of properties and values
1339
1350
*/
1340
1351
private static ImmutableMap <String , String > getExecProperties (
1341
- String execGroup , ImmutableTable <String , String , String > execProperties ) {
1342
- if (!execProperties .containsRow (execGroup ) || execGroup .equals (DEFAULT_EXEC_GROUP_NAME )) {
1343
- return execProperties .row (DEFAULT_EXEC_GROUP_NAME );
1352
+ String execGroup , Map <String , ImmutableMap < String , String > > execProperties ) {
1353
+ if (!execProperties .containsKey (execGroup ) || execGroup .equals (DEFAULT_EXEC_GROUP_NAME )) {
1354
+ return execProperties .get (DEFAULT_EXEC_GROUP_NAME );
1344
1355
}
1345
1356
1346
1357
// Use a HashMap to build here because we expect duplicate keys to happen
1347
1358
// (and rewrite previous entries).
1348
1359
Map <String , String > targetAndGroupProperties =
1349
- new HashMap <>(execProperties .row (DEFAULT_EXEC_GROUP_NAME ));
1350
- targetAndGroupProperties .putAll (execProperties .row (execGroup ));
1360
+ new HashMap <>(execProperties .get (DEFAULT_EXEC_GROUP_NAME ));
1361
+ targetAndGroupProperties .putAll (execProperties .get (execGroup ));
1351
1362
return ImmutableMap .copyOf (targetAndGroupProperties );
1352
1363
}
1353
1364
@@ -1368,6 +1379,11 @@ public DetailedExitCode getDetailedExitCode() {
1368
1379
}
1369
1380
}
1370
1381
1382
+ @ VisibleForTesting
1383
+ public ImmutableMap <String , ImmutableMap <String , String >> getExecPropertiesForTesting () {
1384
+ return execProperties ;
1385
+ }
1386
+
1371
1387
private void checkAttributeIsDependency (String attributeName ) {
1372
1388
Attribute attributeDefinition = attributes .getAttributeDefinition (attributeName );
1373
1389
if (attributeDefinition == null ) {
0 commit comments