@@ -99,7 +99,8 @@ static ImmutableMap<String, BuildOptions> applyAndValidate(
99
99
}
100
100
101
101
for (Map .Entry <String , Map <String , Object >> entry : transitions .entrySet ()) {
102
- Map <String , Object > newValues = handleImplicitPlatformChange (entry .getValue ());
102
+ Map <String , Object > newValues =
103
+ handleImplicitPlatformChange (buildOptions , entry .getValue ());
103
104
BuildOptions transitionedOptions =
104
105
applyTransition (buildOptions , newValues , optionInfoMap , starlarkTransition );
105
106
splitBuildOptions .put (entry .getKey (), transitionedOptions );
@@ -127,21 +128,22 @@ static ImmutableMap<String, BuildOptions> applyAndValidate(
127
128
* <p>Transitions can also explicitly set --platforms to be clear what platform they set.
128
129
*
129
130
* <p>Platform mappings: https://bazel.build/concepts/platforms-intro#platform-mappings.
130
- *
131
- * <p>This doesn't check that the changed value is actually different than the source (i.e.
132
- * setting {@code --cpu=foo} when {@code --cpu} is already {@code foo}). That could unnecessarily
133
- * fork configurations that are really the same. That's a possible optimization TODO.
134
131
*/
135
132
private static Map <String , Object > handleImplicitPlatformChange (
136
- Map <String , Object > originalOutput ) {
137
- boolean changesCpu = originalOutput .containsKey (COMMAND_LINE_OPTION_PREFIX + "cpu" );
138
- boolean changesPlatforms = originalOutput .containsKey (COMMAND_LINE_OPTION_PREFIX + "platforms" );
139
- return changesCpu && !changesPlatforms
140
- ? ImmutableMap .<String , Object >builder ()
141
- .putAll (originalOutput )
142
- .put (COMMAND_LINE_OPTION_PREFIX + "platforms" , ImmutableList .<Label >of ())
143
- .build ()
144
- : originalOutput ;
133
+ BuildOptions options , Map <String , Object > rawTransitionOutput ) {
134
+ Object newCpu = rawTransitionOutput .get (COMMAND_LINE_OPTION_PREFIX + "cpu" );
135
+ if (newCpu == null || newCpu .equals (options .get (CoreOptions .class ).cpu )) {
136
+ // No effective change to --cpu, so no need to prevent the platform mapping from resetting it.
137
+ return rawTransitionOutput ;
138
+ }
139
+ if (rawTransitionOutput .containsKey (COMMAND_LINE_OPTION_PREFIX + "platforms" )) {
140
+ // Explicitly setting --platforms overrides the implicit clearing.
141
+ return rawTransitionOutput ;
142
+ }
143
+ return ImmutableMap .<String , Object >builder ()
144
+ .putAll (rawTransitionOutput )
145
+ .put (COMMAND_LINE_OPTION_PREFIX + "platforms" , ImmutableList .<Label >of ())
146
+ .build ();
145
147
}
146
148
147
149
private static void checkForDenylistedOptions (StarlarkDefinedConfigTransition transition )
0 commit comments