github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/go_stateify/defs.bzl (about)

     1  """Stateify is a tool for generating state wrappers for Go types."""
     2  
     3  def _go_stateify_impl(ctx):
     4      """Implementation for the stateify tool."""
     5      output = ctx.outputs.out
     6  
     7      # Run the stateify command.
     8      args = ["-output=%s" % output.path]
     9      args.append("-fullpkg=%s" % ctx.attr.package)
    10      if ctx.attr._statepkg:
    11          args.append("-statepkg=%s" % ctx.attr._statepkg)
    12      if ctx.attr.imports:
    13          args.append("-imports=%s" % ",".join(ctx.attr.imports))
    14      args.append("--")
    15      for src in ctx.attr.srcs:
    16          args += [f.path for f in src.files.to_list()]
    17      ctx.actions.run(
    18          inputs = ctx.files.srcs,
    19          outputs = [output],
    20          mnemonic = "GoStateify",
    21          progress_message = "Generating state library %s" % ctx.label,
    22          arguments = args,
    23          executable = ctx.executable._tool,
    24      )
    25  
    26  go_stateify = rule(
    27      implementation = _go_stateify_impl,
    28      doc = "Generates save and restore logic from a set of Go files.",
    29      attrs = {
    30          "srcs": attr.label_list(
    31              doc = """
    32  The input source files. These files should include all structs in the package
    33  that need to be saved.
    34  """,
    35              mandatory = True,
    36              allow_files = True,
    37          ),
    38          "imports": attr.string_list(
    39              doc = """
    40  An optional list of extra non-aliased, Go-style absolute import paths required
    41  for statified types.
    42  """,
    43              mandatory = False,
    44          ),
    45          "package": attr.string(
    46              doc = "The fully qualified package name for the input sources.",
    47              mandatory = True,
    48          ),
    49          "out": attr.output(
    50              doc = "Name of the generator output file.",
    51              mandatory = True,
    52          ),
    53          "_tool": attr.label(
    54              executable = True,
    55              cfg = "host",
    56              default = Label("//tools/go_stateify:stateify"),
    57          ),
    58          "_statepkg": attr.string(default = "gvisor.dev/gvisor/pkg/state"),
    59      },
    60  )