|
7 | 7 | load("//third_party/repositories:repositories.bzl", "repositories") |
8 | 8 | load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS") |
9 | 9 |
|
10 | | -def scalafmt_default_config(path = ".scalafmt.conf"): |
| 10 | +def _scalafmt_config_impl(repository_ctx): |
| 11 | + config_path = repository_ctx.attr.path |
11 | 12 | build = [] |
12 | 13 | build.append("filegroup(") |
13 | 14 | build.append(" name = \"config\",") |
14 | | - build.append(" srcs = [\"{}\"],".format(path)) |
| 15 | + build.append(" srcs = [\"{}\"],".format(config_path.name)) |
15 | 16 | build.append(" visibility = [\"//visibility:public\"],") |
16 | | - build.append(")") |
17 | | - native.new_local_repository(name = "scalafmt_default", build_file_content = "\n".join(build), path = "") |
| 17 | + build.append(")\n") |
| 18 | + |
| 19 | + repository_ctx.file("BUILD", "\n".join(build), executable = False) |
| 20 | + repository_ctx.symlink(repository_ctx.path(config_path), config_path.name) |
| 21 | + |
| 22 | +scalafmt_config = repository_rule( |
| 23 | + implementation = _scalafmt_config_impl, |
| 24 | + attrs = { |
| 25 | + "path": attr.label(mandatory = True, allow_single_file = True), |
| 26 | + }, |
| 27 | +) |
| 28 | + |
| 29 | +def scalafmt_default_config(path = ".scalafmt.conf", **kwargs): |
| 30 | + scalafmt_config(name = "scalafmt_default", path = "//:" + path, **kwargs) |
18 | 31 |
|
19 | 32 | _SCALAFMT_DEPS = [ |
20 | 33 | "org_scalameta_common", |
@@ -60,6 +73,7 @@ def scalafmt_repositories( |
60 | 73 |
|
61 | 74 | def _register_scalafmt_toolchains(): |
62 | 75 | for scala_version in SCALA_VERSIONS: |
63 | | - native.register_toolchains( |
64 | | - "@io_bazel_rules_scala//scala/scalafmt:scalafmt_toolchain" + version_suffix(scala_version), |
65 | | - ) |
| 76 | + native.register_toolchains(str(Label( |
| 77 | + "//scala/scalafmt:scalafmt_toolchain" + |
| 78 | + version_suffix(scala_version), |
| 79 | + ))) |
0 commit comments