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
|
"""The go_fieldenum target infers Field, Fields, and FieldSet types for each
struct in an input source file marked +fieldenum.
"""
def _go_fieldenum_impl(ctx):
output = ctx.outputs.out
args = ["-pkg=%s" % ctx.attr.package, "-out=%s" % output.path]
for src in ctx.attr.srcs:
args += [f.path for f in src.files.to_list()]
ctx.actions.run(
inputs = ctx.files.srcs,
outputs = [output],
mnemonic = "GoFieldenum",
progress_message = "Generating Go field enumerators %s" % ctx.label,
arguments = args,
executable = ctx.executable._tool,
)
go_fieldenum = rule(
implementation = _go_fieldenum_impl,
attrs = {
"srcs": attr.label_list(doc = "input source files", mandatory = True, allow_files = True),
"package": attr.string(doc = "the package for the generated source file", mandatory = True),
"out": attr.output(doc = "output file", mandatory = True),
"_tool": attr.label(executable = True, cfg = "host", default = Label("//tools/go_fieldenum:fieldenum")),
},
)
|