Skip to content

Commit

Permalink
Merge pull request #67 from sttts/sttts-remove-registration
Browse files Browse the repository at this point in the history
deepcopy: remove legacy scheme registration
  • Loading branch information
thockin authored Nov 9, 2017
2 parents 2da3816 + 07f81ea commit b58fc7e
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 274 deletions.
55 changes: 1 addition & 54 deletions examples/deepcopy-gen/generators/deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,60 +369,7 @@ func argsFromType(ts ...*types.Type) generator.Args {
}

func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
glog.V(5).Infof("Registering types in pkg %q", g.targetPackage)

// the legacy restration will go away when the cloner is removed from Kubernetes, replaced
// with static function calls to the DeepCopy methods.
return g.legacyRegistration(c, w)
}

func (g *genDeepCopy) legacyRegistration(c *generator.Context, w io.Writer) error {
conversionPackagePath := "k8s.io/apimachinery/pkg/conversion"
runtimePackagePath := "k8s.io/apimachinery/pkg/runtime"

cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"})
g.imports.AddType(cloner)
if !g.registerTypes {
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.\n", nil)
sw.Do("//\n", nil)
sw.Do("// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.\n", nil)
sw.Do("func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc{\n", 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: func(in interface{}, out interface{}, c *conversion.Cloner) error {in.(*$.type|raw$).DeepCopyInto(out.(*$.type|raw$)); return nil}, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do("}\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
}

sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil)
sw.Do("SchemeBuilder.Register(RegisterDeepCopies)\n", nil)
sw.Do("}\n\n", nil)

scheme := c.Universe.Type(types.Name{Package: runtimePackagePath, Name: "Scheme"})
schemePtr := &types.Type{
Kind: types.Pointer,
Elem: scheme,
}
sw.Do("// RegisterDeepCopies adds deep-copy functions to the given scheme. Public\n", nil)
sw.Do("// to allow building arbitrary schemes.\n", nil)
sw.Do("//\n", nil)
sw.Do("// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.\n", nil)
sw.Do("func RegisterDeepCopies(scheme $.|raw$) error {\n", schemePtr)
sw.Do("return scheme.AddGeneratedDeepCopyFuncs(\n", nil)
for _, t := range g.typesForInit {
args := argsFromType(t).
With("typeof", c.Universe.Package("reflect").Function("TypeOf"))
sw.Do("conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {in.(*$.type|raw$).DeepCopyInto(out.(*$.type|raw$)); return nil}, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do(")\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
return nil
}

func (g *genDeepCopy) needsGeneration(t *types.Type) bool {
Expand Down
17 changes: 0 additions & 17 deletions examples/deepcopy-gen/output_tests/builtins/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

package builtins

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ttest) DeepCopyInto(out *Ttest) {
*out = *in
Expand Down
17 changes: 0 additions & 17 deletions examples/deepcopy-gen/output_tests/interfaces/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

package interfaces

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ttest) DeepCopyInto(out *Ttest) {
*out = *in
Expand Down
17 changes: 0 additions & 17 deletions examples/deepcopy-gen/output_tests/maps/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

package maps

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ttest) DeepCopyInto(out *Ttest) {
*out = *in
Expand Down
17 changes: 0 additions & 17 deletions examples/deepcopy-gen/output_tests/pointer/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

package pointer

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ttest) DeepCopyInto(out *Ttest) {
*out = *in
Expand Down
17 changes: 0 additions & 17 deletions examples/deepcopy-gen/output_tests/slices/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,6 @@ limitations under the License.

package slices

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Ttest) DeepCopyInto(out *Ttest) {
*out = *in
Expand Down
21 changes: 0 additions & 21 deletions examples/deepcopy-gen/output_tests/structs/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@ limitations under the License.

package structs

import (
conversion "k8s.io/apimachinery/pkg/conversion"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Inner).DeepCopyInto(out.(*Inner))
return nil
}, InType: reflect.TypeOf(&Inner{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Ttest).DeepCopyInto(out.(*Ttest))
return nil
}, InType: reflect.TypeOf(&Ttest{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Inner) DeepCopyInto(out *Inner) {
*out = *in
Expand Down
114 changes: 0 additions & 114 deletions examples/deepcopy-gen/output_tests/wholepkg/zz_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,123 +21,9 @@ limitations under the License.
package wholepkg

import (
conversion "k8s.io/apimachinery/pkg/conversion"
otherpkg "k8s.io/gengo/examples/deepcopy-gen/output_tests/otherpkg"
reflect "reflect"
)

// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
//
// Deprecated: deepcopy registration will go away when static deepcopy is fully implemented.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*ManualStruct).DeepCopyInto(out.(*ManualStruct))
return nil
}, InType: reflect.TypeOf(&ManualStruct{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*ManualStruct_Alias).DeepCopyInto(out.(*ManualStruct_Alias))
return nil
}, InType: reflect.TypeOf(&ManualStruct_Alias{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_B).DeepCopyInto(out.(*Struct_B))
return nil
}, InType: reflect.TypeOf(&Struct_B{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_Int).DeepCopyInto(out.(*Struct_Embed_Int))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_Int{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_ManualStruct).DeepCopyInto(out.(*Struct_Embed_ManualStruct))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_ManualStruct{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_Pointer).DeepCopyInto(out.(*Struct_Embed_Pointer))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_Pointer{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_Struct_PrimitivePointers).DeepCopyInto(out.(*Struct_Embed_Struct_PrimitivePointers))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_Struct_PrimitivePointers{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_Struct_Primitives).DeepCopyInto(out.(*Struct_Embed_Struct_Primitives))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_Struct_Primitives{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Embed_Struct_Slices).DeepCopyInto(out.(*Struct_Embed_Struct_Slices))
return nil
}, InType: reflect.TypeOf(&Struct_Embed_Struct_Slices{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Empty).DeepCopyInto(out.(*Struct_Empty))
return nil
}, InType: reflect.TypeOf(&Struct_Empty{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Everything).DeepCopyInto(out.(*Struct_Everything))
return nil
}, InType: reflect.TypeOf(&Struct_Everything{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_ExplicitObject).DeepCopyInto(out.(*Struct_ExplicitObject))
return nil
}, InType: reflect.TypeOf(&Struct_ExplicitObject{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_ExplicitSelectorExplicitObject).DeepCopyInto(out.(*Struct_ExplicitSelectorExplicitObject))
return nil
}, InType: reflect.TypeOf(&Struct_ExplicitSelectorExplicitObject{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Interfaces).DeepCopyInto(out.(*Struct_Interfaces))
return nil
}, InType: reflect.TypeOf(&Struct_Interfaces{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_NonPointerExplicitObject).DeepCopyInto(out.(*Struct_NonPointerExplicitObject))
return nil
}, InType: reflect.TypeOf(&Struct_NonPointerExplicitObject{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_ObjectAndList).DeepCopyInto(out.(*Struct_ObjectAndList))
return nil
}, InType: reflect.TypeOf(&Struct_ObjectAndList{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_ObjectAndObject).DeepCopyInto(out.(*Struct_ObjectAndObject))
return nil
}, InType: reflect.TypeOf(&Struct_ObjectAndObject{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_PrimitivePointers).DeepCopyInto(out.(*Struct_PrimitivePointers))
return nil
}, InType: reflect.TypeOf(&Struct_PrimitivePointers{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_PrimitivePointers_Alias).DeepCopyInto(out.(*Struct_PrimitivePointers_Alias))
return nil
}, InType: reflect.TypeOf(&Struct_PrimitivePointers_Alias{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Primitives).DeepCopyInto(out.(*Struct_Primitives))
return nil
}, InType: reflect.TypeOf(&Struct_Primitives{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Primitives_Alias).DeepCopyInto(out.(*Struct_Primitives_Alias))
return nil
}, InType: reflect.TypeOf(&Struct_Primitives_Alias{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Slices).DeepCopyInto(out.(*Struct_Slices))
return nil
}, InType: reflect.TypeOf(&Struct_Slices{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Slices_Alias).DeepCopyInto(out.(*Struct_Slices_Alias))
return nil
}, InType: reflect.TypeOf(&Struct_Slices_Alias{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Struct_PrimitivePointers).DeepCopyInto(out.(*Struct_Struct_PrimitivePointers))
return nil
}, InType: reflect.TypeOf(&Struct_Struct_PrimitivePointers{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Struct_Primitives).DeepCopyInto(out.(*Struct_Struct_Primitives))
return nil
}, InType: reflect.TypeOf(&Struct_Struct_Primitives{})},
{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
in.(*Struct_Struct_Slices).DeepCopyInto(out.(*Struct_Struct_Slices))
return nil
}, InType: reflect.TypeOf(&Struct_Struct_Slices{})},
}
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ManualStruct) DeepCopyInto(out *ManualStruct) {
*out = in.DeepCopy()
Expand Down

0 comments on commit b58fc7e

Please sign in to comment.