summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorZhaozhong Ni <nzz@google.com>2018-08-03 12:07:57 -0700
committerShentubot <shentubot@google.com>2018-08-03 12:09:13 -0700
commit25178ebdf5e881eae8e81eaf2f69d96de42d2250 (patch)
treec56769ea375733dfdcc70ac68cf5c1c45fb9baa8 /tools
parenta3927157c56cc022cefebc30c8a9b6014f5d0412 (diff)
stateify: make explicit mode no longer optional.
PiperOrigin-RevId: 207303405 Change-Id: I17b6433963d78e3631a862b7ac80f566c8e7d106
Diffstat (limited to 'tools')
-rw-r--r--tools/go_stateify/defs.bzl22
-rw-r--r--tools/go_stateify/main.go32
2 files changed, 29 insertions, 25 deletions
diff --git a/tools/go_stateify/defs.bzl b/tools/go_stateify/defs.bzl
index 2b2582b7a..70ce73d7b 100644
--- a/tools/go_stateify/defs.bzl
+++ b/tools/go_stateify/defs.bzl
@@ -1,7 +1,20 @@
"""Stateify is a tool for generating state wrappers for Go types.
-The go_stateify rule is used to generate a file that will appear in a Go
-target; the output file should appear explicitly in a srcs list. For example:
+The recommended way is to use the go_library rule defined below with mostly
+identical configuration as the native go_library rule.
+
+load("//tools/go_stateify:defs.bzl", "go_library")
+
+go_library(
+ name = "foo",
+ srcs = ["foo.go"],
+)
+
+Under the hood, the go_stateify rule is used to generate a file that will
+appear in a Go target; the output file should appear explicitly in a srcs list.
+For example (the above is still the preferred way):
+
+load("//tools/go_stateify:defs.bzl", "go_stateify")
go_stateify(
name = "foo_state",
@@ -35,8 +48,6 @@ def _go_stateify_impl(ctx):
args += ["-statepkg=%s" % ctx.attr._statepkg]
if ctx.attr.imports:
args += ["-imports=%s" % ",".join(ctx.attr.imports)]
- if ctx.attr.explicit:
- args += ["-explicit=true"]
args += ["--"]
for src in ctx.attr.srcs:
args += [f.path for f in src.files]
@@ -57,7 +68,6 @@ def _go_stateify_impl(ctx):
# imports: an optional list of extra non-aliased, Go-style absolute import paths.
# out: the name of the generated file output. This must not conflict with any other files and must be added to the srcs of the relevant go_library.
# package: the package name for the input sources.
-# explicit: only generate for types explicitly annotated as savable.
go_stateify = rule(
implementation = _go_stateify_impl,
attrs = {
@@ -65,7 +75,6 @@ go_stateify = rule(
"imports": attr.string_list(mandatory = False),
"package": attr.string(mandatory = True),
"out": attr.output(mandatory = True),
- "explicit": attr.bool(default = False),
"_tool": attr.label(executable = True, cfg = "host", default = Label("//tools/go_stateify:stateify")),
"_statepkg": attr.string(default = "gvisor.googlesource.com/gvisor/pkg/state"),
},
@@ -81,7 +90,6 @@ def go_library(name, srcs, deps = [], imports = [], **kwargs):
imports = imports,
package = name,
out = name + "_state_autogen.go",
- explicit = True,
)
all_srcs = srcs + [name + "_state_autogen.go"]
if "//pkg/state" not in deps:
diff --git a/tools/go_stateify/main.go b/tools/go_stateify/main.go
index 231c6d80b..5646b879a 100644
--- a/tools/go_stateify/main.go
+++ b/tools/go_stateify/main.go
@@ -33,7 +33,6 @@ var (
imports = flag.String("imports", "", "extra imports for the output file")
output = flag.String("output", "", "output file")
statePkg = flag.String("statepkg", "", "state import package; defaults to empty")
- explicit = flag.Bool("explicit", false, "only generate for types explicitly tagged '// +stateify savable'")
)
// resolveTypeName returns a qualified type name.
@@ -318,25 +317,22 @@ func main() {
continue
}
- if *explicit {
- // In explicit mode, only generate code for
- // types explicitly marked
- // "// +stateify savable" in one of the
- // proceeding comment lines.
- if d.Doc == nil {
- continue
- }
- savable := false
- for _, l := range d.Doc.List {
- if l.Text == "// +stateify savable" {
- savable = true
- break
- }
- }
- if !savable {
- continue
+ // Only generate code for types marked
+ // "// +stateify savable" in one of the proceeding
+ // comment lines.
+ if d.Doc == nil {
+ continue
+ }
+ savable := false
+ for _, l := range d.Doc.List {
+ if l.Text == "// +stateify savable" {
+ savable = true
+ break
}
}
+ if !savable {
+ continue
+ }
for _, gs := range d.Specs {
ts := gs.(*ast.TypeSpec)