Closed mbland closed 3 weeks ago
If you've used the scripts/create_repositories.py
to update dependencies then scalameta_version defined there should also be updated.
Also, I can see Scala version updates. Consider merging #1636 before so we can separate these two upgrades.
@WojciechMazur I didn't use scripts/create_repositories.py
, actually—I didn't see that land in #1607 until after I'd tweaked these files by hand. I'm a little scared to try it on the Scalafmt deps, because as mentioned in the description, I locked it to Scalameta 4.9.9 because 4.10.x breaks Scala 3 formatting, and I don't know exactly why. (If you have a tip, or a workaround, I'm all ears.)
That said, I'll checkout a new branch and give it a try, see what happens. I'm also going to prepare another local test branch rebased on #1636 to have it ready. It does seem like it'd be easier to land #1636, then this one.
Wow, rebasing on #1636 worked perfectly, with all tests passing, as well as bazel test --repo_env=SCALA_VERSION=2.13.15 //test/scalafmt/...
. I do need to bump the Scala 2 libs in the scala_3_{1,2,3,4,5}.bzl
files to 2.13.15 (they're still 2.13.14 right now), but that's a piece of cake.
Since the rebase was so easy, I definitely think #1636 should go in first.
I've created a new mbland/rules_scala/bzlmod-update-scalafmt-deps-after-scala-versions-update branch with commits representing:
WojciechMazur/update/scala-versions
scripts/create_repository.py
after bumping it to Scalatest 3.2.19 and Scalafmt 3.8.3The commit for the successful create_repository.py
run passed the Scalafmt tests from ./test_cross_version.sh
. The unsuccessful run crashed with the error described in #1624 before the protobuf-java 4.28.2 update.
So I'll be happy to rebase this PR after #1636 lands, and cherry-pick the second and third commits above into it. But I don't yet know what to suggest regarding the downgrades from the last commit.
Hi, @mbland, just want to let you know that https://github.com/bazelbuild/rules_scala/pull/1636 was merged.
@simuons Thanks! Just rebased, ran some of the tests, and pushed.
I'll send the successful updates from running scripts/create_repository.py that I mentioned earlier in a separate PR after this one lands.
@simuons Thanks for the approval on this and #1632, but neither have merged yet. Pinging in case that wasn't intentional.
Thanks, @liucijus!
Description
Ensures that all Scalafmt targets succeed under every supported Scala version. Part of #1482.
Scala 2.11 remains on Scalafmt 2.7.5, since there's not a more recent compatible version.
Between 3.0.0 and 3.8.3, Scalafmt's
FileOps
moved packages,Config.fromHoconFile
moved toScalafmtConfig
, and the methods now take ajava.nio.file.Path
parameter. As a result, this required extracting a thinScalafmtAdapter
object, with one implementation for Scala 2.11 and Scalafmt 2.7.5, and one for Scalafmt 3.8.3.This change also adds the file path to the
Scalafmt.format()
call, allowing error messages to show the actual file path instead of<input>
.Removed the
verticalMultiline.newlineBeforeImplicitKW = true
andunindentTopLevelOperators = false
options from.scalafmt.conf
. They don't appear to be available in Scalafmt 3.8.3.Also removes some
@io_bazel_rules_scala
references to make the internal implementation less dependendent on that name. This will allow Bzlmod clients to userules_scala
in abazel_dep()
without settingrepo_name = "io_bazel_rules_scala"
.Motivation
Scalafmt 3.0.0 works with the current default Scala version 2.12.19, but breaks under Scala 2.13.14:
This matches:
Which mentions apparent fixes in:
So the fix was to upgrade the Scalafmt version. That said, I held its Scalameta dependencies to 4.9.9 per the following link, even though 4.10.2 is out now.
This change updates Scalameta to version 4.9.9 because between 4.9.9 and 4.10.2, Scalafmt breaks Scala 3 file formatting by unindenting some code that it shouldn't. Or, our usage of it breaks somehow; I can't find any open or closed issues in the Scalameta project that matches what happes in rules_scala. (Perhaps I can file one eventually.)
The solution was to keep the Scalameta dependencies at 4.9.9. FWIW, this was one of the most time consuming bugs to pinpoint and rectify in the entire Bzlmodification process.
This was the failing command inside
test_cross_version
:The
test_cross_version/scalafmt/unformatted/unformatted-test3.scala
file formatted by this test target looks like this:I hacked
ScalaWorker.format()
to print thecode
variable, and could see that after the firstScalafmt.format()
pass, the code looks like this:Since the result doesn't match the original code, it tries to call
Scalafmt.format()
again on this "formatted" code with the incorrect indentation. That's when we get the following, which doesn't look anything like the original file:As it turns out, bumping to com.google.protobuf:protobuf-java:4.28.2 alone (#1624) breaks the bump to Scalafmt 3.8.3. Then bumping to rules_proto 6.0.2, with the separate protobuf v21.7 (#1623), fixes it, presumably by recompiling
protoc
.The in-between breakage happened in the
test_cross_build
project: