Skip to content

Commit 823b3ce

Browse files
committed
WIP: Bzlmod part the one hundred twenty-first
Resolves the duplicate repo instantiation errors from the previous merge commit. They all had to do with repos that twitter_scrooge and scalafmt have in commmon with scala_proto. Given that, passing the `scala_proto` boolean parameter of `scala_toolchains` into the `twitter_scrooge` and `scalafmt_repositories` functions seemed the easiest workaround for now. I picked up the `**kwargs` + `kwargs.pop()` pattern up from: - bazel-contrib/rules_python#2289 It seems to be a pattern for passing through hidden, purely internal parameters, not to be relied upon by any external users.
1 parent 0a18873 commit 823b3ce

File tree

8 files changed

+5003
-2884
lines changed

8 files changed

+5003
-2884
lines changed

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ dev_deps.toolchains(
8888

8989
use_repo(
9090
dev_deps,
91-
"scala_proto_rules_protoc_bridge",
92-
"scala_proto_rules_scalapb_plugin",
91+
"scala_proto_rules_scalapb_compilerplugin",
92+
"scala_proto_rules_scalapb_protoc_bridge",
9393
"scalafmt_default",
9494
)
9595

MODULE.bazel.lock

Lines changed: 4956 additions & 2845 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dt_patches/test_dt_patches/extensions.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ UNVERSIONED_ARTIFACTS = {
2727
"sbt_compiler_interface": "org.scala-sbt:compiler-interface:1.9.6",
2828
}
2929

30+
IS_SCALA_2 = SCALA_VERSION.startswith("2.")
31+
3032
def import_compiler_source_repos():
3133
versioned_artifact_templates = (
32-
SCALA_2_ARTIFACTS
33-
if SCALA_VERSION.startswith("2.")
34-
else SCALA_3_ARTIFACTS
35-
}
34+
SCALA_2_ARTIFACTS if IS_SCALA_2 else SCALA_3_ARTIFACTS
35+
)
3636
versioned_artifacts = {
37-
k: v % SCALA_VERSION for k, v in versioned_artifact_templates
37+
k: v % SCALA_VERSION
38+
for k, v in versioned_artifact_templates
3839
}
3940

4041
for name, artifact in versioned_artifacts | UNVERSIONED_ARTIFACTS:

dt_patches/test_dt_patches_user_srcjar/extensions.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ UNVERSIONED_ARTIFACTS = {
2828
"sbt_compiler_interface": "org.scala-sbt:compiler-interface:1.9.6",
2929
}
3030

31+
IS_SCALA_2 = SCALA_VERSION.startswith("2.")
32+
3133
def import_compiler_source_repos():
3234
http_jar(
3335
name = "scala_compiler_srcjar",
@@ -42,12 +44,11 @@ def import_compiler_source_repos():
4244
)
4345

4446
versioned_artifact_templates = (
45-
SCALA_2_ARTIFACTS
46-
if SCALA_VERSION.startswith("2.")
47-
else SCALA_3_ARTIFACTS
48-
}
47+
SCALA_2_ARTIFACTS if IS_SCALA_2 else SCALA_3_ARTIFACTS
48+
)
4949
versioned_artifacts = {
50-
k: v % SCALA_VERSION for k, v in versioned_artifact_templates
50+
k: v % SCALA_VERSION
51+
for k, v in versioned_artifact_templates
5152
}
5253

5354
for name, artifact in versioned_artifacts | UNVERSIONED_ARTIFACTS:

scala/private/macros/toolchains.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def scala_toolchains(
141141
maven_servers = maven_servers,
142142
overriden_artifacts = overridden_artifacts,
143143
bzlmod_enabled = True,
144+
_scala_proto_instantiated = scala_proto,
144145
)
145146
if jmh:
146147
jmh_repositories(
@@ -154,6 +155,7 @@ def scala_toolchains(
154155
maven_servers = maven_servers,
155156
overriden_artifacts = overridden_artifacts,
156157
bzlmod_enabled = True,
158+
_scala_proto_instantiated = scala_proto,
157159
)
158160

159161
scala_toolchains_repo(

scala/scalafmt/scalafmt_repositories.bzl

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ def scalafmt_default_config(path = ".scalafmt.conf", **kwargs):
3232
_SCALAFMT_DEPS = [
3333
"com_geirsson_metaconfig_core",
3434
"com_geirsson_metaconfig_typesafe_config",
35-
"com_google_protobuf_protobuf_java",
3635
"com_lihaoyi_fansi",
37-
"com_lihaoyi_fastparse",
38-
"com_lihaoyi_sourcecode",
3936
"com_typesafe_config",
40-
"org_scala_lang_modules_scala_collection_compat",
4137
"org_scala_lang_scalap",
4238
"org_scalameta_common",
4339
"org_scalameta_parsers",
4440
"org_scalameta_scalafmt_core",
4541
"org_scalameta_scalameta",
4642
"org_scalameta_trees",
4743
"org_typelevel_paiges_core",
44+
]
45+
46+
_SCALAFMT_PROTO_DEPS = [
47+
"com_google_protobuf_protobuf_java",
48+
"com_lihaoyi_fastparse",
49+
"com_lihaoyi_sourcecode",
50+
"org_scala_lang_modules_scala_collection_compat",
4851
"scala_proto_rules_scalapb_lenses",
4952
"scala_proto_rules_scalapb_runtime",
5053
]
@@ -62,11 +65,13 @@ _SCALAFMT_DEPS_2_12 = [
6265
"org_scalameta_scalafmt_sysops",
6366
]
6467

65-
def scalafmt_artifact_ids(scala_version):
68+
def scalafmt_artifact_ids(scala_version, scala_proto_instantiated = False):
6669
major_version = extract_major_version(scala_version)
6770

71+
proto_deps = [] if scala_proto_instantiated else _SCALAFMT_PROTO_DEPS
72+
6873
if major_version == "2.11":
69-
return _SCALAFMT_DEPS + _SCALAFMT_DEPS_2_11
74+
return _SCALAFMT_DEPS + _SCALAFMT_DEPS_2_11 + proto_deps
7075

7176
extra_deps = []
7277

@@ -75,16 +80,21 @@ def scalafmt_artifact_ids(scala_version):
7580
else:
7681
extra_deps.append("io_bazel_rules_scala_scala_parallel_collections")
7782

78-
return _SCALAFMT_DEPS + _SCALAFMT_DEPS_2_12 + extra_deps
83+
return _SCALAFMT_DEPS + _SCALAFMT_DEPS_2_12 + extra_deps + proto_deps
7984

8085
def scalafmt_repositories(
8186
maven_servers = _default_maven_server_urls(),
8287
overriden_artifacts = {},
83-
bzlmod_enabled = False):
88+
bzlmod_enabled = False,
89+
**kwargs):
90+
scala_proto_instantiated = kwargs.pop("_scala_proto_instantiated", False)
8491
for scala_version in SCALA_VERSIONS:
8592
repositories(
8693
scala_version = scala_version,
87-
for_artifact_ids = scalafmt_artifact_ids(scala_version),
94+
for_artifact_ids = scalafmt_artifact_ids(
95+
scala_version,
96+
scala_proto_instantiated,
97+
),
8898
maven_servers = maven_servers,
8999
overriden_artifacts = overriden_artifacts,
90100
)

scala_proto/BUILD

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
load("//scala:providers.bzl", "declare_deps_provider")
2-
load(
3-
"//scala_proto/default:default_deps.bzl",
4-
"DEFAULT_SCALAPB_COMPILE_DEPS",
5-
"DEFAULT_SCALAPB_GRPC_DEPS",
6-
"DEFAULT_SCALAPB_WORKER_DEPS",
7-
)
81
load("//scala_proto/private:toolchain_deps.bzl", "export_scalapb_toolchain_deps")
9-
load(
10-
"//scala_proto/private:toolchain_deps.bzl",
11-
"export_scalapb_toolchain_deps",
12-
)
132

143
toolchain_type(
154
name = "toolchain_type",

twitter_scrooge/twitter_scrooge.bzl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def twitter_scrooge(
5252
scrooge_generator = None,
5353
util_core = None,
5454
util_logging = None,
55-
bzlmod_enabled = False):
55+
bzlmod_enabled = False,
56+
**kwargs):
5657
_declare_and_bind(
5758
libthrift,
5859
"libthrift",
@@ -93,14 +94,18 @@ def twitter_scrooge(
9394
maven_servers,
9495
)
9596

97+
artifact_ids = [
98+
"io_bazel_rules_scala_mustache", # Mustache is needed to generate java from thrift, and is passed further down.
99+
"io_bazel_rules_scala_javax_annotation_api",
100+
"io_bazel_rules_scala_scopt",
101+
]
102+
103+
if not kwargs.pop("_scala_proto_instantiated", False):
104+
artifact_ids.append("io_bazel_rules_scala_guava")
105+
96106
repositories(
97107
scala_version = SCALA_VERSION,
98-
for_artifact_ids = [
99-
"io_bazel_rules_scala_guava",
100-
"io_bazel_rules_scala_mustache", # Mustache is needed to generate java from thrift, and is passed further down.
101-
"io_bazel_rules_scala_javax_annotation_api",
102-
"io_bazel_rules_scala_scopt",
103-
],
108+
for_artifact_ids = artifact_ids,
104109
maven_servers = maven_servers,
105110
fetch_sources = False,
106111
overriden_artifacts = overriden_artifacts,

0 commit comments

Comments
 (0)