diff options
Diffstat (limited to 'tools/go_generics')
-rw-r--r-- | tools/go_generics/defs.bzl | 4 | ||||
-rw-r--r-- | tools/go_generics/generics.go | 2 | ||||
-rw-r--r-- | tools/go_generics/go_merge/BUILD | 3 | ||||
-rw-r--r-- | tools/go_generics/go_merge/main.go | 19 | ||||
-rw-r--r-- | tools/go_generics/tests/all_stmts/input.go | 2 | ||||
-rw-r--r-- | tools/go_generics/tests/all_stmts/output.go | 2 | ||||
-rw-r--r-- | tools/go_generics/tests/all_types/lib/lib.go | 1 |
7 files changed, 25 insertions, 8 deletions
diff --git a/tools/go_generics/defs.bzl b/tools/go_generics/defs.bzl index ad97208a8..50e2546bf 100644 --- a/tools/go_generics/defs.bzl +++ b/tools/go_generics/defs.bzl @@ -67,7 +67,7 @@ def _go_template_instance_impl(ctx): # Check that all defined types are expected by the template. for t in ctx.attr.types: if (t not in info.types) and (t not in info.opt_types): - fail("Type %s it not a parameter to %s" % (t, ctx.attr.template.label)) + fail("Type %s is not a parameter to %s" % (t, ctx.attr.template.label)) # Check that all required consts are defined. for t in info.consts: @@ -77,7 +77,7 @@ def _go_template_instance_impl(ctx): # Check that all defined consts are expected by the template. for t in ctx.attr.consts: if (t not in info.consts) and (t not in info.opt_consts): - fail("Const %s it not a parameter to %s" % (t, ctx.attr.template.label)) + fail("Const %s is not a parameter to %s" % (t, ctx.attr.template.label)) # Build the argument list. args = ["-i=%s" % info.template.path, "-o=%s" % output.path] diff --git a/tools/go_generics/generics.go b/tools/go_generics/generics.go index 0860ca9db..30584006c 100644 --- a/tools/go_generics/generics.go +++ b/tools/go_generics/generics.go @@ -223,7 +223,7 @@ func main() { } else { switch kind { case globals.KindType, globals.KindVar, globals.KindConst, globals.KindFunction: - if ident.Name != "_" { + if ident.Name != "_" && !(ident.Name == "init" && kind == globals.KindFunction) { ident.Name = *prefix + ident.Name + *suffix } case globals.KindTag: diff --git a/tools/go_generics/go_merge/BUILD b/tools/go_generics/go_merge/BUILD index 2fd5a200d..5e0487e93 100644 --- a/tools/go_generics/go_merge/BUILD +++ b/tools/go_generics/go_merge/BUILD @@ -6,4 +6,7 @@ go_binary( name = "go_merge", srcs = ["main.go"], visibility = ["//:sandbox"], + deps = [ + "//tools/tags", + ], ) diff --git a/tools/go_generics/go_merge/main.go b/tools/go_generics/go_merge/main.go index e0345500f..801f2354f 100644 --- a/tools/go_generics/go_merge/main.go +++ b/tools/go_generics/go_merge/main.go @@ -22,10 +22,12 @@ import ( "go/format" "go/parser" "go/token" - "io/ioutil" "os" "path/filepath" "strconv" + "strings" + + "gvisor.dev/gvisor/tools/tags" ) var ( @@ -132,10 +134,17 @@ func main() { // Write the output file. var buf bytes.Buffer if err := format.Node(&buf, fset, f); err != nil { - fatalf("%v\n", err) + fatalf("fomatting: %v\n", err) } - - if err := ioutil.WriteFile(*output, buf.Bytes(), 0644); err != nil { - fatalf("%v\n", err) + outf, err := os.OpenFile(*output, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + fatalf("opening output: %v\n", err) + } + defer outf.Close() + if t := tags.Aggregate(flag.Args()); len(t) > 0 { + fmt.Fprintf(outf, "%s\n\n", strings.Join(t.Lines(), "\n")) + } + if _, err := outf.Write(buf.Bytes()); err != nil { + fatalf("write: %v\n", err) } } diff --git a/tools/go_generics/tests/all_stmts/input.go b/tools/go_generics/tests/all_stmts/input.go index 4791d1ff1..7ebe7c40e 100644 --- a/tools/go_generics/tests/all_stmts/input.go +++ b/tools/go_generics/tests/all_stmts/input.go @@ -118,8 +118,10 @@ R: _ = v } else if T := T(0); T != 1 { T++ + _ = T } else { T-- + _ = T } if a := T(0); a != T(1) { diff --git a/tools/go_generics/tests/all_stmts/output.go b/tools/go_generics/tests/all_stmts/output.go index a53d84535..a33944d85 100644 --- a/tools/go_generics/tests/all_stmts/output.go +++ b/tools/go_generics/tests/all_stmts/output.go @@ -116,8 +116,10 @@ R: _ = v } else if T := Q(0); T != 1 { T++ + _ = T } else { T-- + _ = T } if a := Q(0); a != Q(1) { diff --git a/tools/go_generics/tests/all_types/lib/lib.go b/tools/go_generics/tests/all_types/lib/lib.go index 988786496..99edb371f 100644 --- a/tools/go_generics/tests/all_types/lib/lib.go +++ b/tools/go_generics/tests/all_types/lib/lib.go @@ -14,4 +14,5 @@ package lib +// T is a test type. type T int32 |