Skip to content

Commit e52a87f

Browse files
committed
Fix potential bug with transitions
1 parent c8b6b7d commit e52a87f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

rules/register_toolchain.bzl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,29 @@ register_zinc_toolchain = _make_register_toolchain(_zinc_configuration)
215215
def _scala_incoming_transition_impl(settings, attr):
216216
result = dict(settings)
217217

218-
if attr.scala_toolchain_name != "":
218+
if attr.scala_toolchain_name != "" and attr.scala_toolchain_name != settings[scala_toolchain_setting]:
219219
# We set `original_scala_toolchain_setting` so we can reset the toolchain to its
220220
# original value in `scala_outgoing_transition`. That way, we can ensure every target is
221221
# built under a single toolchain, thus preventing duplicate builds.
222222
#
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+
#
223235
# This is inspired by what the rules_go folks are doing.
224236
result[original_scala_toolchain_setting] = settings[scala_toolchain_setting]
225237
result[scala_toolchain_setting] = attr.scala_toolchain_name
226238

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]):
228241
result[original_scalafmt_toolchain_setting] = settings[scalafmt_toolchain_setting]
229242
result[scalafmt_toolchain_setting] = attr.scalafmt_toolchain_name
230243

0 commit comments

Comments
 (0)