@@ -215,16 +215,29 @@ register_zinc_toolchain = _make_register_toolchain(_zinc_configuration)
215
215
def _scala_incoming_transition_impl (settings , attr ):
216
216
result = dict (settings )
217
217
218
- if attr .scala_toolchain_name != "" :
218
+ if attr .scala_toolchain_name != "" and attr . scala_toolchain_name != settings [ scala_toolchain_setting ] :
219
219
# We set `original_scala_toolchain_setting` so we can reset the toolchain to its
220
220
# original value in `scala_outgoing_transition`. That way, we can ensure every target is
221
221
# built under a single toolchain, thus preventing duplicate builds.
222
222
#
223
+ # We do not do this work when the toolchain name is set, but is no different than what is
224
+ # already set. By having that check we avoid the failure mode where the original toolchain
225
+ # name gets set equal to the current toolchain name and destroys whatever the actual original
226
+ # toolchain name was. For example
227
+ # State 1: State 2: State 3:
228
+ # Setting: A => Setting: B => Setting: B => Game over
229
+ # Original: Unset Original: A Original: B
230
+ #
231
+ # Note that the check described above should ideally not be required due to outgoing
232
+ # transitions but it is, so something is going wrong. As a result, the check is probably
233
+ # temporary, but who knows.
234
+ #
223
235
# This is inspired by what the rules_go folks are doing.
224
236
result [original_scala_toolchain_setting ] = settings [scala_toolchain_setting ]
225
237
result [scala_toolchain_setting ] = attr .scala_toolchain_name
226
238
227
- if hasattr (attr , "scalafmt_toolchain_name" ) and attr .scalafmt_toolchain_name != "" :
239
+ if (hasattr (attr , "scalafmt_toolchain_name" ) and attr .scalafmt_toolchain_name != "" and
240
+ attr .scalafmt_toolchain_name != settings [scalafmt_toolchain_setting ]):
228
241
result [original_scalafmt_toolchain_setting ] = settings [scalafmt_toolchain_setting ]
229
242
result [scalafmt_toolchain_setting ] = attr .scalafmt_toolchain_name
230
243
0 commit comments