Commit ae2d4b3c authored by deads2k's avatar deads2k

bump(k8s.io/gengo): 8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21

parent 8ef69025
...@@ -2669,43 +2669,43 @@ ...@@ -2669,43 +2669,43 @@
}, },
{ {
"ImportPath": "k8s.io/gengo/args", "ImportPath": "k8s.io/gengo/args",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/import-boss/generators", "ImportPath": "k8s.io/gengo/examples/import-boss/generators",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/generators", "ImportPath": "k8s.io/gengo/examples/set-gen/generators",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/sets", "ImportPath": "k8s.io/gengo/examples/set-gen/sets",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/generator", "ImportPath": "k8s.io/gengo/generator",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/namer", "ImportPath": "k8s.io/gengo/namer",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/parser", "ImportPath": "k8s.io/gengo/parser",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/gengo/types", "ImportPath": "k8s.io/gengo/types",
"Rev": "6a1c24d7f08e671c244023ca9367d2dfbfaf57fc" "Rev": "8dd9c9e5e82c3cca687497c3cd7ac90e702c7c21"
}, },
{ {
"ImportPath": "k8s.io/heapster/metrics/api/v1/types", "ImportPath": "k8s.io/heapster/metrics/api/v1/types",
......
...@@ -124,14 +124,16 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -124,14 +124,16 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
inputs := sets.NewString(context.Inputs...) inputs := sets.NewString(context.Inputs...)
packages := generator.Packages{} packages := generator.Packages{}
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...) header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
header = append(header, []byte( header = append(header, []byte(`
` // This file was autogenerated by deepcopy-gen. Do not edit it manually!
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
`)...) `)...)
boundingDirs := []string{} boundingDirs := []string{}
if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok {
if customArgs.BoundingDirs == nil {
customArgs.BoundingDirs = context.Inputs
}
for i := range customArgs.BoundingDirs { for i := range customArgs.BoundingDirs {
// Strip any trailing slashes - they are not exactly "correct" but // Strip any trailing slashes - they are not exactly "correct" but
// this is friendlier. // this is friendlier.
...@@ -140,7 +142,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -140,7 +142,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
} }
for i := range inputs { for i := range inputs {
glog.V(5).Infof("considering pkg %q", i) glog.V(5).Infof("Considering pkg %q", i)
pkg := context.Universe[i] pkg := context.Universe[i]
if pkg == nil { if pkg == nil {
// If the input had no Go files, for example. // If the input had no Go files, for example.
...@@ -181,16 +183,16 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -181,16 +183,16 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
} }
if pkgNeedsGeneration { if pkgNeedsGeneration {
glog.V(3).Infof("Package %q needs generation", i)
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: pkg.Path,
HeaderText: header, HeaderText: header,
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
generators = []generator.Generator{} return []generator.Generator{
generators = append( NewGenDeepCopy(arguments.OutputFileBaseName, pkg.Path, boundingDirs, (ptagValue == tagValuePackage), ptagRegister),
generators, NewGenDeepCopy(arguments.OutputFileBaseName, pkg.Path, boundingDirs, (ptagValue == tagValuePackage), ptagRegister)) }
return generators
}, },
FilterFunc: func(c *generator.Context, t *types.Type) bool { FilterFunc: func(c *generator.Context, t *types.Type) bool {
return t.Name.Package == pkg.Path return t.Name.Package == pkg.Path
...@@ -202,7 +204,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -202,7 +204,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
} }
const ( const (
apiPackagePath = "k8s.io/kubernetes/pkg/api"
conversionPackagePath = "k8s.io/kubernetes/pkg/conversion" conversionPackagePath = "k8s.io/kubernetes/pkg/conversion"
runtimePackagePath = "k8s.io/kubernetes/pkg/runtime" runtimePackagePath = "k8s.io/kubernetes/pkg/runtime"
) )
...@@ -253,11 +254,16 @@ func (g *genDeepCopy) Filter(c *generator.Context, t *types.Type) bool { ...@@ -253,11 +254,16 @@ func (g *genDeepCopy) Filter(c *generator.Context, t *types.Type) bool {
enabled = true enabled = true
} }
} }
copyable := enabled && copyableType(t) if !enabled {
if copyable { return false
g.typesForInit = append(g.typesForInit, t)
} }
return copyable if !copyableType(t) {
glog.V(2).Infof("Type %v is not copyable", t)
return false
}
glog.V(4).Infof("Type %v is copyable", t)
g.typesForInit = append(g.typesForInit, t)
return true
} }
func (g *genDeepCopy) copyableAndInBounds(t *types.Type) bool { func (g *genDeepCopy) copyableAndInBounds(t *types.Type) bool {
...@@ -368,12 +374,20 @@ func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error { ...@@ -368,12 +374,20 @@ func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"}) cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"})
g.imports.AddType(cloner) g.imports.AddType(cloner)
if !g.registerTypes { if !g.registerTypes {
// TODO: We should come up with a solution to register all generated sw := generator.NewSnippetWriter(w, c, "$", "$")
// deep-copy functions. However, for now, to avoid import cycles sw.Do("// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.\n", nil)
// we register only those explicitly requested. sw.Do("func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc{\n", nil)
return nil sw.Do("return []conversion.GeneratedDeepCopyFunc{\n", nil)
for _, t := range g.typesForInit {
args := argsFromType(t).
With("typeof", c.Universe.Package("reflect").Function("TypeOf"))
sw.Do("{Fn: $.type|dcFnName$, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do("}\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
} }
glog.V(5).Infof("registering types in pkg %q", g.targetPackage) glog.V(5).Infof("Registering types in pkg %q", g.targetPackage)
sw := generator.NewSnippetWriter(w, c, "$", "$") sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil) sw.Do("func init() {\n", nil)
...@@ -410,12 +424,12 @@ func (g *genDeepCopy) needsGeneration(t *types.Type) bool { ...@@ -410,12 +424,12 @@ func (g *genDeepCopy) needsGeneration(t *types.Type) bool {
} }
if g.allTypes && tv == "false" { if g.allTypes && tv == "false" {
// The whole package is being generated, but this type has opted out. // The whole package is being generated, but this type has opted out.
glog.V(5).Infof("not generating for type %v because type opted out", t) glog.V(5).Infof("Not generating for type %v because type opted out", t)
return false return false
} }
if !g.allTypes && tv != "true" { if !g.allTypes && tv != "true" {
// The whole package is NOT being generated, and this type has NOT opted in. // The whole package is NOT being generated, and this type has NOT opted in.
glog.V(5).Infof("not generating for type %v because type did not opt in", t) glog.V(5).Infof("Not generating for type %v because type did not opt in", t)
return false return false
} }
return true return true
...@@ -425,7 +439,7 @@ func (g *genDeepCopy) GenerateType(c *generator.Context, t *types.Type, w io.Wri ...@@ -425,7 +439,7 @@ func (g *genDeepCopy) GenerateType(c *generator.Context, t *types.Type, w io.Wri
if !g.needsGeneration(t) { if !g.needsGeneration(t) {
return nil return nil
} }
glog.V(5).Infof("generating for type %v", t) glog.V(5).Infof("Generating deepcopy function for type %v", t)
sw := generator.NewSnippetWriter(w, c, "$", "$") sw := generator.NewSnippetWriter(w, c, "$", "$")
args := argsFromType(t). args := argsFromType(t).
...@@ -535,12 +549,18 @@ func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) { ...@@ -535,12 +549,18 @@ func (g *genDeepCopy) doSlice(t *types.Type, sw *generator.SnippetWriter) {
} }
func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) { func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
if len(t.Members) == 0 { if hasDeepCopyMethod(t) {
// at least do something with in/out to avoid "declared and not used" errors sw.Do("*out = in.DeepCopy()\n", nil)
sw.Do("_ = in\n_ = out\n", nil) return
} }
// Simple copy covers a lot of cases.
sw.Do("*out = *in\n", nil)
// Now fix-up fields as needed.
for _, m := range t.Members { for _, m := range t.Members {
t := m.Type t := m.Type
hasMethod := hasDeepCopyMethod(t)
if t.Kind == types.Alias { if t.Kind == types.Alias {
copied := *t.Underlying copied := *t.Underlying
copied.Name = t.Name copied.Name = t.Name
...@@ -548,28 +568,40 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) { ...@@ -548,28 +568,40 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
} }
args := generator.Args{ args := generator.Args{
"type": t, "type": t,
"kind": t.Kind,
"name": m.Name, "name": m.Name,
} }
switch t.Kind { switch t.Kind {
case types.Builtin: case types.Builtin:
sw.Do("out.$.name$ = in.$.name$\n", args) if hasMethod {
sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
}
case types.Map, types.Slice, types.Pointer: case types.Map, types.Slice, types.Pointer:
sw.Do("if in.$.name$ != nil {\n", args) if hasMethod {
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args) sw.Do("if in.$.name$ != nil {\n", args)
g.generateFor(t, sw) sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
sw.Do("} else {\n", nil) sw.Do("}\n", nil)
sw.Do("out.$.name$ = nil\n", args) } else {
sw.Do("}\n", nil) // Fixup non-nil reference-sematic types.
sw.Do("if in.$.name$ != nil {\n", args)
sw.Do("in, out := &in.$.name$, &out.$.name$\n", args)
g.generateFor(t, sw)
sw.Do("}\n", nil)
}
case types.Struct: case types.Struct:
if hasDeepCopyMethod(t) { if hasMethod {
sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args) sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
} else if t.IsAssignable() { } else if t.IsAssignable() {
sw.Do("out.$.name$ = in.$.name$\n", args) // Nothing else needed.
} else if g.copyableAndInBounds(t) { } else if g.copyableAndInBounds(t) {
// Not assignable but should have a deepcopy function.
// TODO: do a topological sort of packages and ensure that this works, else inline it.
sw.Do("if err := $.type|dcFnName$(&in.$.name$, &out.$.name$, c); err != nil {\n", args) sw.Do("if err := $.type|dcFnName$(&in.$.name$, &out.$.name$, c); err != nil {\n", args)
sw.Do("return err\n", nil) sw.Do("return err\n", nil)
sw.Do("}\n", nil) sw.Do("}\n", nil)
} else { } else {
// Fall back on the slow-path and hope it works.
// TODO: don't depend on kubernetes code for this
sw.Do("if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args) sw.Do("if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args)
sw.Do("return err\n", nil) sw.Do("return err\n", nil)
sw.Do("} else {\n", nil) sw.Do("} else {\n", nil)
...@@ -577,13 +609,22 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) { ...@@ -577,13 +609,22 @@ func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) {
sw.Do("}\n", nil) sw.Do("}\n", nil)
} }
default: default:
sw.Do("if in.$.name$ == nil {\n", args) // Interfaces, Arrays, and other Kinds we don't understand.
sw.Do("out.$.name$ = nil\n", args) sw.Do("// in.$.name$ is kind '$.kind$'\n", args)
sw.Do("} else if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args) if hasMethod {
sw.Do("return err\n", nil) sw.Do("if in.$.name$ != nil {\n", args)
sw.Do("} else {\n", nil) sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args) sw.Do("}\n", args)
sw.Do("}\n", nil) } else {
// TODO: don't depend on kubernetes code for this
sw.Do("if in.$.name$ != nil {\n", args)
sw.Do("if newVal, err := c.DeepCopy(&in.$.name$); err != nil {\n", args)
sw.Do("return err\n", nil)
sw.Do("} else {\n", nil)
sw.Do("out.$.name$ = *newVal.(*$.type|raw$)\n", args)
sw.Do("}\n", nil)
sw.Do("}\n", nil)
}
} }
} }
} }
......
...@@ -323,7 +323,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat ...@@ -323,7 +323,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
if len(newDefaulters) == 0 { if len(newDefaulters) == 0 {
glog.V(5).Infof("no defaulters in package %s", pkg.Name) glog.V(5).Infof("no defaulters in package %s", pkg.Name)
continue
} }
packages = append(packages, packages = append(packages,
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
/* /*
Copyright 2016 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment