forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.bzl
51 lines (43 loc) · 1.73 KB
/
resources.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
# 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.
# Resources for transitive deps, shared by C++ and Rust.
ResourceInfo = provider(fields = [
# A map containing all resources from transitive dependencies. The keys
# are rule labels and the values are maps of resource names (the name used
# to lookup the resource at runtime) and the actual resource artifact.
"resources", # {"label": {str.type: ("artifact", ["hidden"])}}
])
def gather_resources(
label: "label",
resources: {str.type: ("artifact", ["_arglike"])} = {},
deps: ["dependency"] = []) -> {"label": {str.type: ("artifact", ["_arglike"])}}:
"""
Return the resources for this rule and its transitive deps.
"""
all_resources = {}
# Resources for self.
if resources:
all_resources[label] = resources
# Merge in resources for deps.
for dep in deps:
if ResourceInfo in dep:
all_resources.update(dep[ResourceInfo].resources)
return all_resources
def create_resource_db(
ctx: "context",
name: str.type,
binary: "artifact",
resources: {str.type: ("artifact", ["_arglike"])}) -> "artifact":
"""
Generate a resource DB for resources for the given binary, relativized to
the binary's working directory.
"""
db = {
name: cmd_args(resource, delimiter = "").relative_to(binary, parent = 1)
for (name, (resource, _other)) in resources.items()
}
return ctx.actions.write_json(name, db)