Commit fa7c661
authored
Use custom repo rule to generate @scalafmt_default (bazel-contrib#1626)
* Use custom repo rule to generate @scalafmt_default
Part of bazel-contrib#1482.
Replaces `native.new_local_repository` in `scalafmt_default_config` with
the new `scalafmt_config` repo rule. Resolves an incompatibility between
Bazel 6.5.0 and 7.3.2, while creating a much smaller `@scalafmt_default`
repo. Also updates the `native.register_toolchains` call with a
stringified `Label` to remove the hardcoding of `@io_bazel_rules_scala`.
The problem is that under Bazel 7.3.2, calling `scalafmt_default_config`
from a module extension produces this error:
```txt
$ bazel test //test/scalafmt/...
ERROR: Traceback (most recent call last):
File ".../scala/extensions/deps.bzl",
line 218, column 32, in _scala_deps_impl
scalafmt_default_config()
File ".../scala/scalafmt/scalafmt_repositories.bzl",
line 18, column 32, in scalafmt_default_config
native.new_local_repository(
Error in new_local_repository: The native module can be accessed only
from a BUILD thread. Wrap the function in a macro and call it from a
BUILD file
```
Ostensibly the solution is to replace `native.new_local_repository`
with:
```py
load(
"@bazel_tools//tools/build_defs/repo:local.bzl",
"new_local_repository",
)
```
However, `local.bzl` isn't available in Bazel 6.5.0:
```txt
$ bazel test //test/scalafmt/...
ERROR: Error computing the main repository mapping:
at .../scala/scalafmt/scalafmt_repositories.bzl:8:6:
cannot load '@bazel_tools//tools/build_defs/repo:local.bzl':
no such file
```
The new `scalafmt_config` repository rule works under both Bazel 6.5.0
and 7.3.2. Also, it symlinks only the single Scalafmt config file,
instead of every top level file and directory in the project, as
`new_local_repository` did.
* Fix scalafmt_repositories.bzl lint errors
Broke CI again. D'oh!1 parent 68e9987 commit fa7c661
1 file changed
+21
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | | - | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
18 | 31 | | |
19 | 32 | | |
20 | 33 | | |
| |||
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
63 | | - | |
64 | | - | |
65 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
0 commit comments