forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifacts.bzl
80 lines (63 loc) · 2.31 KB
/
artifacts.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
77
78
79
80
# 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//:paths.bzl", "paths")
load(
"@prelude//utils:utils.bzl",
"expect",
)
# A group of artifacts.
ArtifactGroupInfo = provider(
fields = [
"artifacts", # ["artifact"]
],
)
def _from_default_info(dep: "dependency") -> ("artifact", ["_arglike"]):
info = dep[DefaultInfo]
expect(
len(info.default_outputs) == 1,
"expected exactly one default output from {} ({})"
.format(dep, info.default_outputs),
)
return (info.default_outputs[0], info.other_outputs)
def unpack_artifacts(artifacts: [["artifact", "dependency"]]) -> [("artifact", ["_arglike"])]:
"""
Unpack a list of `artifact` and `ArtifactGroupInfo` into a flattened list
of `artifact`s
"""
out = []
for artifact in artifacts:
if type(artifact) == "artifact":
out.append((artifact, []))
continue
if ArtifactGroupInfo in artifact:
for artifact in artifact[ArtifactGroupInfo].artifacts:
out.append((artifact, []))
continue
if DefaultInfo in artifact:
out.append(_from_default_info(artifact))
continue
fail("unexpected dependency type: {}".format(type(artifact)))
return out
def unpack_artifact_map(artifacts: {str.type: ["artifact", "dependency"]}) -> {str.type: ("artifact", ["_arglike"])}:
"""
Unpack a list of `artifact` and `ArtifactGroupInfo` into a flattened list
of `artifact`s
"""
out = {}
for name, artifact in artifacts.items():
if type(artifact) == "artifact":
out[name] = (artifact, [])
continue
if ArtifactGroupInfo in artifact:
for artifact in artifact[ArtifactGroupInfo].artifacts:
out[paths.join(name, artifact.short_path)] = (artifact, [])
continue
if DefaultInfo in artifact:
out[name] = _from_default_info(artifact)
continue
fail("unexpected dependency type: {}".format(type(artifact)))
return out