forked from frc971/971-Robot-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.bzl
85 lines (78 loc) · 2.72 KB
/
config.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
81
82
83
84
85
load("//tools/build_rules:label.bzl", "expand_label")
AosConfigInfo = provider(fields = [
"transitive_flatbuffers",
"transitive_src",
])
def aos_config(name, src, flatbuffers = [], deps = [], visibility = None, testonly = False, target_compatible_with = None):
_aos_config(
name = name,
src = src,
config_json = name + ".json",
config_stripped = name + ".stripped.json",
config_binary = name + ".bfbs",
deps = deps,
flatbuffers = [expand_label(flatbuffer) + "_reflection_out" for flatbuffer in flatbuffers],
visibility = visibility,
testonly = testonly,
target_compatible_with = target_compatible_with,
)
def _aos_config_impl(ctx):
config = ctx.outputs.config_json
stripped_config = ctx.outputs.config_stripped
binary_config = ctx.outputs.config_binary
flatbuffers_depset = depset(
ctx.files.flatbuffers,
transitive = [dep[AosConfigInfo].transitive_flatbuffers for dep in ctx.attr.deps],
)
src_depset = depset(
ctx.files.src,
transitive = [dep[AosConfigInfo].transitive_src for dep in ctx.attr.deps],
)
all_files = flatbuffers_depset.to_list() + src_depset.to_list()
ctx.actions.run(
outputs = [config, stripped_config, binary_config],
inputs = all_files,
arguments = [
config.path,
stripped_config.path,
binary_config.path,
(ctx.label.workspace_root or ".") + "/" + ctx.files.src[0].short_path,
ctx.bin_dir.path,
] + [f.path for f in flatbuffers_depset.to_list()],
progress_message = "Flattening config",
executable = ctx.executable._config_flattener,
)
runfiles = ctx.runfiles(files = [config, stripped_config, binary_config])
return [
DefaultInfo(
files = depset([config, stripped_config, binary_config]),
runfiles = runfiles,
),
AosConfigInfo(
transitive_flatbuffers = flatbuffers_depset,
transitive_src = src_depset,
),
]
_aos_config = rule(
attrs = {
"config_json": attr.output(mandatory = True),
"config_stripped": attr.output(mandatory = True),
"config_binary": attr.output(mandatory = True),
"_config_flattener": attr.label(
executable = True,
cfg = "host",
default = Label("//aos:config_flattener"),
),
"src": attr.label(
mandatory = True,
allow_files = True,
),
"deps": attr.label_list(
providers = [AosConfigInfo],
),
"flatbuffers": attr.label_list(
mandatory = False,
),
},
implementation = _aos_config_impl,
)