blob: b5fba96eb057d161c4735b7528798c9ef73a0365 [file] [log] [blame]
Tony Aiuto337e7172020-12-09 10:20:14 -08001# Copyright 2020 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http:#www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
Xavier Bonaventurafc4d9d62021-12-08 02:17:49 -080014"""List the distribution dependencies we need to build Bazel.
15
16Note for Bazel users: This is not the file that you are looking for.
17This is internal source and is not intended to tell you what version
18you should use for each dependency.
19"""
Tony Aiuto337e7172020-12-09 10:20:14 -080020
21DIST_DEPS = {
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -080022 ########################################
23 #
24 # Runtime language dependencies
25 #
26 ########################################
Tony Aiutoe973aef2021-01-11 00:32:51 -080027 "platforms": {
John Cater2cff2ac2021-02-26 07:38:37 -080028 "archive": "platforms-0.0.4.tar.gz",
29 "sha256": "079945598e4b6cc075846f7fd6a9d0857c33a7afc0de868c2ccb96405225135d",
Tony Aiutoe973aef2021-01-11 00:32:51 -080030 "urls": [
John Cater2cff2ac2021-02-26 07:38:37 -080031 "https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
32 "https://github.com/bazelbuild/platforms/releases/download/0.0.4/platforms-0.0.4.tar.gz",
Tony Aiutoe973aef2021-01-11 00:32:51 -080033 ],
34 "used_in": [
35 "additional_distfiles",
36 "test_WORKSPACE_files",
37 ],
38 },
Chi Wang26b94ff2021-09-28 23:42:26 -070039 "bazelci_rules": {
40 "archive": "bazelci_rules-1.0.0.tar.gz",
41 "sha256": "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
42 "strip_prefix": "bazelci_rules-1.0.0",
Tony Aiutoe973aef2021-01-11 00:32:51 -080043 "urls": [
Chi Wang38a22d12021-12-06 08:30:58 -080044 "https://mirror.bazel.build/github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
Chi Wang26b94ff2021-09-28 23:42:26 -070045 "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
Tony Aiutoe973aef2021-01-11 00:32:51 -080046 ],
47 "used_in": [
48 "additional_distfiles",
49 ],
50 },
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -080051 # Keep in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/cc_configure.WORKSPACE.
52 # Keep in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
53 # Note: This is not in sync with src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java.
54 # Perhaps it should be.
Tony Aiuto337e7172020-12-09 10:20:14 -080055 "rules_cc": {
56 "archive": "b1c40e1de81913a3c40e5948f78719c28152486d.zip",
57 "sha256": "d0c573b94a6ef20ef6ff20154a23d0efcb409fb0e1ff0979cec318dfe42f0cdd",
58 "strip_prefix": "rules_cc-b1c40e1de81913a3c40e5948f78719c28152486d",
59 "urls": [
60 "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/b1c40e1de81913a3c40e5948f78719c28152486d.zip",
61 "https://github.com/bazelbuild/rules_cc/archive/b1c40e1de81913a3c40e5948f78719c28152486d.zip",
62 ],
Tony Aiutoe973aef2021-01-11 00:32:51 -080063 "used_in": [
64 "additional_distfiles",
65 "test_WORKSPACE_files",
66 ],
Tony Aiuto337e7172020-12-09 10:20:14 -080067 },
Tony Aiutob15a8b42021-01-08 07:42:57 -080068 "rules_java": {
69 "archive": "7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
70 "sha256": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
71 "strip_prefix": "rules_java-7cf3cefd652008d0a64a419c34c13bdca6c8f178",
72 "urls": [
73 "https://mirror.bazel.build/github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
74 "https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
75 ],
76 "used_in": [
77 "additional_distfiles",
78 "test_WORKSPACE_files",
79 ],
Tony Aiutob15a8b42021-01-08 07:42:57 -080080 },
Tony Aiuto320bc942021-01-14 07:43:21 -080081 # TODO(aiuto): Update src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java to use
82 # this dynamically.
83 "rules_proto": {
84 "archive": "7e4afce6fe62dbff0a4a03450143146f9f2d7488.tar.gz",
85 "sha256": "8e7d59a5b12b233be5652e3d29f42fba01c7cbab09f6b3a8d0a57ed6d1e9a0da",
86 "strip_prefix": "rules_proto-7e4afce6fe62dbff0a4a03450143146f9f2d7488",
87 "urls": [
88 "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/7e4afce6fe62dbff0a4a03450143146f9f2d7488.tar.gz",
89 "https://github.com/bazelbuild/rules_proto/archive/7e4afce6fe62dbff0a4a03450143146f9f2d7488.tar.gz",
90 ],
91 "used_in": [
92 "additional_distfiles",
93 "test_WORKSPACE_files",
94 ],
95 },
Tony Aiutoe973aef2021-01-11 00:32:51 -080096 #################################################
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -080097 #
Tony Aiutoe973aef2021-01-11 00:32:51 -080098 # Dependencies which are part of the Bazel binary
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -080099 #
Tony Aiutoe973aef2021-01-11 00:32:51 -0800100 #################################################
101 "com_google_protobuf": {
102 "archive": "v3.13.0.tar.gz",
103 "sha256": "9b4ee22c250fe31b16f1a24d61467e40780a3fbb9b91c3b65be2a376ed913a1a",
104 "strip_prefix": "protobuf-3.13.0",
105 "urls": [
106 "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
107 "https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz",
108 ],
109 "patch_args": ["-p1"],
110 "patches": ["//third_party/protobuf:3.13.0.patch"],
111 "used_in": [
112 "additional_distfiles",
113 "test_WORKSPACE_files",
114 ],
115 },
Tony Aiuto320bc942021-01-14 07:43:21 -0800116 "protocolbuffers": {
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700117 "archive": "2de300726a1ba2de9a468468dc5ff9ed17a3215f.tar.gz",
118 "sha256": "6a5f67874af66b239b709c572ac1a5a00fdb1b29beaf13c3e6f79b1ba10dc7c4",
Tony Aiuto320bc942021-01-14 07:43:21 -0800119 "urls": [
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700120 "https://mirror.bazel.build/github.com/protocolbuffers/upb/archive/2de300726a1ba2de9a468468dc5ff9ed17a3215f.tar.gz",
121 "https://github.com/protocolbuffers/upb/archive/2de300726a1ba2de9a468468dc5ff9ed17a3215f.tar.gz",
Tony Aiuto320bc942021-01-14 07:43:21 -0800122 ],
123 "used_in": [
124 "additional_distfiles",
125 "test_WORKSPACE_files",
126 ],
127 },
Tony Aiutoe973aef2021-01-11 00:32:51 -0800128 "com_github_grpc_grpc": {
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700129 "archive": "v1.41.0.tar.gz",
130 "sha256": "e5fb30aae1fa1cffa4ce00aa0bbfab908c0b899fcf0bbc30e268367d660d8656",
131 "strip_prefix": "grpc-1.41.0",
Tony Aiutoe973aef2021-01-11 00:32:51 -0800132 "urls": [
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700133 "https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.41.0.tar.gz",
134 "https://github.com/grpc/grpc/archive/v1.41.0.tar.gz",
Tony Aiutoe973aef2021-01-11 00:32:51 -0800135 ],
136 "patch_args": ["-p1"],
137 "patches": [
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700138 "//third_party/grpc:grpc_1.41.0.patch",
Tony Aiutoe973aef2021-01-11 00:32:51 -0800139 ],
140 "used_in": [
141 "additional_distfiles",
142 "test_WORKSPACE_files",
143 ],
144 },
145 "c-ares": {
146 "archive": "e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz",
147 "sha256": "e8c2751ddc70fed9dc6f999acd92e232d5846f009ee1674f8aee81f19b2b915a",
148 "urls": [
149 "https://mirror.bazel.build/github.com/c-ares/c-ares/archive/e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz",
150 "https://github.com/c-ares/c-ares/archive/e982924acee7f7313b4baa4ee5ec000c5e373c30.tar.gz",
151 ],
152 "used_in": [
153 "additional_distfiles",
154 "test_WORKSPACE_files",
155 ],
156 },
157 "re2": {
158 "archive": "aecba11114cf1fac5497aeb844b6966106de3eb6.tar.gz",
159 "sha256": "9f385e146410a8150b6f4cb1a57eab7ec806ced48d427554b1e754877ff26c3e",
160 "urls": [
161 "https://mirror.bazel.build/github.com/google/re2/archive/aecba11114cf1fac5497aeb844b6966106de3eb6.tar.gz",
162 "https://github.com/google/re2/archive/aecba11114cf1fac5497aeb844b6966106de3eb6.tar.gz",
163 ],
164 "used_in": [
165 "additional_distfiles",
166 "test_WORKSPACE_files",
167 ],
168 },
169 "abseil-cpp": {
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700170 "archive": "997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz",
171 "sha256": "35f22ef5cb286f09954b7cc4c85b5a3f6221c9d4df6b8c4a1e9d399555b366ee",
Tony Aiutoe973aef2021-01-11 00:32:51 -0800172 "urls": [
Benjamin Petersonc01219e2021-10-25 02:29:55 -0700173 "https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz",
174 "https://github.com/abseil/abseil-cpp/archive/997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz",
Tony Aiutoe973aef2021-01-11 00:32:51 -0800175 ],
176 "used_in": [
177 "additional_distfiles",
178 "test_WORKSPACE_files",
179 ],
180 },
Alessandro Patti6da80862021-11-11 22:49:37 -0800181 "zstd-jni": {
182 "archive": "v1.5.0-4.zip",
183 "patch_args": ["-p1"],
184 "patches": [
185 "//third_party:zstd-jni/Native.java.patch",
186 ],
187 "sha256": "d320d59b89a163c5efccbe4915ae6a49883ce653cdc670643dfa21c6063108e4",
188 "urls": [
189 "https://mirror.bazel.build/github.com/luben/zstd-jni/archive/v1.5.0-4.zip",
190 "https://github.com/luben/zstd-jni/archive/v1.5.0-4.zip",
191 ],
192 "used_in": [
193 "additional_distfiles",
194 ],
195 },
Tony Aiutoe973aef2021-01-11 00:32:51 -0800196 ###################################################
197 #
198 # Build time dependencies for testing and packaging
199 #
200 ###################################################
Tony Aiuto2b7ec5c2021-01-11 07:50:26 -0800201 "bazel_skylib": {
202 "archive": "bazel-skylib-1.0.3.tar.gz",
203 "sha256": "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
204 "urls": [
205 "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
206 "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
207 ],
208 "used_in": [
209 "additional_distfiles",
210 "test_WORKSPACE_files",
211 ],
212 },
213 "io_bazel_skydoc": {
214 "archive": "1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
215 "sha256": "5a725b777976b77aa122b707d1b6f0f39b6020f66cd427bb111a585599c857b1",
216 "urls": [
217 "https://mirror.bazel.build/github.com/bazelbuild/stardoc/archive/1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
218 "https://github.com/bazelbuild/stardoc/archive/1ef781ced3b1443dca3ed05dec1989eca1a4e1cd.tar.gz",
219 ],
220 "used_in": [
221 "additional_distfiles",
222 ],
223 "strip_prefix": "stardoc-1ef781ced3b1443dca3ed05dec1989eca1a4e1cd",
224 },
Tony Aiuto337e7172020-12-09 10:20:14 -0800225 "rules_pkg": {
Tony Aiuto99079b32021-04-06 06:41:17 -0700226 "archive": "rules_pkg-0.4.0.tar.gz",
227 "sha256": "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
Tony Aiuto337e7172020-12-09 10:20:14 -0800228 "urls": [
Tony Aiuto99079b32021-04-06 06:41:17 -0700229 "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
230 "https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
Tony Aiuto337e7172020-12-09 10:20:14 -0800231 ],
Tony Aiutoe973aef2021-01-11 00:32:51 -0800232 "used_in": [
233 "additional_distfiles",
234 ],
Tony Aiuto337e7172020-12-09 10:20:14 -0800235 },
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -0800236 # for Stardoc
237 "io_bazel_rules_sass": {
238 "archive": "1.25.0.zip",
239 "sha256": "c78be58f5e0a29a04686b628cf54faaee0094322ae0ac99da5a8a8afca59a647",
240 "strip_prefix": "rules_sass-1.25.0",
241 "urls": [
242 "https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
243 "https://github.com/bazelbuild/rules_sass/archive/1.25.0.zip",
244 ],
Tony Aiutoe973aef2021-01-11 00:32:51 -0800245 "used_in": [
246 "additional_distfiles",
247 ],
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -0800248 },
249 # for Stardoc
250 "build_bazel_rules_nodejs": {
251 "archive": "rules_nodejs-2.2.2.tar.gz",
252 "sha256": "f2194102720e662dbf193546585d705e645314319554c6ce7e47d8b59f459e9c",
253 "urls": [
254 "https://mirror.bazel.build/github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
255 "https://github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz",
256 ],
Tony Aiutoe973aef2021-01-11 00:32:51 -0800257 "used_in": [
258 "additional_distfiles",
259 ],
Tony Aiuto1c9e7ca2021-01-05 08:01:21 -0800260 },
mennyf431b0c2021-01-13 09:18:29 -0800261 "desugar_jdk_libs": {
Menny Even Danan29cfb0b2021-03-31 15:21:30 -0700262 # Commit 5847d6a06302136d95a14b4cbd4b55a9c9f1436e of 2021-03-10
263 "archive": "5847d6a06302136d95a14b4cbd4b55a9c9f1436e.zip",
264 "sha256": "299452e6f4a4981b2e6d22357f7332713382a63e4c137f5fd6b89579f6d610cb",
265 "strip_prefix": "desugar_jdk_libs-5847d6a06302136d95a14b4cbd4b55a9c9f1436e",
mennyf431b0c2021-01-13 09:18:29 -0800266 "urls": [
Menny Even Danan29cfb0b2021-03-31 15:21:30 -0700267 "https://mirror.bazel.build/github.com/google/desugar_jdk_libs/archive/5847d6a06302136d95a14b4cbd4b55a9c9f1436e.zip",
268 "https://github.com/google/desugar_jdk_libs/archive/5847d6a06302136d95a14b4cbd4b55a9c9f1436e.zip",
mennyf431b0c2021-01-13 09:18:29 -0800269 ],
270 "used_in": [
271 "additional_distfiles",
272 ],
273 },
aiutobbeb1da2021-01-15 06:50:56 -0800274 "remote_coverage_tools": {
275 "archive": "coverage_output_generator-v2.5.zip",
276 "sha256": "cd14f1cb4559e4723e63b7e7b06d09fcc3bd7ba58d03f354cdff1439bd936a7d",
277 "urls": [
278 "https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.5.zip",
279 ],
280 "used_in": [
281 "additional_distfiles",
282 "test_WORKSPACE_files",
283 ],
284 },
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800285 "remote_java_tools": {
John Cater2cff2ac2021-02-26 07:38:37 -0800286 "aliases": [
287 "remote_java_tools_test",
288 "remote_java_tools_for_testing",
289 ],
hvadehrad703b7b2021-11-18 12:24:25 -0800290 "archive": "java_tools-v11.6.zip",
291 "sha256": "a7ac5922ee01e8b8fcb546ffc264ef314d0a0c679328b7fa4c432e5f54a86067",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800292 "urls": [
hvadehrad703b7b2021-11-18 12:24:25 -0800293 "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.6/java_tools-v11.6.zip",
294 "https://github.com/bazelbuild/java_tools/releases/download/java_v11.6/java_tools-v11.6.zip",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800295 ],
296 "used_in": [
297 "additional_distfiles",
298 "test_WORKSPACE_files",
299 ],
300 },
301 "remote_java_tools_linux": {
John Cater2cff2ac2021-02-26 07:38:37 -0800302 "aliases": [
303 "remote_java_tools_test_linux",
304 "remote_java_tools_linux_for_testing",
305 ],
hvadehrad703b7b2021-11-18 12:24:25 -0800306 "archive": "java_tools_linux-v11.6.zip",
307 "sha256": "15da4f84a7d39cd179acf3035d9def638eea6ba89a0ed8f4e8a8e6e1d6c8e328",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800308 "urls": [
hvadehrad703b7b2021-11-18 12:24:25 -0800309 "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.6/java_tools_linux-v11.6.zip",
310 "https://github.com/bazelbuild/java_tools/releases/download/java_v11.6/java_tools_linux-v11.6.zip",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800311 ],
312 "used_in": [
313 "additional_distfiles",
314 "test_WORKSPACE_files",
315 ],
316 },
317 "remote_java_tools_windows": {
John Cater2cff2ac2021-02-26 07:38:37 -0800318 "aliases": [
319 "remote_java_tools_test_windows",
320 "remote_java_tools_windows_for_testing",
321 ],
hvadehrad703b7b2021-11-18 12:24:25 -0800322 "archive": "java_tools_windows-v11.6.zip",
323 "sha256": "939f9d91f0df02851bbad8f5b1d26d24011329394cafe5668c1234e31ac2a1f7",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800324 "urls": [
hvadehrad703b7b2021-11-18 12:24:25 -0800325 "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.6/java_tools_windows-v11.6.zip",
326 "https://github.com/bazelbuild/java_tools/releases/download/java_v11.6/java_tools_windows-v11.6.zip",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800327 ],
328 "used_in": [
329 "additional_distfiles",
330 "test_WORKSPACE_files",
331 ],
332 },
333 "remote_java_tools_darwin": {
John Cater2cff2ac2021-02-26 07:38:37 -0800334 "aliases": [
335 "remote_java_tools_test_darwin",
336 "remote_java_tools_darwin_for_testing",
337 ],
hvadehrad703b7b2021-11-18 12:24:25 -0800338 "archive": "java_tools_darwin-v11.6.zip",
339 "sha256": "f17ee54582b61f1ebd84c8fa2c54df796914cfbaac3cb821fb1286b55b080bc0",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800340 "urls": [
hvadehrad703b7b2021-11-18 12:24:25 -0800341 "https://mirror.bazel.build/bazel_java_tools/releases/java/v11.6/java_tools_darwin-v11.6.zip",
342 "https://github.com/bazelbuild/java_tools/releases/download/java_v11.6/java_tools_darwin-v11.6.zip",
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800343 ],
344 "used_in": [
345 "additional_distfiles",
346 "test_WORKSPACE_files",
347 ],
348 },
Tony Aiuto337e7172020-12-09 10:20:14 -0800349}
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800350
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800351# Add aliased names
352DEPS_BY_NAME = {}
353
354def _create_index():
355 for repo_name in DIST_DEPS:
356 repo = DIST_DEPS[repo_name]
357 DEPS_BY_NAME[repo_name] = repo
358 aliases = repo.get("aliases")
359 if aliases:
360 for alias in aliases:
361 DEPS_BY_NAME[alias] = repo
362
363_create_index()
364
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800365def _gen_workspace_stanza_impl(ctx):
366 if ctx.attr.template and (ctx.attr.preamble or ctx.attr.postamble):
367 fail("Can not use template with either preamble or postamble")
368
Tony Aiutob15a8b42021-01-08 07:42:57 -0800369 if ctx.attr.use_maybe:
370 repo_clause = """
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800371maybe(
372 http_archive,
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800373 name = "{repo}",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800374 sha256 = "{sha256}",
375 strip_prefix = {strip_prefix},
376 urls = {urls},
377)
378"""
Tony Aiutob15a8b42021-01-08 07:42:57 -0800379 else:
380 repo_clause = """
381http_archive(
382 name = "{repo}",
383 sha256 = "{sha256}",
384 strip_prefix = {strip_prefix},
385 urls = {urls},
386)
387"""
388
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800389 repo_stanzas = {}
390 for repo in ctx.attr.repos:
Tony Aiuto6a3d5f12021-01-12 13:38:32 -0800391 info = DEPS_BY_NAME[repo]
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800392 strip_prefix = info.get("strip_prefix")
393 if strip_prefix:
394 strip_prefix = "\"%s\"" % strip_prefix
395 else:
396 strip_prefix = "None"
397
398 repo_stanzas["{%s}" % repo] = repo_clause.format(
399 repo = repo,
400 archive = info["archive"],
401 sha256 = str(info["sha256"]),
402 strip_prefix = strip_prefix,
403 urls = info["urls"],
404 )
405
406 if ctx.attr.template:
407 ctx.actions.expand_template(
408 output = ctx.outputs.out,
409 template = ctx.file.template,
410 substitutions = repo_stanzas,
411 )
412 else:
413 content = "\n".join([p.strip() for p in ctx.attr.preamble.strip().split("\n")])
414 content += "\n"
415 content += "".join(repo_stanzas.values())
416 content += "\n"
417 content += "\n".join([p.strip() for p in ctx.attr.postamble.strip().split("\n")])
418 content += "\n"
419 ctx.actions.write(ctx.outputs.out, content)
420
421 return [DefaultInfo(files = depset([ctx.outputs.out]))]
422
423gen_workspace_stanza = rule(
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800424 attrs = {
twerth69a0d1a2021-08-12 07:03:10 -0700425 "repos": attr.string_list(doc = "Set of repos to include."),
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800426 "out": attr.output(mandatory = True),
427 "preamble": attr.string(doc = "Preamble."),
twerth69a0d1a2021-08-12 07:03:10 -0700428 "postamble": attr.string(doc = "Set of rules to follow repos."),
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800429 "template": attr.label(
twerth69a0d1a2021-08-12 07:03:10 -0700430 doc = "Template WORKSPACE file. May not be used with preamble or postamble." +
431 "Repo stanzas can be included using the syntax '{repo name}'.",
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800432 allow_single_file = True,
433 mandatory = False,
434 ),
twerth69a0d1a2021-08-12 07:03:10 -0700435 "use_maybe": attr.bool(doc = "Use maybe() invocation instead of http_archive."),
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800436 },
John Cater2cff2ac2021-02-26 07:38:37 -0800437 doc = "Use specifications from DIST_DEPS to generate WORKSPACE http_archive stanzas or to" +
438 "drop them into a template.",
439 implementation = _gen_workspace_stanza_impl,
Tony Aiuto3b2d3102021-01-07 03:40:14 -0800440)