-
Notifications
You must be signed in to change notification settings - Fork 34
/
http_file.bzl
68 lines (63 loc) · 2.23 KB
/
http_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//utils:expect.bzl", "expect")
load("@prelude//utils:utils.bzl", "value_or")
def http_file_shared(
actions: AnalysisActions,
name: str,
url: str,
vpnless_url: [None, str],
is_executable: bool,
is_exploded_zip: bool,
unzip_tool: [RunInfo, None],
sha1: [None, str],
sha256 = [None, str]) -> list[Provider]:
output = actions.declare_output(name)
downloaded_output = actions.declare_output("exploded_zip") if is_exploded_zip else output
actions.download_file(
downloaded_output,
url,
vpnless_url = vpnless_url,
is_executable = is_executable,
sha1 = sha1,
sha256 = sha256,
is_deferrable = True,
)
if is_exploded_zip:
actions.run(
cmd_args([
unzip_tool,
"--src",
downloaded_output,
"--dst",
output.as_output(),
]),
category = "exploded_zip_unzip",
local_only = sha1 == None,
)
providers = [DefaultInfo(default_output = output)]
if is_executable:
providers.append(RunInfo(args = [output]))
return providers
def http_file_impl(ctx: AnalysisContext) -> list[Provider]:
expect(len(ctx.attrs.urls) == 1, "multiple `urls` not supported: {}", ctx.attrs.urls)
expect(len(ctx.attrs.vpnless_urls) < 2, "multiple `vpnless_urls` not supported: {}", ctx.attrs.vpnless_urls)
if len(ctx.attrs.vpnless_urls) > 0:
vpnless_url = ctx.attrs.vpnless_urls[0]
else:
vpnless_url = None
return http_file_shared(
ctx.actions,
name = value_or(ctx.attrs.out, ctx.label.name),
url = ctx.attrs.urls[0],
vpnless_url = vpnless_url,
sha1 = ctx.attrs.sha1,
sha256 = ctx.attrs.sha256,
is_executable = ctx.attrs.executable or False,
is_exploded_zip = False,
unzip_tool = None,
)