Skip to content

Commit 3368a6f

Browse files
committed
Extract dev_deps_repositories() from WORKSPACE
`dev_deps_repositories()` encapsulates the instantiation of repositories used only for `rules_scala` development. Also removes the unused `//private` package and its `WORKSPACE` statements. Part of bazel-contrib#1482. Both `WORKSPACE` and Bzlmod builds can use this macro, though how Bzlmod will use it will depend on whether we continue building with Bazel 6. `@bazel_tools//tools/build_defs/repo:local.bzl` isn't available under Bazel 6. To continue building with Bazel 6 under Bzlmod, we will need to call `dev_deps_repositories()` from `WORKSPACE.bzlmod` to continue using `native.{,new_}local_repository()`. If we switch to Bazel 7, we can load `local.bzl` and strip the `native.` prefix from the `{,new_}local_repository()` calls. Then we can call `dev_deps_repositories()` from a module extension instead of from `WORKSPACE.bzlmod`. Another alternative would be updating the local repositories to become proper nested repositories. Then we can call `local_repository()` from `WORKSPACE` and call `bazel_dep()` and `local_path_override()` from `MODULE.bazel`. In that case, we'd remove the `{,new_}local_repository` calls from `dev_deps_dependencies()`, and remove `proto_cross_repo_boundary_repository()` entirely.
1 parent bfcc6bb commit 3368a6f

File tree

5 files changed

+141
-172
lines changed

5 files changed

+141
-172
lines changed

WORKSPACE

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories")
2626

2727
py_repositories()
2828

29-
_build_tools_release = "5.1.0"
30-
31-
http_archive(
32-
name = "com_github_bazelbuild_buildtools",
33-
sha256 = "e3bb0dc8b0274ea1aca75f1f8c0c835adbe589708ea89bf698069d0790701ea3",
34-
strip_prefix = "buildtools-%s" % _build_tools_release,
35-
url = "https://github.com/bazelbuild/buildtools/archive/%s.tar.gz" % _build_tools_release,
36-
)
37-
3829
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
3930

4031
scala_config(enable_compiler_dependency_tracking = True)
@@ -74,7 +65,6 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
7465

7566
protobuf_deps()
7667

77-
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
7868
load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge")
7969

8070
twitter_scrooge()
@@ -101,53 +91,6 @@ scalafmt_default_config()
10191

10292
scalafmt_repositories()
10393

104-
MAVEN_SERVER_URLS = default_maven_server_urls()
105-
106-
# needed for the cross repo proto test
107-
load("//test/proto_cross_repo_boundary:repo.bzl", "proto_cross_repo_boundary_repository")
108-
109-
proto_cross_repo_boundary_repository()
110-
111-
new_local_repository(
112-
name = "test_new_local_repo",
113-
build_file_content =
114-
"""
115-
filegroup(
116-
name = "data",
117-
srcs = glob(["**/*.txt"]),
118-
visibility = ["//visibility:public"],
119-
)
120-
""",
121-
path = "third_party/test/new_local_repo",
122-
)
123-
124-
local_repository(
125-
name = "example_external_workspace",
126-
path = "third_party/test/example_external_workspace",
127-
)
128-
129-
load("//scala:scala_maven_import_external.bzl", "java_import_external")
130-
131-
# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external
132-
# in order to allow for other jvm-language imports (e.g. scala_import)
133-
# the 3rd-party dependency below is using the java_import_external macro
134-
# in order to make sure no regression with the original java_import_external
135-
java_import_external(
136-
name = "org_apache_commons_commons_lang_3_5_without_file",
137-
generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file",
138-
jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c",
139-
jar_urls = ["https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
140-
licenses = ["notice"], # Apache 2.0
141-
neverlink = True,
142-
testonly_ = True,
143-
)
144-
145-
## Linting
146-
147-
load("//private:format.bzl", "format_repositories")
148-
149-
format_repositories()
150-
15194
http_archive(
15295
name = "io_bazel_rules_go",
15396
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
@@ -167,12 +110,6 @@ go_rules_dependencies()
167110

168111
go_register_toolchains(version = "1.19.5")
169112

170-
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
171-
172-
# We need to select based on platform when we use these
173-
# https://github.com/bazelbuild/bazel/issues/11655
174-
remote_jdk8_repos()
175-
176113
http_archive(
177114
name = "bazelci_rules",
178115
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
@@ -187,35 +124,20 @@ rbe_preconfig(
187124
toolchain = "ubuntu2004-bazel-java11",
188125
)
189126

190-
load("//third_party/repositories:repositories.bzl", "repositories")
191-
192-
repositories(
193-
fetch_sources = False,
194-
for_artifact_ids = [
195-
# test adding a scala jar:
196-
"com_twitter__scalding_date",
197-
# test of strict deps (scalac plugin UT + E2E)
198-
"com_google_guava_guava_21_0_with_file",
199-
"com_github_jnr_jffi_native",
200-
"org_apache_commons_commons_lang_3_5",
201-
"com_google_guava_guava_21_0",
202-
# test of import external
203-
# scala maven import external decodes maven artifacts to its parts
204-
# (group id, artifact id, packaging, version and classifier). To make sure
205-
# the decoding and then the download url composition are working the artifact example
206-
# must contain all the different parts and sha256s so the downloaded content will be
207-
# validated against it
208-
"org_springframework_spring_core",
209-
"org_springframework_spring_tx",
210-
"org_typelevel_kind_projector",
211-
# For testing that we don't include sources jars to the classpath
212-
"org_typelevel__cats_core",
213-
],
214-
maven_servers = MAVEN_SERVER_URLS,
215-
)
127+
load("//scala/private/extensions:dev_deps.bzl", "dev_deps_repositories")
216128

217-
load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories", "remote_jdk21_toolchains")
129+
dev_deps_repositories()
218130

219-
remote_jdk21_repositories()
131+
# Copied from bazel_tools/tools/jdk/remote_java_repository.bzl.
132+
[
133+
register_toolchains(
134+
"@remotejdk21_" + platform + "_toolchain_config_repo//:all",
135+
)
136+
for platform in [
137+
"linux",
138+
"macos",
139+
"win",
140+
]
141+
]
220142

221-
remote_jdk21_toolchains()
143+
register_toolchains("//test/toolchains:java21_toolchain_definition")

private/BUILD

Lines changed: 0 additions & 7 deletions
This file was deleted.

private/format.bzl

Lines changed: 0 additions & 71 deletions
This file was deleted.

scala/private/extensions/dev_deps.bzl

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""Repositories for testing rules_scala itself"""
2+
3+
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
4+
load("//scala:scala_maven_import_external.bzl", "java_import_external")
5+
load(
6+
"//test/proto_cross_repo_boundary:repo.bzl",
7+
"proto_cross_repo_boundary_repository",
8+
)
9+
load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories")
10+
load("//third_party/repositories:repositories.bzl", "repositories")
11+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
12+
13+
# Once we switch to Bazel 7, uncomment this `load` statement remove the
14+
# `native.` prefix from `local_repository` and `new_local_repository`.
15+
# Update //test/proto_cross_repo_boundary:repo.bzl in the same way.
16+
#load(
17+
# "@bazel_tools//tools/build_defs/repo:local.bzl",
18+
# "local_repository",
19+
# "new_local_repository",
20+
#)
21+
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
22+
23+
_BUILD_TOOLS_RELEASE = "5.1.0"
24+
25+
def dev_deps_repositories(
26+
name = "unused_dev_deps_name",
27+
maven_servers = default_maven_server_urls(),
28+
fetch_sources = False):
29+
"""Instantiates internal only repos for development and testing
30+
31+
Once we're using Bazel 7, uncomment the `load()` statement for `local.bzl`
32+
in this file and remove `native.` from the `native.{,new_}local_repository`
33+
calls.
34+
35+
Until then, `dev_deps_repositories()` must be called from `WORKSPACE` or
36+
`WORKSPACE.bzlmod`, as module extensions won't be able to use it.
37+
38+
Args:
39+
name: unused macro parameter to satisfy Buildifier lint rules
40+
maven_servers: servers to use when resolving Maven artifacts
41+
fetch_sources: retrieve Maven artifact sources when True
42+
"""
43+
http_archive(
44+
name = "com_github_bazelbuild_buildtools",
45+
sha256 = "e3bb0dc8b0274ea1aca75f1f8c0c835adbe589708ea89bf698069d0790701ea3",
46+
strip_prefix = "buildtools-%s" % _BUILD_TOOLS_RELEASE,
47+
url = (
48+
"https://github.com/bazelbuild/buildtools/archive/%s.tar.gz" %
49+
_BUILD_TOOLS_RELEASE
50+
),
51+
)
52+
53+
# needed for the cross repo proto test
54+
proto_cross_repo_boundary_repository()
55+
56+
native.local_repository(
57+
name = "example_external_workspace",
58+
path = "third_party/test/example_external_workspace",
59+
)
60+
61+
native.new_local_repository(
62+
name = "test_new_local_repo",
63+
build_file_content = """
64+
filegroup(
65+
name = "data",
66+
srcs = glob(["**/*.txt"]),
67+
visibility = ["//visibility:public"],
68+
)
69+
""",
70+
path = "third_party/test/new_local_repo",
71+
)
72+
73+
# bazel's java_import_external has been altered in rules_scala to be a macro
74+
# based on jvm_import_external in order to allow for other jvm-language
75+
# imports (e.g. scala_import) the 3rd-party dependency below is using the
76+
# java_import_external macro in order to make sure no regression with the
77+
# original java_import_external
78+
java_import_external(
79+
name = "org_apache_commons_commons_lang_3_5_without_file",
80+
generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file",
81+
jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c",
82+
jar_urls = ["https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
83+
licenses = ["notice"], # Apache 2.0
84+
neverlink = True,
85+
testonly_ = True,
86+
)
87+
88+
# We need to select based on platform when we use these
89+
# https://github.com/bazelbuild/bazel/issues/11655
90+
remote_jdk8_repos()
91+
92+
repositories(
93+
fetch_sources = fetch_sources,
94+
for_artifact_ids = [
95+
# test adding a scala jar:
96+
"com_twitter__scalding_date",
97+
# test of strict deps (scalac plugin UT + E2E)
98+
"com_google_guava_guava_21_0_with_file",
99+
"com_github_jnr_jffi_native",
100+
"org_apache_commons_commons_lang_3_5",
101+
"com_google_guava_guava_21_0",
102+
# test of import external
103+
# scala maven import external decodes maven artifacts to its parts
104+
# (group id, artifact id, packaging, version and classifier). To make sure
105+
# the decoding and then the download url composition are working the artifact example
106+
# must contain all the different parts and sha256s so the downloaded content will be
107+
# validated against it
108+
"org_springframework_spring_core",
109+
"org_springframework_spring_tx",
110+
"org_typelevel_kind_projector",
111+
# For testing that we don't include sources jars to the classpath
112+
"org_typelevel__cats_core",
113+
],
114+
maven_servers = maven_servers,
115+
)
116+
117+
remote_jdk21_repositories()
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
def proto_cross_repo_boundary_repository():
1+
"""Macro for creating the @proto_cross_repo_boundary repo for testing"""
2+
3+
# Once we switch to Bazel 7, uncomment this `load` statement remove the
4+
# `native.` prefix from `new_local_repository`.
5+
#load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
6+
7+
def proto_cross_repo_boundary_repository(
8+
name = "proto_cross_repo_boundary"):
9+
"""Creates the @proto_cross_repo_boundary repo for rules_scala testing."""
210
native.new_local_repository(
3-
name = "proto_cross_repo_boundary",
11+
name = name,
412
path = "test/proto_cross_repo_boundary/repo",
513
build_file = "//test/proto_cross_repo_boundary:repo/BUILD.repo",
614
)

0 commit comments

Comments
 (0)