Skip to content

Commit 8115f88

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 d35448f commit 8115f88

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)
@@ -66,7 +57,6 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
6657

6758
protobuf_deps()
6859

69-
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
7060
load("//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge")
7161

7262
twitter_scrooge()
@@ -93,53 +83,6 @@ scalafmt_default_config()
9383

9484
scalafmt_repositories()
9585

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

160103
go_register_toolchains(version = "1.19.5")
161104

162-
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
163-
164-
# We need to select based on platform when we use these
165-
# https://github.com/bazelbuild/bazel/issues/11655
166-
remote_jdk8_repos()
167-
168105
http_archive(
169106
name = "bazelci_rules",
170107
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
@@ -179,35 +116,20 @@ rbe_preconfig(
179116
toolchain = "ubuntu2004-bazel-java11",
180117
)
181118

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

209-
load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories", "remote_jdk21_toolchains")
121+
dev_deps_repositories()
210122

211-
remote_jdk21_repositories()
123+
# Copied from bazel_tools/tools/jdk/remote_java_repository.bzl.
124+
[
125+
register_toolchains(
126+
"@remotejdk21_" + platform + "_toolchain_config_repo//:all",
127+
)
128+
for platform in [
129+
"linux",
130+
"macos",
131+
"win",
132+
]
133+
]
212134

213-
remote_jdk21_toolchains()
135+
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)