bazelbuild / rules_scala

Scala rules for Bazel
Apache License 2.0
363 stars 278 forks source link

Refactor `scripts/create_repository.py`, improve efficiency and correctness, and bump Scalatest, protobuf-java, kind-projector #1642

Closed mbland closed 1 week ago

mbland commented 2 weeks ago

Description

Refactors scripts/create_repository.py to make more modular, robust, and efficient, and update Scalatest, protobuf-java, and kind-projector jars. Part of #1482.

There are a lot of changes from individual commits in this one large PR, since @simuons said it wasn't necessary to break up #1639, another large PR to refactor scripts/create_repository.py, and all tests continue to pass. That said, I'm always more than happy to break this one apart if it really is too much.

The highlights are:

Perhaps most significantly, this cuts the number of Coursier commands and artifact downloads significantly, leading to a very large performance improvement. Here are the times for creating a fresh output dir and then updating it before this change (all with a warm Coursier download cache):

$ /usr/bin/time ./scripts/create_repository.py --output_dir before

[ ...snip... ]
       66.01 real        13.25 user         9.99 sys

$ /usr/bin/time ./scripts/create_repository.py --output_dir before

[ ...snip... ]
        1.76 real         1.41 user         0.49 sys

Here are the times after:

$ /usr/bin/time ./scripts/create_repository.py --output_dir after

[ ...snip... ]
        1.16 real         0.84 user         0.39 sys

$ /usr/bin/time ./scripts/create_repository.py --output_dir after

[ ...snip... ]
        0.96 real         0.72 user         0.27 sys

Motivation

Overall, this script is making my further work to update dependencies to ease the Bzlmod migration in #1482 so much faster, easier, and safer. But I found ways to improve it further, after #1639, to make the script itself more maintainable, more correct and robust, and much faster.

I'm now using it to bump ScalaPB, protoc-bridge, gRPC, guava, etc. dependencies, and resolving any breakages, in an effort to make rules_scala able to use newer versions of the Protobuf library. Though independent from (and not strictly required by) the Bzlmod migration work, this may be especially important to future Bzlmod users that include later Protobuf versions in their dependencies.

The script is now in a state where I really trust it to do the right thing as I continue this work. This makes this complex upgrade work far more tractable than before.