Skip to content

Commit 8d9e1f8

Browse files
authored
Extract dev_deps_repositories() from WORKSPACE and remove //private (bazel-contrib#1656)
* 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. * Add test local_repository calls to WORKSPACE Removes `native.{,new_}local_repository()` calls in macros in favor of `local_repository` calls from `WORKSPACE`. Part of bazel-contrib#1482. `native.{,new_}local_repository()` isn't available under Bzlmod, `@bazel_tools//tools/build_defs/repo:local.bzl` with the Starlarkified definitions isn't available under Bazel 6, and Bazel 8 compatibility work is imminent. Redefining the repositories in this way will be compatible with Bazel 6, 7, and 8, both under `WORKSPACE` and Bzlmod. (`MODULE.bazel` will use a combination of `bazel_dep()` and `local_path_override()`.)
1 parent 374c559 commit 8d9e1f8

File tree

11 files changed

+103
-165
lines changed

11 files changed

+103
-165
lines changed

WORKSPACE

+19-81
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,23 +83,14 @@ scalafmt_default_config()
9383

9484
scalafmt_repositories()
9585

96-
MAVEN_SERVER_URLS = default_maven_server_urls()
97-
9886
# 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()
87+
local_repository(
88+
name = "proto_cross_repo_boundary",
89+
path = "test/proto_cross_repo_boundary/repo",
90+
)
10291

103-
new_local_repository(
92+
local_repository(
10493
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-
""",
11394
path = "third_party/test/new_local_repo",
11495
)
11596

@@ -118,28 +99,6 @@ local_repository(
11899
path = "third_party/test/example_external_workspace",
119100
)
120101

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-
143102
http_archive(
144103
name = "io_bazel_rules_go",
145104
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
@@ -159,12 +118,6 @@ go_rules_dependencies()
159118

160119
go_register_toolchains(version = "1.19.5")
161120

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-
168121
http_archive(
169122
name = "bazelci_rules",
170123
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
@@ -179,35 +132,20 @@ rbe_preconfig(
179132
toolchain = "ubuntu2004-bazel-java11",
180133
)
181134

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-
)
135+
load("//scala/private/extensions:dev_deps.bzl", "dev_deps_repositories")
208136

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

211-
remote_jdk21_repositories()
139+
# Copied from bazel_tools/tools/jdk/remote_java_repository.bzl.
140+
[
141+
register_toolchains(
142+
"@remotejdk21_" + platform + "_toolchain_config_repo//:all",
143+
)
144+
for platform in [
145+
"linux",
146+
"macos",
147+
"win",
148+
]
149+
]
212150

213-
remote_jdk21_toolchains()
151+
register_toolchains("//test/toolchains:java21_toolchain_definition")

private/BUILD

-7
This file was deleted.

private/format.bzl

-71
This file was deleted.

scala/private/extensions/dev_deps.bzl

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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("//test/toolchains:jdk.bzl", "remote_jdk21_repositories")
6+
load("//third_party/repositories:repositories.bzl", "repositories")
7+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
8+
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
9+
10+
_BUILD_TOOLS_RELEASE = "5.1.0"
11+
12+
def dev_deps_repositories(
13+
name = "unused_dev_deps_name",
14+
maven_servers = default_maven_server_urls(),
15+
fetch_sources = False):
16+
"""Instantiates internal only repos for development and testing
17+
18+
Args:
19+
name: unused macro parameter to satisfy Buildifier lint rules
20+
maven_servers: servers to use when resolving Maven artifacts
21+
fetch_sources: retrieve Maven artifact sources when True
22+
"""
23+
http_archive(
24+
name = "com_github_bazelbuild_buildtools",
25+
sha256 = "e3bb0dc8b0274ea1aca75f1f8c0c835adbe589708ea89bf698069d0790701ea3",
26+
strip_prefix = "buildtools-%s" % _BUILD_TOOLS_RELEASE,
27+
url = (
28+
"https://github.com/bazelbuild/buildtools/archive/%s.tar.gz" %
29+
_BUILD_TOOLS_RELEASE
30+
),
31+
)
32+
33+
# bazel's java_import_external has been altered in rules_scala to be a macro
34+
# based on jvm_import_external in order to allow for other jvm-language
35+
# imports (e.g. scala_import) the 3rd-party dependency below is using the
36+
# java_import_external macro in order to make sure no regression with the
37+
# original java_import_external
38+
java_import_external(
39+
name = "org_apache_commons_commons_lang_3_5_without_file",
40+
generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file",
41+
jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c",
42+
jar_urls = ["https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
43+
licenses = ["notice"], # Apache 2.0
44+
neverlink = True,
45+
testonly_ = True,
46+
)
47+
48+
# We need to select based on platform when we use these
49+
# https://github.com/bazelbuild/bazel/issues/11655
50+
remote_jdk8_repos()
51+
52+
repositories(
53+
fetch_sources = fetch_sources,
54+
for_artifact_ids = [
55+
# test adding a scala jar:
56+
"com_twitter__scalding_date",
57+
# test of strict deps (scalac plugin UT + E2E)
58+
"com_google_guava_guava_21_0_with_file",
59+
"com_github_jnr_jffi_native",
60+
"org_apache_commons_commons_lang_3_5",
61+
"com_google_guava_guava_21_0",
62+
# test of import external
63+
# scala maven import external decodes maven artifacts to its parts
64+
# (group id, artifact id, packaging, version and classifier). To make sure
65+
# the decoding and then the download url composition are working the artifact example
66+
# must contain all the different parts and sha256s so the downloaded content will be
67+
# validated against it
68+
"org_springframework_spring_core",
69+
"org_springframework_spring_tx",
70+
"org_typelevel_kind_projector",
71+
# For testing that we don't include sources jars to the classpath
72+
"org_typelevel__cats_core",
73+
],
74+
maven_servers = maven_servers,
75+
)
76+
77+
remote_jdk21_repositories()

test/proto_cross_repo_boundary/repo.bzl

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.5.0

test/proto_cross_repo_boundary/repo/WORKSPACE

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.5.0

third_party/test/new_local_repo/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
filegroup(
2+
name = "data",
3+
srcs = glob(["**/*.txt"]),
4+
visibility = ["//visibility:public"],
5+
)

third_party/test/new_local_repo/WORKSPACE

Whitespace-only changes.

0 commit comments

Comments
 (0)