-
Notifications
You must be signed in to change notification settings - Fork 35
/
remote_file.bzl
68 lines (58 loc) · 2.03 KB
/
remote_file.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
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@prelude//:http_file.bzl", "http_file_shared")
load("@prelude//utils:expect.bzl", "expect")
load("@prelude//utils:utils.bzl", "value_or")
_ROOT = "https://maven.thefacebook.com/nexus/content/groups/public"
def _from_mvn_url(url: str) -> str:
"""
Convert `mvn:` style URIs to a URL.
"""
count = url.count(":")
mod = ""
if count == 4:
mvn, group, id, typ, version = url.split(":")
repo = _ROOT
elif count == 5:
mvn, group, id, typ, mod, version = url.split(":")
mod = "-" + mod
repo = _ROOT
elif count == 6:
mvn, repo_protocol, repo_host, group, id, typ, version = url.split(":")
repo = repo_protocol + ":" + repo_host
else:
fail("Unsupported mvn URL scheme: " + url + " (" + str(count) + ")")
expect(mvn == "mvn")
group = group.replace(".", "/")
if typ == "src":
ext = "-sources.jar"
else:
ext = "." + typ
return "{repo}/{group}/{id}/{version}/{id}-{version}{mod}{ext}".format(
repo = repo,
group = group,
id = id,
version = version,
ext = ext,
mod = mod,
)
# Implementation of the `remote_file` build rule.
def remote_file_impl(ctx: AnalysisContext) -> list[Provider]:
url = ctx.attrs.url
if url.startswith("mvn:"):
url = _from_mvn_url(url)
return http_file_shared(
ctx.actions,
name = value_or(ctx.attrs.out, ctx.label.name),
url = url,
vpnless_url = ctx.attrs.vpnless_url,
is_executable = ctx.attrs.type == "executable",
is_exploded_zip = ctx.attrs.type == "exploded_zip",
unzip_tool = ctx.attrs._unzip_tool[RunInfo],
sha1 = ctx.attrs.sha1,
sha256 = ctx.attrs.sha256,
)