Skip to content

Commit b3378a6

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 5144202 commit b3378a6

File tree

5 files changed

+141
-173
lines changed

5 files changed

+141
-173
lines changed

WORKSPACE

Lines changed: 14 additions & 93 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)
@@ -72,55 +63,6 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
7263

7364
protobuf_deps()
7465

75-
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
76-
77-
MAVEN_SERVER_URLS = default_maven_server_urls()
78-
79-
# needed for the cross repo proto test
80-
load("//test/proto_cross_repo_boundary:repo.bzl", "proto_cross_repo_boundary_repository")
81-
82-
proto_cross_repo_boundary_repository()
83-
84-
new_local_repository(
85-
name = "test_new_local_repo",
86-
build_file_content =
87-
"""
88-
filegroup(
89-
name = "data",
90-
srcs = glob(["**/*.txt"]),
91-
visibility = ["//visibility:public"],
92-
)
93-
""",
94-
path = "third_party/test/new_local_repo",
95-
)
96-
97-
local_repository(
98-
name = "example_external_workspace",
99-
path = "third_party/test/example_external_workspace",
100-
)
101-
102-
load("//scala:scala_maven_import_external.bzl", "java_import_external")
103-
104-
# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external
105-
# in order to allow for other jvm-language imports (e.g. scala_import)
106-
# the 3rd-party dependency below is using the java_import_external macro
107-
# in order to make sure no regression with the original java_import_external
108-
java_import_external(
109-
name = "org_apache_commons_commons_lang_3_5_without_file",
110-
generated_linkable_rule_name = "linkable_org_apache_commons_commons_lang_3_5_without_file",
111-
jar_sha256 = "8ac96fc686512d777fca85e144f196cd7cfe0c0aec23127229497d1a38ff651c",
112-
jar_urls = ["https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar"],
113-
licenses = ["notice"], # Apache 2.0
114-
neverlink = True,
115-
testonly_ = True,
116-
)
117-
118-
## Linting
119-
120-
load("//private:format.bzl", "format_repositories")
121-
122-
format_repositories()
123-
12466
http_archive(
12567
name = "io_bazel_rules_go",
12668
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
@@ -140,12 +82,6 @@ go_rules_dependencies()
14082

14183
go_register_toolchains(version = "1.19.5")
14284

143-
load("@rules_java//java:repositories.bzl", "remote_jdk8_repos")
144-
145-
# We need to select based on platform when we use these
146-
# https://github.com/bazelbuild/bazel/issues/11655
147-
remote_jdk8_repos()
148-
14985
http_archive(
15086
name = "bazelci_rules",
15187
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
@@ -160,35 +96,20 @@ rbe_preconfig(
16096
toolchain = "ubuntu2004-bazel-java11",
16197
)
16298

163-
load("//third_party/repositories:repositories.bzl", "repositories")
164-
165-
repositories(
166-
fetch_sources = False,
167-
for_artifact_ids = [
168-
# test adding a scala jar:
169-
"com_twitter__scalding_date",
170-
# test of strict deps (scalac plugin UT + E2E)
171-
"com_google_guava_guava_21_0_with_file",
172-
"com_github_jnr_jffi_native",
173-
"org_apache_commons_commons_lang_3_5",
174-
"com_google_guava_guava_21_0",
175-
# test of import external
176-
# scala maven import external decodes maven artifacts to its parts
177-
# (group id, artifact id, packaging, version and classifier). To make sure
178-
# the decoding and then the download url composition are working the artifact example
179-
# must contain all the different parts and sha256s so the downloaded content will be
180-
# validated against it
181-
"org_springframework_spring_core",
182-
"org_springframework_spring_tx",
183-
"org_typelevel_kind_projector",
184-
# For testing that we don't include sources jars to the classpath
185-
"org_typelevel__cats_core",
186-
],
187-
maven_servers = MAVEN_SERVER_URLS,
188-
)
99+
load("//scala/private/extensions:dev_deps.bzl", "dev_deps_repositories")
189100

190-
load("//test/toolchains:jdk.bzl", "remote_jdk21_repositories", "remote_jdk21_toolchains")
101+
dev_deps_repositories()
191102

192-
remote_jdk21_repositories()
103+
# Copied from bazel_tools/tools/jdk/remote_java_repository.bzl.
104+
[
105+
register_toolchains(
106+
"@remotejdk21_" + platform + "_toolchain_config_repo//:all",
107+
)
108+
for platform in [
109+
"linux",
110+
"macos",
111+
"win",
112+
]
113+
]
193114

194-
remote_jdk21_toolchains()
115+
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)