2828import com .google .common .collect .ImmutableMap ;
2929import com .google .common .collect .ImmutableSet ;
3030import com .google .common .collect .ImmutableSortedSet ;
31+ import com .google .common .collect .ImmutableTable ;
3132import com .google .common .collect .Iterables ;
3233import com .google .common .collect .ListMultimap ;
3334import com .google .common .collect .Lists ;
@@ -210,7 +211,7 @@ public ImmutableList<TransitiveInfoCollection> getFiles() {
210211 private final ConstraintSemantics <RuleContext > constraintSemantics ;
211212 private final ImmutableSet <String > requiredConfigFragments ;
212213 private final List <Expander > makeVariableExpanders = new ArrayList <>();
213- private final ImmutableMap <String , ImmutableMap < String , String > > execProperties ;
214+ private final ImmutableTable <String , String , String > execProperties ;
214215
215216 /** Map of exec group names to ActionOwners. */
216217 private final Map <String , ActionOwner > actionOwners = new HashMap <>();
@@ -603,17 +604,16 @@ private static ImmutableMap<String, String> computeExecProperties(
603604 Map <String , String > execProperties = new HashMap <>();
604605
605606 if (executionPlatform != null ) {
606- Map <String , Map < String , String > > execPropertiesPerGroup =
607+ ImmutableTable <String , String , String > execPropertiesPerGroup =
607608 parseExecGroups (executionPlatform .execProperties ());
608609
609- if (execPropertiesPerGroup .containsKey (DEFAULT_EXEC_GROUP_NAME )) {
610- execProperties .putAll (execPropertiesPerGroup .get (DEFAULT_EXEC_GROUP_NAME ));
611- execPropertiesPerGroup .remove (DEFAULT_EXEC_GROUP_NAME );
610+ if (execPropertiesPerGroup .containsRow (DEFAULT_EXEC_GROUP_NAME )) {
611+ execProperties .putAll (execPropertiesPerGroup .row (DEFAULT_EXEC_GROUP_NAME ));
612612 }
613613
614- for (Map . Entry < String , Map < String , String >> execGroup : execPropertiesPerGroup .entrySet ()) {
615- if (execGroups .contains (execGroup . getKey () )) {
616- execProperties .putAll (execGroup . getValue ( ));
614+ for (String execGroup : execPropertiesPerGroup .rowKeySet ()) {
615+ if (execGroups .contains (execGroup )) {
616+ execProperties .putAll (execPropertiesPerGroup . row ( execGroup ));
617617 }
618618 }
619619 }
@@ -1273,10 +1273,10 @@ public ImmutableSortedSet<String> getRequiredConfigFragments() {
12731273 return ans .build ();
12741274 }
12751275
1276- private ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1276+ private ImmutableTable <String , String , String > parseExecProperties (
12771277 Map <String , String > execProperties ) throws InvalidExecGroupException {
12781278 if (execProperties .isEmpty ()) {
1279- return ImmutableMap .of (DEFAULT_EXEC_GROUP_NAME , ImmutableMap . of () );
1279+ return ImmutableTable .of ();
12801280 } else {
12811281 return parseExecProperties (
12821282 execProperties , toolchainContexts == null ? null : toolchainContexts .getExecGroups ());
@@ -1289,39 +1289,35 @@ private ImmutableMap<String, ImmutableMap<String, String>> parseExecProperties(
12891289 * former get parsed into the default exec group, the latter get parsed into their relevant exec
12901290 * groups.
12911291 */
1292- private static Map <String , Map < String , String > > parseExecGroups (
1292+ private static ImmutableTable <String , String , String > parseExecGroups (
12931293 Map <String , String > rawExecProperties ) {
1294- Map <String , Map <String , String >> consolidatedProperties = new HashMap <>();
1295- consolidatedProperties .put (DEFAULT_EXEC_GROUP_NAME , new HashMap <>());
1294+ ImmutableTable .Builder <String , String , String > execProperties = ImmutableTable .builder ();
12961295 for (Map .Entry <String , String > execProperty : rawExecProperties .entrySet ()) {
12971296 String rawProperty = execProperty .getKey ();
12981297 int delimiterIndex = rawProperty .indexOf ('.' );
12991298 if (delimiterIndex == -1 ) {
1300- consolidatedProperties
1301- .get (DEFAULT_EXEC_GROUP_NAME )
1302- .put (rawProperty , execProperty .getValue ());
1299+ execProperties .put (DEFAULT_EXEC_GROUP_NAME , rawProperty , execProperty .getValue ());
13031300 } else {
13041301 String execGroup = rawProperty .substring (0 , delimiterIndex );
13051302 String property = rawProperty .substring (delimiterIndex + 1 );
1306- consolidatedProperties .putIfAbsent (execGroup , new HashMap <>());
1307- consolidatedProperties .get (execGroup ).put (property , execProperty .getValue ());
1303+ execProperties .put (execGroup , property , execProperty .getValue ());
13081304 }
13091305 }
1310- return consolidatedProperties ;
1306+ return execProperties . build () ;
13111307 }
13121308
13131309 /**
13141310 * Parse raw exec properties attribute value into a map of exec group names to their properties.
13151311 * If given a set of exec groups, validates all the exec groups in the map are applicable to the
13161312 * action.
13171313 */
1318- private static ImmutableMap <String , ImmutableMap < String , String > > parseExecProperties (
1314+ private static ImmutableTable <String , String , String > parseExecProperties (
13191315 Map <String , String > rawExecProperties , @ Nullable Set <String > execGroups )
13201316 throws InvalidExecGroupException {
1321- Map <String , Map <String , String >> consolidatedProperties = parseExecGroups (rawExecProperties );
1317+ ImmutableTable <String , String , String > consolidatedProperties =
1318+ parseExecGroups (rawExecProperties );
13221319 if (execGroups != null ) {
1323- for (Map .Entry <String , Map <String , String >> execGroup : consolidatedProperties .entrySet ()) {
1324- String execGroupName = execGroup .getKey ();
1320+ for (String execGroupName : consolidatedProperties .rowKeySet ()) {
13251321 if (!execGroupName .equals (DEFAULT_EXEC_GROUP_NAME ) && !execGroups .contains (execGroupName )) {
13261322 throw new InvalidExecGroupException (
13271323 String .format (
@@ -1330,14 +1326,7 @@ private static ImmutableMap<String, ImmutableMap<String, String>> parseExecPrope
13301326 }
13311327 }
13321328
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 ();
1329+ return consolidatedProperties ;
13411330 }
13421331
13431332 /**
@@ -1349,16 +1338,16 @@ private static ImmutableMap<String, ImmutableMap<String, String>> parseExecPrope
13491338 * @param execProperties Map of exec group name to map of properties and values
13501339 */
13511340 private static ImmutableMap <String , String > getExecProperties (
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 );
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 );
13551344 }
13561345
13571346 // Use a HashMap to build here because we expect duplicate keys to happen
13581347 // (and rewrite previous entries).
13591348 Map <String , String > targetAndGroupProperties =
1360- new HashMap <>(execProperties .get (DEFAULT_EXEC_GROUP_NAME ));
1361- targetAndGroupProperties .putAll (execProperties .get (execGroup ));
1349+ new HashMap <>(execProperties .row (DEFAULT_EXEC_GROUP_NAME ));
1350+ targetAndGroupProperties .putAll (execProperties .row (execGroup ));
13621351 return ImmutableMap .copyOf (targetAndGroupProperties );
13631352 }
13641353
@@ -1379,11 +1368,6 @@ public DetailedExitCode getDetailedExitCode() {
13791368 }
13801369 }
13811370
1382- @ VisibleForTesting
1383- public ImmutableMap <String , ImmutableMap <String , String >> getExecPropertiesForTesting () {
1384- return execProperties ;
1385- }
1386-
13871371 private void checkAttributeIsDependency (String attributeName ) {
13881372 Attribute attributeDefinition = attributes .getAttributeDefinition (attributeName );
13891373 if (attributeDefinition == null ) {
0 commit comments