Skip to content

Commit f76941f

Browse files
committed
Fix potential bug with transitions
1 parent f1b8171 commit f76941f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

rules/register_toolchain.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,25 @@ 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+
#
223231
# This is inspired by what the rules_go folks are doing.
224232
result[original_scala_toolchain_setting] = settings[scala_toolchain_setting]
225233
result[scala_toolchain_setting] = attr.scala_toolchain_name
226234

227-
if hasattr(attr, "scalafmt_toolchain_name") and attr.scalafmt_toolchain_name != "":
235+
if (hasattr(attr, "scalafmt_toolchain_name") and attr.scalafmt_toolchain_name != "" and
236+
attr.scalafmt_toolchain_name != settings[scalafmt_toolchain_setting]):
228237
result[original_scalafmt_toolchain_setting] = settings[scalafmt_toolchain_setting]
229238
result[scalafmt_toolchain_setting] = attr.scalafmt_toolchain_name
230239

0 commit comments

Comments
 (0)