-
Notifications
You must be signed in to change notification settings - Fork 34
/
resources.bzl
53 lines (44 loc) · 1.75 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
52
53
# 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//:artifacts.bzl", "ArtifactOutputs")
# 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": provider_field(dict[Label, dict[str, ArtifactOutputs]]),
})
def gather_resources(
label: Label,
resources: dict[str, ArtifactOutputs] = {},
deps: list[Dependency] = []) -> dict[Label, dict[str, ArtifactOutputs]]:
"""
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: AnalysisContext,
name: str,
binary: Artifact,
resources: dict[str, ArtifactOutputs]) -> Artifact:
"""
Generate a resource DB for resources for the given binary, relativized to
the binary's working directory.
"""
db = {
name: cmd_args(resource.default_output, delimiter = "", relative_to = (binary, 1))
for (name, resource) in resources.items()
}
return ctx.actions.write_json(name, db)