forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolchains.bzl
195 lines (175 loc) · 7.14 KB
/
toolchains.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""Macros to instantiate and register @rules_scala_toolchains"""
load("//jmh/toolchain:toolchain.bzl", "jmh_artifact_ids")
load("//junit:junit.bzl", "junit_artifact_ids")
load(
"//scala/private:macros/scala_repositories.bzl",
"scala_version_artifact_ids",
"setup_scala_compiler_sources",
)
load(
"//scala/scalafmt:scalafmt_repositories.bzl",
"scalafmt_artifact_ids",
"scalafmt_config",
)
load("//scala:scala_cross_version.bzl", "default_maven_server_urls")
load("//scala:toolchains_repo.bzl", "scala_toolchains_repo")
load("//scala_proto/default:repositories.bzl", "scala_proto_artifact_ids")
load("//scalatest:scalatest.bzl", "scalatest_artifact_ids")
load("//specs2:specs2.bzl", "specs2_artifact_ids")
load("//specs2:specs2_junit.bzl", "specs2_junit_artifact_ids")
load("//third_party/repositories:repositories.bzl", "repositories")
load(
"//twitter_scrooge/toolchain:toolchain.bzl",
"twitter_scrooge_artifact_ids",
_TWITTER_SCROOGE_DEPS = "TOOLCHAIN_DEPS",
)
load("@rules_scala_config//:config.bzl", "SCALA_VERSIONS")
def _get_unknown_entries(entries, allowed_entries):
return [e for e in entries if e not in allowed_entries]
def scala_toolchains(
maven_servers = default_maven_server_urls(),
overridden_artifacts = {},
load_scala_toolchain_dependencies = True,
fetch_sources = False,
validate_scala_version = True,
scala_compiler_srcjars = {},
scalatest = False,
junit = False,
specs2 = False,
scalafmt = False,
scalafmt_default_config_path = ".scalafmt.conf",
scala_proto = False,
scala_proto_enable_all_options = False,
jmh = False,
twitter_scrooge = False,
twitter_scrooge_deps = {}):
"""Instantiates rules_scala toolchains and all their dependencies.
Provides a unified interface to configuring `rules_scala` both directly in a
`WORKSPACE` file and in a Bazel module extension.
Instantiates a repository containing all configured toolchains. Under
`WORKSPACE`, you will need to call `scala_register_toolchains()`. Under
Bzlmod, the `MODULE.bazel` file from `rules_scala` does this automatically.
All arguments are optional.
Args:
maven_servers: Maven servers used to fetch dependency jar files
overridden_artifacts: specific dependency jar files to use instead of
those from `maven_servers`, in the format:
```starlark
"repo_name": {
"artifact": "<maven coordinates>",
"sha256": "<checksum>",
"deps": [
"repository_names_of_dependencies",
],
}
```
fetch_sources: whether to download dependency source jars
validate_scala_version: whether to check if the configured Scala version
matches the default version supported by rules_scala
scala_compiler_srcjars: optional dictionary of Scala version string to
compiler srcjar metadata dictionaries containing:
- exactly one "label", "url", or "urls" key
- optional "integrity" or "sha256" keys
scalatest: whether to instantiate the ScalaTest toolchain
junit: whether to instantiate the JUnit toolchain
specs2: whether to instantiate the Specs2 JUnit toolchain
scalafmt: whether to instantiate the Scalafmt toolchain
scalafmt_default_config_path: the relative path to the default Scalafmt
config file within the repository
scala_proto: whether to instantiate the scala_proto toolchain
scala_proto_enable_all_options: whether to instantiate the scala_proto
toolchain with all options enabled; `scala_proto` must also be
`True` for this to take effect
jmh: whether to instantiate the Java Microbenchmarks Harness toolchain
twitter_scrooge: whether to instantiate the twitter_scrooge toolchain
twitter_scrooge_deps: dictionary of string to Label containing overrides
for twitter_scrooge toolchain dependency providers with keys:
libthrift
scrooge_core
scrooge_generator
util_core
util_logging
"""
unknown_ts_deps = _get_unknown_entries(
twitter_scrooge_deps,
_TWITTER_SCROOGE_DEPS,
)
if unknown_ts_deps:
fail("unknown twitter_scrooge_deps:", ", ".join(unknown_ts_deps))
setup_scala_compiler_sources(scala_compiler_srcjars)
if scalafmt:
scalafmt_conf_target = "//:" + scalafmt_default_config_path
scalafmt_config(name = "scalafmt_default", path = scalafmt_conf_target)
if specs2:
junit = True
artifact_ids_to_fetch_sources = {}
if scalatest:
artifact_ids_to_fetch_sources.update({
id: True
for id in scalatest_artifact_ids()
})
if junit:
artifact_ids_to_fetch_sources.update({
id: True
for id in junit_artifact_ids()
})
if specs2:
artifact_ids_to_fetch_sources.update({
id: True
for id in specs2_artifact_ids() + specs2_junit_artifact_ids()
})
if jmh:
artifact_ids_to_fetch_sources.update({
id: False
for id in jmh_artifact_ids()
})
if twitter_scrooge:
artifact_ids_to_fetch_sources.update({
id: False
for id in twitter_scrooge_artifact_ids(**twitter_scrooge_deps)
})
for scala_version in SCALA_VERSIONS:
version_specific_artifact_ids = {
id: fetch_sources
for id in scala_version_artifact_ids(scala_version)
}
if scala_proto:
version_specific_artifact_ids.update({
id: True
for id in scala_proto_artifact_ids(scala_version)
})
if scalafmt:
version_specific_artifact_ids.update({
id: fetch_sources
for id in scalafmt_artifact_ids(scala_version)
})
all_artifacts = (
artifact_ids_to_fetch_sources | version_specific_artifact_ids
)
repositories(
scala_version = scala_version,
for_artifact_ids = all_artifacts.keys(),
maven_servers = maven_servers,
fetch_sources = fetch_sources,
fetch_sources_by_id = all_artifacts,
# Note the internal macro parameter misspells "overriden".
overriden_artifacts = overridden_artifacts,
validate_scala_version = validate_scala_version,
)
scala_toolchains_repo(
scalatest = scalatest,
junit = junit,
specs2 = specs2,
scalafmt = scalafmt,
scala_proto = scala_proto,
scala_proto_enable_all_options = scala_proto_enable_all_options,
jmh = jmh,
twitter_scrooge = twitter_scrooge,
twitter_scrooge_deps = twitter_scrooge_deps,
)
def scala_register_toolchains():
native.register_toolchains("@rules_scala_toolchains//...:all")
def scala_register_unused_deps_toolchains():
native.register_toolchains(
str(Label("//scala:unused_dependency_checker_error_toolchain")),
)