bump(k8s.io/gengo):c118aa8edfff53fe5b69127a970f54b6cf3a7563

This commit is contained in:
Clayton Coleman 2017-01-23 14:25:37 -05:00
parent df831db360
commit c5059bd772
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
4 changed files with 57 additions and 33 deletions

20
Godeps/Godeps.json generated
View File

@ -2663,43 +2663,43 @@
}, },
{ {
"ImportPath": "k8s.io/gengo/args", "ImportPath": "k8s.io/gengo/args",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/import-boss/generators", "ImportPath": "k8s.io/gengo/examples/import-boss/generators",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/generators", "ImportPath": "k8s.io/gengo/examples/set-gen/generators",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/sets", "ImportPath": "k8s.io/gengo/examples/set-gen/sets",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/generator", "ImportPath": "k8s.io/gengo/generator",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/namer", "ImportPath": "k8s.io/gengo/namer",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/parser", "ImportPath": "k8s.io/gengo/parser",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/gengo/types", "ImportPath": "k8s.io/gengo/types",
"Rev": "3c6a809462caf39389d70d9ea787ed24c5acffed" "Rev": "c118aa8edfff53fe5b69127a970f54b6cf3a7563"
}, },
{ {
"ImportPath": "k8s.io/heapster/metrics/api/v1/types", "ImportPath": "k8s.io/heapster/metrics/api/v1/types",

View File

@ -184,10 +184,25 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
if pkgNeedsGeneration { if pkgNeedsGeneration {
glog.V(3).Infof("Package %q needs generation", i) glog.V(3).Infof("Package %q needs generation", i)
path := pkg.Path
// if the source path is within a /vendor/ directory (for example,
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1), allow
// generation to output to the proper relative path (under vendor).
// Otherwise, the generator will create the file in the wrong location
// in the output directory.
// TODO: build a more fundamental concept in gengo for dealing with modifications
// to vendored packages.
if strings.HasPrefix(pkg.SourcePath, arguments.OutputBase) {
expandedPath := strings.TrimPrefix(pkg.SourcePath, arguments.OutputBase)
if strings.Contains(expandedPath, "/vendor/") {
path = expandedPath
glog.V(3).Infof(" %s", path)
}
}
packages = append(packages, packages = append(packages,
&generator.DefaultPackage{ &generator.DefaultPackage{
PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0], PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0],
PackagePath: pkg.Path, PackagePath: path,
HeaderText: header, HeaderText: header,
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
return []generator.Generator{ return []generator.Generator{
@ -524,15 +539,25 @@ func (g *genDeepCopy) doMap(t *types.Type, sw *generator.SnippetWriter) {
} }
func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) { func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) {
if hasDeepCopyMethod(t) {
sw.Do("*out = in.DeepCopy()\n", nil)
return
}
sw.Do("*out = make($.|raw$, len(*in))\n", t) sw.Do("*out = make($.|raw$, len(*in))\n", t)
if t.Elem.Kind == types.Builtin { if hasDeepCopyMethod(t.Elem) {
sw.Do("for i := range *in {\n", nil)
sw.Do("(*out)[i] = (*in)[i].DeepCopy()\n", nil)
sw.Do("}\n", nil)
} else if t.Elem.Kind == types.Builtin || t.Elem.IsAssignable() {
sw.Do("copy(*out, *in)\n", nil) sw.Do("copy(*out, *in)\n", nil)
} else { } else {
sw.Do("for i := range *in {\n", nil) sw.Do("for i := range *in {\n", nil)
if hasDeepCopyMethod(t.Elem) { if t.Elem.Kind == types.Slice {
sw.Do("(*out)[i] = (*in)[i].DeepCopy()\n", nil) sw.Do("if (*in)[i] != nil {\n", nil)
} else if t.Elem.IsAssignable() { sw.Do("in, out := &(*in)[i], &(*out)[i]\n", nil)
sw.Do("(*out)[i] = (*in)[i]\n", nil) g.generateFor(t.Elem, sw)
sw.Do("}\n", nil)
} else if g.copyableAndInBounds(t.Elem) { } else if g.copyableAndInBounds(t.Elem) {
sw.Do("if err := $.type|dcFnName$(&(*in)[i], &(*out)[i], c); err != nil {\n", argsFromType(t.Elem)) sw.Do("if err := $.type|dcFnName$(&(*in)[i], &(*out)[i], c); err != nil {\n", argsFromType(t.Elem))
sw.Do("return err\n", nil) sw.Do("return err\n", nil)
@ -582,7 +607,7 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args) sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
sw.Do("}\n", nil) sw.Do("}\n", nil)
} else { } else {
// Fixup non-nil reference-sematic types. // Fixup non-nil reference-semantic types.
sw.Do("if in.$.name$ != nil {\n", args) sw.Do("if in.$.name$ != nil {\n", args)
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args) sw.Do("in, out := &in.$.name$, &out.$.name$\n", args)
g.generateFor(t, sw) g.generateFor(t, sw)

13
vendor/k8s.io/gengo/parser/parse.go generated vendored
View File

@ -695,16 +695,16 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
} }
return out return out
case *tc.Named: case *tc.Named:
var out *types.Type
switch t.Underlying().(type) { switch t.Underlying().(type) {
case *tc.Named, *tc.Basic, *tc.Map, *tc.Slice: case *tc.Named, *tc.Basic, *tc.Map, *tc.Slice:
name := tcNameToName(t.String()) name := tcNameToName(t.String())
out := u.Type(name) out = u.Type(name)
if out.Kind != types.Unknown { if out.Kind != types.Unknown {
return out return out
} }
out.Kind = types.Alias out.Kind = types.Alias
out.Underlying = b.walkType(u, nil, t.Underlying()) out.Underlying = b.walkType(u, nil, t.Underlying())
return out
default: default:
// tc package makes everything "named" with an // tc package makes everything "named" with an
// underlying anonymous type--we remove that annoying // underlying anonymous type--we remove that annoying
@ -714,11 +714,11 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
if out := u.Type(name); out.Kind != types.Unknown { if out := u.Type(name); out.Kind != types.Unknown {
return out // short circuit if we've already made this. return out // short circuit if we've already made this.
} }
out := b.walkType(u, &name, t.Underlying()) out = b.walkType(u, &name, t.Underlying())
}
// If the underlying type didn't already add methods, add them.
// (Interface types will have already added methods.)
if len(out.Methods) == 0 { if len(out.Methods) == 0 {
// If the underlying type didn't already add
// methods, add them. (Interface types will
// have already added methods.)
for i := 0; i < t.NumMethods(); i++ { for i := 0; i < t.NumMethods(); i++ {
if out.Methods == nil { if out.Methods == nil {
out.Methods = map[string]*types.Type{} out.Methods = map[string]*types.Type{}
@ -727,7 +727,6 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
} }
} }
return out return out
}
default: default:
out := u.Type(name) out := u.Type(name)
if out.Kind != types.Unknown { if out.Kind != types.Unknown {

2
vendor/k8s.io/gengo/types/types.go generated vendored
View File

@ -163,7 +163,7 @@ func (p *Package) Function(funcName string) *Type {
return t return t
} }
// Variable gets the given varaible Type in this Package. If the variable is // Variable gets the given variable Type in this Package. If the variable is
// not already defined, this will add it. If a variable is added, it's the caller's // not already defined, this will add it. If a variable is added, it's the caller's
// responsibility to finish construction of the variable by setting Underlying // responsibility to finish construction of the variable by setting Underlying
// to the correct type. // to the correct type.