forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_file.bzl
More file actions
79 lines (68 loc) · 2.56 KB
/
Copy pathremote_file.bzl
File metadata and controls
79 lines (68 loc) · 2.56 KB
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
77
78
79
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is dual-licensed under either the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree or the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree. You may select, at your option, one of the
# above-listed licenses.
load("@prelude//:http_file.bzl", "http_file_shared")
load("@prelude//utils:expect.bzl", "expect")
load("@prelude//utils:utils.bzl", "value_or")
_DEFAULT_MAVEN_REPO = read_config("http", "maven_repo", "https://repo1.maven.org/maven2")
_MAVEN_REPO_OVERRIDE = read_config("http", "maven_repo_override")
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 = _DEFAULT_MAVEN_REPO
elif count == 5:
mvn, group, id, typ, mod, version = url.split(":")
mod = "-" + mod
repo = _DEFAULT_MAVEN_REPO
elif count == 6:
mvn, repo_protocol, repo_host, group, id, typ, version = url.split(":")
repo = repo_protocol + ":" + repo_host
elif count == 7:
mvn, repo_protocol, repo_host, group, id, typ, mod, version = url.split(":")
mod = "-" + mod
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
if _MAVEN_REPO_OVERRIDE:
repo = _MAVEN_REPO_OVERRIDE
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,
size_bytes = ctx.attrs.size_bytes,
has_content_based_path = ctx.attrs.has_content_based_path,
)