-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace_config.bzl
76 lines (63 loc) · 2.79 KB
/
workspace_config.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
load("lut.bzl", "hashicorp_to_java_prop")
_HASHICORP_URL = "https://releases.hashicorp.com/{product}/{version}/{product}_{version}_{os}_{arch}.zip"
_HASHIHASH_URL = "https://releases.hashicorp.com/{product}/{version}/{product}_{version}_SHA256SUMS"
def _shas(repository_ctx, hashicorp_product, version):
repository_ctx.download(
url = _HASHIHASH_URL.format(product = hashicorp_product, version = version),
output = "{product}_{version}_shas.txt".format(product = hashicorp_product, version = version),
)
shas = repository_ctx.read(
"{product}_{version}_shas.txt".format(product = hashicorp_product, version = version),
)
fname_lut = {}
for line in shas.split("\n"):
if len(line.split(" ")) == 3:
fname_lut[line.split(" ")[2]] = line.split(" ")[0]
return fname_lut
def _unravel_fname(fn_sha_dict_lst, valid_os, valid_arch):
shas = {}
for elt in fn_sha_dict_lst:
for line, sha in elt.items():
info = line.split("_")
product = info[0]
version = info[1]
os = info[2]
if os != "manifest.json":
os = info[2]
arch = info[3][:-4]
if any([x for x in valid_os[product] if x == hashicorp_to_java_prop(os)]) and any([x for x in valid_arch[product] if x == hashicorp_to_java_prop(arch)]):
export_name = ""
if os == "windows":
export_name = product + ".exe"
else:
export_name = product
shas.setdefault(product, {}).setdefault(version, {}).setdefault(os, {}).setdefault(
arch,
(
sha,
_HASHICORP_URL.format(
product = product,
version = version,
os = os,
arch = arch,
),
export_name,
),
)
return shas
def _hashicorp_configure_impl(repository_ctx):
products = repository_ctx.attr.products.keys()
versions = repository_ctx.attr.products.values()
shas = [_shas(repository_ctx, p, v) for p, v in zip(products, versions) if v != ""]
lut = _unravel_fname(shas, repository_ctx.attr.os, repository_ctx.attr.arch)
config_file_content = "LUT={lut}".format(lut = lut)
repository_ctx.file("config.bzl", config_file_content)
repository_ctx.file("BUILD")
hashicorp_configure = repository_rule(
implementation = _hashicorp_configure_impl,
attrs = {
"products": attr.string_dict(),
"os": attr.string_list_dict(),
"arch": attr.string_list_dict(),
},
)