Skip to content
File

Blob: build/exts/http.bzl

3.0 KB
1"""
2A Bazel module extension that wraps the http_archive and http_file repository rules, in order
3to allow the injection of a custom proxy URL.
4"""
5 
6load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
7load("//:build/http_proxy_config.bzl", "PROXY_URL")
8 
9def _http_ext_impl(ctx):
10 for mod in ctx.modules:
11 for archive in mod.tags.archive:
12 _http_ext_delegate(http_archive, archive)
13 
14 for file in mod.tags.file:
15 _http_ext_delegate(http_file, file)
16 
17def _http_ext_delegate(repo_rule, tag_struct):
18 tag_dict = _struct_to_dict(tag_struct)
19 tag_dict["url"] = PROXY_URL + tag_dict["url"]
20 repo_rule(**tag_dict)
21 
22def _struct_to_dict(tag_struct):
23 new_dict = {}
24 for k in dir(tag_struct):
25 new_dict[k] = getattr(tag_struct, k)
26 return new_dict
27 
28# The following content is taken from @bazel_tools//tools/build_defs/repo:http.bzl, with
29# documentation stripped to save space. See <https://bazel.build/rules/lib/repo/http> for docs.
30 
31_http_archive_attrs = tag_class(attrs = {
32 "name": attr.string(),
33 "url": attr.string(),
34 "urls": attr.string_list(),
35 "sha256": attr.string(),
36 "integrity": attr.string(),
37 "netrc": attr.string(),
38 "auth_patterns": attr.string_dict(),
39 "canonical_id": attr.string(),
40 "strip_prefix": attr.string(),
41 "add_prefix": attr.string(
42 default = "",
43 ),
44 "files": attr.string_keyed_label_dict(),
45 "type": attr.string(),
46 "patches": attr.label_list(
47 default = [],
48 ),
49 "remote_file_urls": attr.string_list_dict(
50 default = {},
51 ),
52 "remote_file_integrity": attr.string_dict(
53 default = {},
54 ),
55 "remote_module_file_urls": attr.string_list(
56 default = [],
57 ),
58 "remote_module_file_integrity": attr.string(
59 default = "",
60 ),
61 "remote_patches": attr.string_dict(
62 default = {},
63 ),
64 "remote_patch_strip": attr.int(
65 default = 0,
66 ),
67 "patch_tool": attr.string(
68 default = "",
69 ),
70 "patch_args": attr.string_list(
71 default = [],
72 ),
73 "patch_strip": attr.int(
74 default = 0,
75 ),
76 "patch_cmds": attr.string_list(
77 default = [],
78 ),
79 "patch_cmds_win": attr.string_list(
80 default = [],
81 ),
82 "build_file": attr.label(
83 allow_single_file = True,
84 ),
85 "build_file_content": attr.string(),
86 "workspace_file": attr.label(),
87 "workspace_file_content": attr.string(),
88})
89 
90_http_file_attrs = tag_class(attrs = {
91 "name": attr.string(),
92 "executable": attr.bool(),
93 "downloaded_file_path": attr.string(
94 default = "downloaded",
95 ),
96 "sha256": attr.string(),
97 "integrity": attr.string(),
98 "canonical_id": attr.string(),
99 "url": attr.string(),
100 "urls": attr.string_list(),
101 "netrc": attr.string(),
102 "auth_patterns": attr.string_dict(),
103})
104 
105# Extension definition
106 
107http = module_extension(
108 implementation = _http_ext_impl,
109 tag_classes = {
110 "archive": _http_archive_attrs,
111 "file": _http_file_attrs,
112 },
113)