41
41
)
42
42
43
43
# Shared between http_jar, http_file and http_archive.
44
+
45
+ _URL_DOC = """A URL to a file that will be made available to Bazel.
46
+
47
+ This must be a file, http or https URL. Redirections are followed.
48
+ Authentication is not supported.
49
+
50
+ More flexibility can be achieved by the urls parameter that allows
51
+ to specify alternative URLs to fetch from."""
52
+
53
+ _URLS_DOC = """A list of URLs to a file that will be made available to Bazel.
54
+
55
+ Each entry must be a file, http or https URL. Redirections are followed.
56
+ Authentication is not supported.
57
+
58
+ URLs are tried in order until one succeeds, so you should list local mirrors first.
59
+ If all downloads fail, the rule will fail."""
60
+
61
+ def _get_all_urls (ctx ):
62
+ """Returns all urls provided via the url or urls attributes.
63
+
64
+ Also checks that at least one url is provided."""
65
+ if not ctx .attr .url and not ctx .attr .urls :
66
+ fail ("At least one of url and urls must be provided" )
67
+
68
+ all_urls = []
69
+ if ctx .attr .urls :
70
+ all_urls = ctx .attr .urls
71
+ if ctx .attr .url :
72
+ all_urls = [ctx .attr .url ] + all_urls
73
+
74
+ return all_urls
75
+
44
76
_AUTH_PATTERN_DOC = """An optional dict mapping host names to custom authorization patterns.
45
77
46
78
If a URL's host name is present in this dict the value will be used as a pattern when
@@ -84,17 +116,10 @@ def _get_auth(ctx, urls):
84
116
85
117
def _http_archive_impl (ctx ):
86
118
"""Implementation of the http_archive rule."""
87
- if not ctx .attr .url and not ctx .attr .urls :
88
- fail ("At least one of url and urls must be provided" )
89
119
if ctx .attr .build_file and ctx .attr .build_file_content :
90
120
fail ("Only one of build_file and build_file_content can be provided." )
91
121
92
- all_urls = []
93
- if ctx .attr .urls :
94
- all_urls = ctx .attr .urls
95
- if ctx .attr .url :
96
- all_urls = [ctx .attr .url ] + all_urls
97
-
122
+ all_urls = _get_all_urls (ctx )
98
123
auth = _get_auth (ctx , all_urls )
99
124
100
125
download_info = ctx .download_and_extract (
@@ -138,9 +163,10 @@ def _http_file_impl(ctx):
138
163
download_path = ctx .path ("file/" + downloaded_file_path )
139
164
if download_path in forbidden_files or not str (download_path ).startswith (str (repo_root )):
140
165
fail ("'%s' cannot be used as downloaded_file_path in http_file" % ctx .attr .downloaded_file_path )
141
- auth = _get_auth (ctx , ctx .attr .urls )
166
+ all_urls = _get_all_urls (ctx )
167
+ auth = _get_auth (ctx , all_urls )
142
168
download_info = ctx .download (
143
- ctx . attr . urls ,
169
+ all_urls ,
144
170
"file/" + downloaded_file_path ,
145
171
ctx .attr .sha256 ,
146
172
ctx .attr .executable ,
@@ -173,11 +199,7 @@ filegroup(
173
199
174
200
def _http_jar_impl (ctx ):
175
201
"""Implementation of the http_jar rule."""
176
- all_urls = []
177
- if ctx .attr .urls :
178
- all_urls = ctx .attr .urls
179
- if ctx .attr .url :
180
- all_urls = [ctx .attr .url ] + all_urls
202
+ all_urls = _get_all_urls (ctx )
181
203
auth = _get_auth (ctx , all_urls )
182
204
downloaded_file_name = ctx .attr .downloaded_file_name
183
205
download_info = ctx .download (
@@ -192,28 +214,8 @@ def _http_jar_impl(ctx):
192
214
return update_attrs (ctx .attr , _http_jar_attrs .keys (), {"sha256" : download_info .sha256 })
193
215
194
216
_http_archive_attrs = {
195
- "url" : attr .string (
196
- doc =
197
- """A URL to a file that will be made available to Bazel.
198
-
199
- This must be a file, http or https URL. Redirections are followed.
200
- Authentication is not supported.
201
-
202
- This parameter is to simplify the transition from the native http_archive
203
- rule. More flexibility can be achieved by the urls parameter that allows
204
- to specify alternative URLs to fetch from.
205
- """ ,
206
- ),
207
- "urls" : attr .string_list (
208
- doc =
209
- """A list of URLs to a file that will be made available to Bazel.
210
-
211
- Each entry must be a file, http or https URL. Redirections are followed.
212
- Authentication is not supported.
213
-
214
- URLs are tried in order until one succeeds, so you should list local mirrors first.
215
- If all downloads fail, the rule will fail.""" ,
216
- ),
217
+ "url" : attr .string (doc = _URL_DOC ),
218
+ "urls" : attr .string_list (doc = _URLS_DOC ),
217
219
"sha256" : attr .string (
218
220
doc = """The expected SHA-256 of the file downloaded.
219
221
@@ -393,7 +395,7 @@ Examples:
393
395
394
396
http_archive(
395
397
name = "my_ssl",
396
- urls = [ "http://example.com/openssl.zip"] ,
398
+ url = "http://example.com/openssl.zip",
397
399
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
398
400
build_file = "@//:openssl.BUILD",
399
401
)
@@ -426,13 +428,8 @@ If specified and non-empty, bazel will not take the archive from cache,
426
428
unless it was added to the cache by a request with the same canonical id.
427
429
""" ,
428
430
),
429
- "urls" : attr .string_list (
430
- mandatory = True ,
431
- doc = """A list of URLs to a file that will be made available to Bazel.
432
-
433
- Each entry must be a file, http or https URL. Redirections are followed.
434
- Authentication is not supported.""" ,
435
- ),
431
+ "url" : attr .string (doc = _URL_DOC ),
432
+ "urls" : attr .string_list (doc = _URLS_DOC ),
436
433
"netrc" : attr .string (
437
434
doc = "Location of the .netrc file to use for authentication" ,
438
435
),
@@ -458,7 +455,7 @@ Examples:
458
455
459
456
http_file(
460
457
name = "my_deb",
461
- urls = [ "http://example.com/package.deb"] ,
458
+ url = "http://example.com/package.deb",
462
459
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
463
460
)
464
461
```
@@ -478,15 +475,8 @@ If specified and non-empty, bazel will not take the archive from cache,
478
475
unless it was added to the cache by a request with the same canonical id.
479
476
""" ,
480
477
),
481
- "url" : attr .string (
482
- doc =
483
- "The URL to fetch the jar from. It must end in `.jar`." ,
484
- ),
485
- "urls" : attr .string_list (
486
- doc =
487
- "A list of URLS the jar can be fetched from. They have to end " +
488
- "in `.jar`." ,
489
- ),
478
+ "url" : attr .string (doc = _URL_DOC + "\n \n The URL must end in `.jar`." ),
479
+ "urls" : attr .string_list (doc = _URLS_DOC + "\n \n All URLs must end in `.jar`." ),
490
480
"netrc" : attr .string (
491
481
doc = "Location of the .netrc file to use for authentication" ,
492
482
),
0 commit comments