2020-01-27 18:04:07 +00:00
|
|
|
"""Stateify is a tool for generating state wrappers for Go types."""
|
2018-07-27 17:16:27 +00:00
|
|
|
|
2018-04-27 17:37:02 +00:00
|
|
|
def _go_stateify_impl(ctx):
|
2018-05-03 20:43:20 +00:00
|
|
|
"""Implementation for the stateify tool."""
|
|
|
|
output = ctx.outputs.out
|
2018-04-27 17:37:02 +00:00
|
|
|
|
2018-05-03 20:43:20 +00:00
|
|
|
# Run the stateify command.
|
|
|
|
args = ["-output=%s" % output.path]
|
2020-02-11 19:40:51 +00:00
|
|
|
args.append("-fullpkg=%s" % ctx.attr.package)
|
2018-05-03 20:43:20 +00:00
|
|
|
if ctx.attr._statepkg:
|
2019-12-21 02:07:09 +00:00
|
|
|
args.append("-statepkg=%s" % ctx.attr._statepkg)
|
2018-05-03 20:43:20 +00:00
|
|
|
if ctx.attr.imports:
|
2019-12-21 02:07:09 +00:00
|
|
|
args.append("-imports=%s" % ",".join(ctx.attr.imports))
|
|
|
|
args.append("--")
|
2018-05-03 20:43:20 +00:00
|
|
|
for src in ctx.attr.srcs:
|
2019-06-17 12:12:41 +00:00
|
|
|
args += [f.path for f in src.files.to_list()]
|
2018-05-03 20:43:20 +00:00
|
|
|
ctx.actions.run(
|
|
|
|
inputs = ctx.files.srcs,
|
|
|
|
outputs = [output],
|
|
|
|
mnemonic = "GoStateify",
|
|
|
|
progress_message = "Generating state library %s" % ctx.label,
|
|
|
|
arguments = args,
|
|
|
|
executable = ctx.executable._tool,
|
|
|
|
)
|
2018-04-27 17:37:02 +00:00
|
|
|
|
|
|
|
go_stateify = rule(
|
2018-05-03 20:43:20 +00:00
|
|
|
implementation = _go_stateify_impl,
|
2019-09-12 22:09:01 +00:00
|
|
|
doc = "Generates save and restore logic from a set of Go files.",
|
2018-04-27 17:37:02 +00:00
|
|
|
attrs = {
|
2019-09-12 22:09:01 +00:00
|
|
|
"srcs": attr.label_list(
|
|
|
|
doc = """
|
|
|
|
The input source files. These files should include all structs in the package
|
|
|
|
that need to be saved.
|
|
|
|
""",
|
|
|
|
mandatory = True,
|
|
|
|
allow_files = True,
|
|
|
|
),
|
|
|
|
"imports": attr.string_list(
|
|
|
|
doc = """
|
|
|
|
An optional list of extra non-aliased, Go-style absolute import paths required
|
|
|
|
for statified types.
|
|
|
|
""",
|
|
|
|
mandatory = False,
|
|
|
|
),
|
|
|
|
"package": attr.string(
|
2020-02-11 19:40:51 +00:00
|
|
|
doc = "The fully qualified package name for the input sources.",
|
2019-09-12 22:09:01 +00:00
|
|
|
mandatory = True,
|
|
|
|
),
|
|
|
|
"out": attr.output(
|
2020-02-04 22:36:43 +00:00
|
|
|
doc = "Name of the generator output file.",
|
2019-09-12 22:09:01 +00:00
|
|
|
mandatory = True,
|
|
|
|
),
|
|
|
|
"_tool": attr.label(
|
|
|
|
executable = True,
|
|
|
|
cfg = "host",
|
|
|
|
default = Label("//tools/go_stateify:stateify"),
|
|
|
|
),
|
2019-06-13 23:49:09 +00:00
|
|
|
"_statepkg": attr.string(default = "gvisor.dev/gvisor/pkg/state"),
|
2018-04-27 17:37:02 +00:00
|
|
|
},
|
|
|
|
)
|