diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/debian/changelog golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/debian/changelog --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/debian/changelog 2017-02-20 21:56:15.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/debian/changelog 2017-09-25 10:54:34.000000000 +0000 @@ -1,3 +1,9 @@ +golang-github-kubernetes-gengo (0.0~git20170531.0.c79c13d-1) unstable; urgency=medium + + * New upstream snapshot. + + -- Andrew Shadura Mon, 25 Sep 2017 12:27:09 +0200 + golang-github-kubernetes-gengo (0.0~git20161024.0.6a1c24d-1) unstable; urgency=medium * Initial release (Closes: #858311) diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/debian/rules golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/debian/rules --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/debian/rules 2017-02-20 21:56:15.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/debian/rules 2017-09-25 10:54:34.000000000 +0000 @@ -1,5 +1,7 @@ #!/usr/bin/make -f +export DH_GOLANG_EXCLUDES := examples + %: dh $@ --buildsystem=golang --with=golang diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/generators/deepcopy.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/generators/deepcopy.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/generators/deepcopy.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/generators/deepcopy.go 2017-05-31 20:30:55.000000000 +0000 @@ -124,14 +124,16 @@ inputs := sets.NewString(context.Inputs...) packages := generator.Packages{} header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...) - header = append(header, []byte( - ` -// This file was autogenerated by deepcopy-gen. Do not edit it manually! + header = append(header, []byte(` + // This file was autogenerated by deepcopy-gen. Do not edit it manually! -`)...) + `)...) boundingDirs := []string{} if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { + if customArgs.BoundingDirs == nil { + customArgs.BoundingDirs = context.Inputs + } for i := range customArgs.BoundingDirs { // Strip any trailing slashes - they are not exactly "correct" but // this is friendlier. @@ -140,7 +142,7 @@ } for i := range inputs { - glog.V(5).Infof("considering pkg %q", i) + glog.V(5).Infof("Considering pkg %q", i) pkg := context.Universe[i] if pkg == nil { // If the input had no Go files, for example. @@ -181,16 +183,30 @@ } if pkgNeedsGeneration { + 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 + } + } packages = append(packages, &generator.DefaultPackage{ PackageName: strings.Split(filepath.Base(pkg.Path), ".")[0], - PackagePath: pkg.Path, + PackagePath: path, HeaderText: header, GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { - generators = []generator.Generator{} - generators = append( - generators, NewGenDeepCopy(arguments.OutputFileBaseName, pkg.Path, boundingDirs, (ptagValue == tagValuePackage), ptagRegister)) - return generators + return []generator.Generator{ + NewGenDeepCopy(arguments.OutputFileBaseName, pkg.Path, boundingDirs, (ptagValue == tagValuePackage), ptagRegister), + } }, FilterFunc: func(c *generator.Context, t *types.Type) bool { return t.Name.Package == pkg.Path @@ -202,9 +218,8 @@ } const ( - apiPackagePath = "k8s.io/kubernetes/pkg/api" - conversionPackagePath = "k8s.io/kubernetes/pkg/conversion" - runtimePackagePath = "k8s.io/kubernetes/pkg/runtime" + conversionPackagePath = "k8s.io/apimachinery/pkg/conversion" + runtimePackagePath = "k8s.io/apimachinery/pkg/runtime" ) // genDeepCopy produces a file with autogenerated deep-copy functions. @@ -253,11 +268,16 @@ enabled = true } } - copyable := enabled && copyableType(t) - if copyable { - g.typesForInit = append(g.typesForInit, t) + if !enabled { + return false } - 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 { @@ -368,12 +388,20 @@ cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"}) g.imports.AddType(cloner) if !g.registerTypes { - // TODO: We should come up with a solution to register all generated - // deep-copy functions. However, for now, to avoid import cycles - // we register only those explicitly requested. - return nil + sw := generator.NewSnippetWriter(w, c, "$", "$") + sw.Do("// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.\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: $.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.Do("func init() {\n", nil) @@ -410,12 +438,12 @@ } if g.allTypes && tv == "false" { // 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 } if !g.allTypes && tv != "true" { // 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 true @@ -425,11 +453,12 @@ if !g.needsGeneration(t) { 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, "$", "$") args := argsFromType(t). With("clonerType", types.Ref(conversionPackagePath, "Cloner")) + sw.Do("// $.type|dcFnName$ is an autogenerated deepcopy function.\n", args) sw.Do("func $.type|dcFnName$(in interface{}, out interface{}, c *$.clonerType|raw$) error {{\n", args) sw.Do("in := in.(*$.type|raw$)\nout := out.(*$.type|raw$)\n", argsFromType(t)) g.generateFor(t, sw) @@ -510,15 +539,25 @@ } 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) - 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) } else { sw.Do("for i := range *in {\n", nil) - if hasDeepCopyMethod(t.Elem) { - sw.Do("(*out)[i] = (*in)[i].DeepCopy()\n", nil) - } else if t.Elem.IsAssignable() { - sw.Do("(*out)[i] = (*in)[i]\n", nil) + if t.Elem.Kind == types.Slice { + sw.Do("if (*in)[i] != nil {\n", nil) + sw.Do("in, out := &(*in)[i], &(*out)[i]\n", nil) + g.generateFor(t.Elem, sw) + sw.Do("}\n", nil) } 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("return err\n", nil) @@ -535,12 +574,18 @@ } func (g *genDeepCopy) doStruct(t *types.Type, sw *generator.SnippetWriter) { - if len(t.Members) == 0 { - // at least do something with in/out to avoid "declared and not used" errors - sw.Do("_ = in\n_ = out\n", nil) + if hasDeepCopyMethod(t) { + sw.Do("*out = in.DeepCopy()\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 { t := m.Type + hasMethod := hasDeepCopyMethod(t) if t.Kind == types.Alias { copied := *t.Underlying copied.Name = t.Name @@ -548,28 +593,40 @@ } args := generator.Args{ "type": t, + "kind": t.Kind, "name": m.Name, } switch t.Kind { 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: - sw.Do("if in.$.name$ != nil {\n", args) - sw.Do("in, out := &in.$.name$, &out.$.name$\n", args) - g.generateFor(t, sw) - sw.Do("} else {\n", nil) - sw.Do("out.$.name$ = nil\n", args) - sw.Do("}\n", nil) + if hasMethod { + sw.Do("if in.$.name$ != nil {\n", args) + sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args) + sw.Do("}\n", nil) + } else { + // Fixup non-nil reference-semantic 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: - if hasDeepCopyMethod(t) { + if hasMethod { sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args) } else if t.IsAssignable() { - sw.Do("out.$.name$ = in.$.name$\n", args) + // Nothing else needed. } 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("return err\n", nil) sw.Do("}\n", nil) } 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("return err\n", nil) sw.Do("} else {\n", nil) @@ -577,13 +634,22 @@ sw.Do("}\n", nil) } default: - sw.Do("if in.$.name$ == nil {\n", args) - sw.Do("out.$.name$ = nil\n", args) - sw.Do("} else 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) + // Interfaces, Arrays, and other Kinds we don't understand. + sw.Do("// in.$.name$ is kind '$.kind$'\n", args) + if hasMethod { + sw.Do("if in.$.name$ != nil {\n", args) + sw.Do("out.$.name$ = in.$.name$.DeepCopy()\n", args) + sw.Do("}\n", args) + } 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) + } } } } diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/Makefile golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/Makefile --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/Makefile 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/Makefile 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,16 @@ +TOOL=deepcopy-gen + +test: + @if ! git diff --quiet HEAD; then \ + echo "FAIL: git client is not clean"; \ + false; \ + fi + @go build -o /tmp/$(TOOL) + @PKGS=$$(go list ./output_tests/... | paste -sd' '); \ + /tmp/$(TOOL) --logtostderr --v=4 -i $$(echo $$PKGS | sed 's/ /,/g') -O zz_generated + @if ! git diff --quiet HEAD; then \ + echo "FAIL: output files changed"; \ + git diff; \ + false; \ + fi + diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/builtins/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/builtins/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/builtins/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/builtins/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,35 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package builtins + +type Ttest struct { + Byte byte + //Int8 int8 //TODO: int8 becomes byte in SnippetWriter + Int16 int16 + Int32 int32 + Int64 int64 + Uint8 uint8 + Uint16 uint16 + Uint32 uint32 + Uint64 uint64 + Float32 float32 + Float64 float64 + String string +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/builtins/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/builtins/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/builtins/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/builtins/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,43 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package builtins + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_builtins_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_builtins_Ttest is an autogenerated deepcopy function. +func DeepCopy_builtins_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/emptyinterface/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/emptyinterface/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/emptyinterface/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/emptyinterface/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,24 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package emptyinterface + +type Ttest struct { + Interface interface{} +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/emptyinterface/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/emptyinterface/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/emptyinterface/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/emptyinterface/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,51 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package emptyinterface + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_emptyinterface_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_emptyinterface_Ttest is an autogenerated deepcopy function. +func DeepCopy_emptyinterface_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + // in.Interface is kind 'Interface' + if in.Interface != nil { + if newVal, err := c.DeepCopy(&in.Interface); err != nil { + return err + } else { + out.Interface = *newVal.(*interface{}) + } + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/interfaces/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/interfaces/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/interfaces/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/interfaces/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,28 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package interfaces + +type Inner interface { + function() float64 +} + +type Ttest struct { + I []Inner +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/interfaces/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/interfaces/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/interfaces/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/interfaces/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,54 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package interfaces + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_interfaces_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_interfaces_Ttest is an autogenerated deepcopy function. +func DeepCopy_interfaces_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + if in.I != nil { + in, out := &in.I, &out.I + *out = make([]Inner, len(*in)) + for i := range *in { + if newVal, err := c.DeepCopy(&(*in)[i]); err != nil { + return err + } else { + (*out)[i] = *newVal.(*Inner) + } + } + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/maps/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/maps/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/maps/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/maps/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,35 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package maps + +type Ttest struct { + Byte map[string]byte + //Int8 map[string]int8 //TODO: int8 becomes byte in SnippetWriter + Int16 map[string]int16 + Int32 map[string]int32 + Int64 map[string]int64 + Uint8 map[string]uint8 + Uint16 map[string]uint16 + Uint32 map[string]uint32 + Uint64 map[string]uint64 + Float32 map[string]float32 + Float64 map[string]float64 + String map[string]string +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/maps/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/maps/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/maps/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/maps/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,120 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package maps + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_maps_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_maps_Ttest is an autogenerated deepcopy function. +func DeepCopy_maps_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + if in.Byte != nil { + in, out := &in.Byte, &out.Byte + *out = make(map[string]byte) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Int16 != nil { + in, out := &in.Int16, &out.Int16 + *out = make(map[string]int16) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Int32 != nil { + in, out := &in.Int32, &out.Int32 + *out = make(map[string]int32) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Int64 != nil { + in, out := &in.Int64, &out.Int64 + *out = make(map[string]int64) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Uint8 != nil { + in, out := &in.Uint8, &out.Uint8 + *out = make(map[string]byte) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Uint16 != nil { + in, out := &in.Uint16, &out.Uint16 + *out = make(map[string]uint16) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Uint32 != nil { + in, out := &in.Uint32, &out.Uint32 + *out = make(map[string]uint32) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Uint64 != nil { + in, out := &in.Uint64, &out.Uint64 + *out = make(map[string]uint64) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Float32 != nil { + in, out := &in.Float32, &out.Float32 + *out = make(map[string]float32) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Float64 != nil { + in, out := &in.Float64, &out.Float64 + *out = make(map[string]float64) + for key, val := range *in { + (*out)[key] = val + } + } + if in.String != nil { + in, out := &in.String, &out.String + *out = make(map[string]string) + for key, val := range *in { + (*out)[key] = val + } + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/pointer/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/pointer/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/pointer/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/pointer/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,24 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package pointer + +type Ttest struct { + Types map[string]*Ttest +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/pointer/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/pointer/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/pointer/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/pointer/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,54 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package pointer + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_pointer_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_pointer_Ttest is an autogenerated deepcopy function. +func DeepCopy_pointer_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + if in.Types != nil { + in, out := &in.Types, &out.Types + *out = make(map[string]*Ttest) + for key, val := range *in { + if newVal, err := c.DeepCopy(&val); err != nil { + return err + } else { + (*out)[key] = *newVal.(**Ttest) + } + } + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/slices/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/slices/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/slices/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/slices/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,35 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package slices + +type Ttest struct { + Byte []byte + //Int8 []int8 //TODO: int8 becomes byte in SnippetWriter + Int16 []int16 + Int32 []int32 + Int64 []int64 + Uint8 []uint8 + Uint16 []uint16 + Uint32 []uint32 + Uint64 []uint64 + Float32 []float32 + Float64 []float64 + String []string +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/slices/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/slices/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/slices/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/slices/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,98 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package slices + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_slices_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_slices_Ttest is an autogenerated deepcopy function. +func DeepCopy_slices_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + if in.Byte != nil { + in, out := &in.Byte, &out.Byte + *out = make([]byte, len(*in)) + copy(*out, *in) + } + if in.Int16 != nil { + in, out := &in.Int16, &out.Int16 + *out = make([]int16, len(*in)) + copy(*out, *in) + } + if in.Int32 != nil { + in, out := &in.Int32, &out.Int32 + *out = make([]int32, len(*in)) + copy(*out, *in) + } + if in.Int64 != nil { + in, out := &in.Int64, &out.Int64 + *out = make([]int64, len(*in)) + copy(*out, *in) + } + if in.Uint8 != nil { + in, out := &in.Uint8, &out.Uint8 + *out = make([]byte, len(*in)) + copy(*out, *in) + } + if in.Uint16 != nil { + in, out := &in.Uint16, &out.Uint16 + *out = make([]uint16, len(*in)) + copy(*out, *in) + } + if in.Uint32 != nil { + in, out := &in.Uint32, &out.Uint32 + *out = make([]uint32, len(*in)) + copy(*out, *in) + } + if in.Uint64 != nil { + in, out := &in.Uint64, &out.Uint64 + *out = make([]uint64, len(*in)) + copy(*out, *in) + } + if in.Float32 != nil { + in, out := &in.Float32, &out.Float32 + *out = make([]float32, len(*in)) + copy(*out, *in) + } + if in.Float64 != nil { + in, out := &in.Float64, &out.Float64 + *out = make([]float64, len(*in)) + copy(*out, *in) + } + if in.String != nil { + in, out := &in.String, &out.String + *out = make([]string, len(*in)) + copy(*out, *in) + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/structs/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/structs/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/structs/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/structs/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,40 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package structs + +type Inner struct { + Byte byte + //Int8 int8 //TODO: int8 becomes byte in SnippetWriter + Int16 int16 + Int32 int32 + Int64 int64 + Uint8 uint8 + Uint16 uint16 + Uint32 uint32 + Uint64 uint64 + Float32 float32 + Float64 float64 + String string +} + +type Ttest struct { + Inner1 Inner + Inner2 Inner +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/structs/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/structs/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/structs/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/structs/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,54 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package structs + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_structs_Inner, InType: reflect.TypeOf(&Inner{})}, + {Fn: DeepCopy_structs_Ttest, InType: reflect.TypeOf(&Ttest{})}, + } +} + +// DeepCopy_structs_Inner is an autogenerated deepcopy function. +func DeepCopy_structs_Inner(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Inner) + out := out.(*Inner) + *out = *in + return nil + } +} + +// DeepCopy_structs_Ttest is an autogenerated deepcopy function. +func DeepCopy_structs_Ttest(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Ttest) + out := out.(*Ttest) + *out = *in + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/a.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/a.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/a.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/a.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,130 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package wholepkg + +// Trivial +type Struct_Empty struct{} + +// Only primitives +type Struct_Primitives struct { + BoolField bool + IntField int + StringField string + FloatField float64 +} +type Struct_Primitives_Alias Struct_Primitives +type Struct_Embed_Struct_Primitives struct { + Struct_Primitives +} +type Struct_Embed_Int struct { + int +} +type Struct_Struct_Primitives struct { + StructField Struct_Primitives +} + +// Manual DeepCopy method +type ManualStruct struct { + StringField string +} + +func (m ManualStruct) DeepCopy() ManualStruct { + return m +} + +type ManualStruct_Alias ManualStruct + +type Struct_Embed_ManualStruct struct { + ManualStruct +} + +// Only pointers to primitives +type Struct_PrimitivePointers struct { + BoolPtrField *bool + IntPtrField *int + StringPtrField *string + FloatPtrField *float64 +} +type Struct_PrimitivePointers_Alias Struct_PrimitivePointers +type Struct_Embed_Struct_PrimitivePointers struct { + Struct_PrimitivePointers +} +type Struct_Embed_Pointer struct { + *int +} +type Struct_Struct_PrimitivePointers struct { + StructField Struct_PrimitivePointers +} + +// Manual DeepCopy method +type ManualSlice []string + +func (m ManualSlice) DeepCopy() ManualSlice { + r := make(ManualSlice, len(m)) + copy(r, m) + return r +} + +// Slices +type Struct_Slices struct { + SliceBoolField []bool + SliceByteField []byte + SliceIntField []int + SliceStringField []string + SliceFloatField []float64 + SliceStructPrimitivesField []Struct_Primitives + SliceStructPrimitivesAliasField []Struct_Primitives_Alias + SliceStructPrimitivePointersField []Struct_PrimitivePointers + SliceStructPrimitivePointersAliasField []Struct_PrimitivePointers_Alias + SliceSliceIntField [][]int + SliceManualStructField []ManualStruct + ManualSliceField ManualSlice +} +type Struct_Slices_Alias Struct_Slices +type Struct_Embed_Struct_Slices struct { + Struct_Slices +} +type Struct_Struct_Slices struct { + StructField Struct_Slices +} + +// Everything +type Struct_Everything struct { + BoolField bool + IntField int + StringField string + FloatField float64 + StructField Struct_Primitives + EmptyStructField Struct_Empty + ManualStructField ManualStruct + ManualStructAliasField ManualStruct_Alias + BoolPtrField *bool + IntPtrField *int + StringPtrField *string + FloatPtrField *float64 + PrimitivePointersField Struct_PrimitivePointers + ManualStructPtrField *ManualStruct + ManualStructAliasPtrField *ManualStruct_Alias + SliceBoolField []bool + SliceByteField []byte + SliceIntField []int + SliceStringField []string + SliceFloatField []float64 + SlicesField Struct_Slices + SliceManualStructField []ManualStruct + ManualSliceField ManualSlice +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/b.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/b.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/b.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/b.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,20 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package wholepkg + +// Another type in another file. +type Struct_B struct{} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/deepcopy_test.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,48 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package wholepkg + +import ( + "reflect" + "testing" + + fuzz "github.com/google/gofuzz" +) + +func TestDeepCopy(t *testing.T) { + x := Struct_Primitives{} + y := Struct_Primitives{} + + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal to start, but are not") + } + + fuzzer := fuzz.New() + fuzzer.Fuzz(&x) + fuzzer.Fuzz(&y) + + if reflect.DeepEqual(&x, &y) { + t.Errorf("objects should not be equal, but are") + } + + if err := DeepCopy_wholepkg_Struct_Primitives(&x, &y, nil); err != nil { + t.Errorf("unexpected error: %v", err) + } + if !reflect.DeepEqual(&x, &y) { + t.Errorf("objects should be equal, but are not") + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,20 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package + +// This is a test package. +package wholepkg diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/zz_generated.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/zz_generated.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/deepcopy-gen/output_tests/wholepkg/zz_generated.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/deepcopy-gen/output_tests/wholepkg/zz_generated.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,530 @@ +// +build !ignore_autogenerated + +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// This file was autogenerated by deepcopy-gen. Do not edit it manually! + +package wholepkg + +import ( + conversion "k8s.io/apimachinery/pkg/conversion" + reflect "reflect" +) + +// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them. +func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc { + return []conversion.GeneratedDeepCopyFunc{ + {Fn: DeepCopy_wholepkg_ManualStruct, InType: reflect.TypeOf(&ManualStruct{})}, + {Fn: DeepCopy_wholepkg_ManualStruct_Alias, InType: reflect.TypeOf(&ManualStruct_Alias{})}, + {Fn: DeepCopy_wholepkg_Struct_B, InType: reflect.TypeOf(&Struct_B{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_Int, InType: reflect.TypeOf(&Struct_Embed_Int{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_ManualStruct, InType: reflect.TypeOf(&Struct_Embed_ManualStruct{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_Pointer, InType: reflect.TypeOf(&Struct_Embed_Pointer{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_Struct_PrimitivePointers, InType: reflect.TypeOf(&Struct_Embed_Struct_PrimitivePointers{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_Struct_Primitives, InType: reflect.TypeOf(&Struct_Embed_Struct_Primitives{})}, + {Fn: DeepCopy_wholepkg_Struct_Embed_Struct_Slices, InType: reflect.TypeOf(&Struct_Embed_Struct_Slices{})}, + {Fn: DeepCopy_wholepkg_Struct_Empty, InType: reflect.TypeOf(&Struct_Empty{})}, + {Fn: DeepCopy_wholepkg_Struct_Everything, InType: reflect.TypeOf(&Struct_Everything{})}, + {Fn: DeepCopy_wholepkg_Struct_PrimitivePointers, InType: reflect.TypeOf(&Struct_PrimitivePointers{})}, + {Fn: DeepCopy_wholepkg_Struct_PrimitivePointers_Alias, InType: reflect.TypeOf(&Struct_PrimitivePointers_Alias{})}, + {Fn: DeepCopy_wholepkg_Struct_Primitives, InType: reflect.TypeOf(&Struct_Primitives{})}, + {Fn: DeepCopy_wholepkg_Struct_Primitives_Alias, InType: reflect.TypeOf(&Struct_Primitives_Alias{})}, + {Fn: DeepCopy_wholepkg_Struct_Slices, InType: reflect.TypeOf(&Struct_Slices{})}, + {Fn: DeepCopy_wholepkg_Struct_Slices_Alias, InType: reflect.TypeOf(&Struct_Slices_Alias{})}, + {Fn: DeepCopy_wholepkg_Struct_Struct_PrimitivePointers, InType: reflect.TypeOf(&Struct_Struct_PrimitivePointers{})}, + {Fn: DeepCopy_wholepkg_Struct_Struct_Primitives, InType: reflect.TypeOf(&Struct_Struct_Primitives{})}, + {Fn: DeepCopy_wholepkg_Struct_Struct_Slices, InType: reflect.TypeOf(&Struct_Struct_Slices{})}, + } +} + +// DeepCopy_wholepkg_ManualStruct is an autogenerated deepcopy function. +func DeepCopy_wholepkg_ManualStruct(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*ManualStruct) + out := out.(*ManualStruct) + *out = in.DeepCopy() + return nil + } +} + +// DeepCopy_wholepkg_ManualStruct_Alias is an autogenerated deepcopy function. +func DeepCopy_wholepkg_ManualStruct_Alias(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*ManualStruct_Alias) + out := out.(*ManualStruct_Alias) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_B is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_B(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_B) + out := out.(*Struct_B) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_Int is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_Int(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_Int) + out := out.(*Struct_Embed_Int) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_ManualStruct is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_ManualStruct(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_ManualStruct) + out := out.(*Struct_Embed_ManualStruct) + *out = *in + out.ManualStruct = in.ManualStruct.DeepCopy() + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_Pointer is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_Pointer(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_Pointer) + out := out.(*Struct_Embed_Pointer) + *out = *in + if in.int != nil { + in, out := &in.int, &out.int + *out = new(int) + **out = **in + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_Struct_PrimitivePointers is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_Struct_PrimitivePointers(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_Struct_PrimitivePointers) + out := out.(*Struct_Embed_Struct_PrimitivePointers) + *out = *in + if err := DeepCopy_wholepkg_Struct_PrimitivePointers(&in.Struct_PrimitivePointers, &out.Struct_PrimitivePointers, c); err != nil { + return err + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_Struct_Primitives is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_Struct_Primitives(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_Struct_Primitives) + out := out.(*Struct_Embed_Struct_Primitives) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Embed_Struct_Slices is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Embed_Struct_Slices(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Embed_Struct_Slices) + out := out.(*Struct_Embed_Struct_Slices) + *out = *in + if err := DeepCopy_wholepkg_Struct_Slices(&in.Struct_Slices, &out.Struct_Slices, c); err != nil { + return err + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Empty is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Empty(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Empty) + out := out.(*Struct_Empty) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Everything is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Everything(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Everything) + out := out.(*Struct_Everything) + *out = *in + out.ManualStructField = in.ManualStructField.DeepCopy() + if in.BoolPtrField != nil { + in, out := &in.BoolPtrField, &out.BoolPtrField + *out = new(bool) + **out = **in + } + if in.IntPtrField != nil { + in, out := &in.IntPtrField, &out.IntPtrField + *out = new(int) + **out = **in + } + if in.StringPtrField != nil { + in, out := &in.StringPtrField, &out.StringPtrField + *out = new(string) + **out = **in + } + if in.FloatPtrField != nil { + in, out := &in.FloatPtrField, &out.FloatPtrField + *out = new(float64) + **out = **in + } + if err := DeepCopy_wholepkg_Struct_PrimitivePointers(&in.PrimitivePointersField, &out.PrimitivePointersField, c); err != nil { + return err + } + if in.ManualStructPtrField != nil { + in, out := &in.ManualStructPtrField, &out.ManualStructPtrField + *out = new(ManualStruct) + **out = (*in).DeepCopy() + } + if in.ManualStructAliasPtrField != nil { + in, out := &in.ManualStructAliasPtrField, &out.ManualStructAliasPtrField + *out = new(ManualStruct_Alias) + **out = **in + } + if in.SliceBoolField != nil { + in, out := &in.SliceBoolField, &out.SliceBoolField + *out = make([]bool, len(*in)) + copy(*out, *in) + } + if in.SliceByteField != nil { + in, out := &in.SliceByteField, &out.SliceByteField + *out = make([]byte, len(*in)) + copy(*out, *in) + } + if in.SliceIntField != nil { + in, out := &in.SliceIntField, &out.SliceIntField + *out = make([]int, len(*in)) + copy(*out, *in) + } + if in.SliceStringField != nil { + in, out := &in.SliceStringField, &out.SliceStringField + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.SliceFloatField != nil { + in, out := &in.SliceFloatField, &out.SliceFloatField + *out = make([]float64, len(*in)) + copy(*out, *in) + } + if err := DeepCopy_wholepkg_Struct_Slices(&in.SlicesField, &out.SlicesField, c); err != nil { + return err + } + if in.SliceManualStructField != nil { + in, out := &in.SliceManualStructField, &out.SliceManualStructField + *out = make([]ManualStruct, len(*in)) + for i := range *in { + (*out)[i] = (*in)[i].DeepCopy() + } + } + if in.ManualSliceField != nil { + out.ManualSliceField = in.ManualSliceField.DeepCopy() + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_PrimitivePointers is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_PrimitivePointers(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_PrimitivePointers) + out := out.(*Struct_PrimitivePointers) + *out = *in + if in.BoolPtrField != nil { + in, out := &in.BoolPtrField, &out.BoolPtrField + *out = new(bool) + **out = **in + } + if in.IntPtrField != nil { + in, out := &in.IntPtrField, &out.IntPtrField + *out = new(int) + **out = **in + } + if in.StringPtrField != nil { + in, out := &in.StringPtrField, &out.StringPtrField + *out = new(string) + **out = **in + } + if in.FloatPtrField != nil { + in, out := &in.FloatPtrField, &out.FloatPtrField + *out = new(float64) + **out = **in + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_PrimitivePointers_Alias is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_PrimitivePointers_Alias(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_PrimitivePointers_Alias) + out := out.(*Struct_PrimitivePointers_Alias) + *out = *in + if in.BoolPtrField != nil { + in, out := &in.BoolPtrField, &out.BoolPtrField + *out = new(bool) + **out = **in + } + if in.IntPtrField != nil { + in, out := &in.IntPtrField, &out.IntPtrField + *out = new(int) + **out = **in + } + if in.StringPtrField != nil { + in, out := &in.StringPtrField, &out.StringPtrField + *out = new(string) + **out = **in + } + if in.FloatPtrField != nil { + in, out := &in.FloatPtrField, &out.FloatPtrField + *out = new(float64) + **out = **in + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Primitives is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Primitives(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Primitives) + out := out.(*Struct_Primitives) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Primitives_Alias is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Primitives_Alias(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Primitives_Alias) + out := out.(*Struct_Primitives_Alias) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Slices is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Slices(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Slices) + out := out.(*Struct_Slices) + *out = *in + if in.SliceBoolField != nil { + in, out := &in.SliceBoolField, &out.SliceBoolField + *out = make([]bool, len(*in)) + copy(*out, *in) + } + if in.SliceByteField != nil { + in, out := &in.SliceByteField, &out.SliceByteField + *out = make([]byte, len(*in)) + copy(*out, *in) + } + if in.SliceIntField != nil { + in, out := &in.SliceIntField, &out.SliceIntField + *out = make([]int, len(*in)) + copy(*out, *in) + } + if in.SliceStringField != nil { + in, out := &in.SliceStringField, &out.SliceStringField + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.SliceFloatField != nil { + in, out := &in.SliceFloatField, &out.SliceFloatField + *out = make([]float64, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivesField != nil { + in, out := &in.SliceStructPrimitivesField, &out.SliceStructPrimitivesField + *out = make([]Struct_Primitives, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivesAliasField != nil { + in, out := &in.SliceStructPrimitivesAliasField, &out.SliceStructPrimitivesAliasField + *out = make([]Struct_Primitives_Alias, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivePointersField != nil { + in, out := &in.SliceStructPrimitivePointersField, &out.SliceStructPrimitivePointersField + *out = make([]Struct_PrimitivePointers, len(*in)) + for i := range *in { + if err := DeepCopy_wholepkg_Struct_PrimitivePointers(&(*in)[i], &(*out)[i], c); err != nil { + return err + } + } + } + if in.SliceStructPrimitivePointersAliasField != nil { + in, out := &in.SliceStructPrimitivePointersAliasField, &out.SliceStructPrimitivePointersAliasField + *out = make([]Struct_PrimitivePointers_Alias, len(*in)) + for i := range *in { + if err := DeepCopy_wholepkg_Struct_PrimitivePointers_Alias(&(*in)[i], &(*out)[i], c); err != nil { + return err + } + } + } + if in.SliceSliceIntField != nil { + in, out := &in.SliceSliceIntField, &out.SliceSliceIntField + *out = make([][]int, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]int, len(*in)) + copy(*out, *in) + } + } + } + if in.SliceManualStructField != nil { + in, out := &in.SliceManualStructField, &out.SliceManualStructField + *out = make([]ManualStruct, len(*in)) + for i := range *in { + (*out)[i] = (*in)[i].DeepCopy() + } + } + if in.ManualSliceField != nil { + out.ManualSliceField = in.ManualSliceField.DeepCopy() + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Slices_Alias is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Slices_Alias(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Slices_Alias) + out := out.(*Struct_Slices_Alias) + *out = *in + if in.SliceBoolField != nil { + in, out := &in.SliceBoolField, &out.SliceBoolField + *out = make([]bool, len(*in)) + copy(*out, *in) + } + if in.SliceByteField != nil { + in, out := &in.SliceByteField, &out.SliceByteField + *out = make([]byte, len(*in)) + copy(*out, *in) + } + if in.SliceIntField != nil { + in, out := &in.SliceIntField, &out.SliceIntField + *out = make([]int, len(*in)) + copy(*out, *in) + } + if in.SliceStringField != nil { + in, out := &in.SliceStringField, &out.SliceStringField + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.SliceFloatField != nil { + in, out := &in.SliceFloatField, &out.SliceFloatField + *out = make([]float64, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivesField != nil { + in, out := &in.SliceStructPrimitivesField, &out.SliceStructPrimitivesField + *out = make([]Struct_Primitives, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivesAliasField != nil { + in, out := &in.SliceStructPrimitivesAliasField, &out.SliceStructPrimitivesAliasField + *out = make([]Struct_Primitives_Alias, len(*in)) + copy(*out, *in) + } + if in.SliceStructPrimitivePointersField != nil { + in, out := &in.SliceStructPrimitivePointersField, &out.SliceStructPrimitivePointersField + *out = make([]Struct_PrimitivePointers, len(*in)) + for i := range *in { + if err := DeepCopy_wholepkg_Struct_PrimitivePointers(&(*in)[i], &(*out)[i], c); err != nil { + return err + } + } + } + if in.SliceStructPrimitivePointersAliasField != nil { + in, out := &in.SliceStructPrimitivePointersAliasField, &out.SliceStructPrimitivePointersAliasField + *out = make([]Struct_PrimitivePointers_Alias, len(*in)) + for i := range *in { + if err := DeepCopy_wholepkg_Struct_PrimitivePointers_Alias(&(*in)[i], &(*out)[i], c); err != nil { + return err + } + } + } + if in.SliceSliceIntField != nil { + in, out := &in.SliceSliceIntField, &out.SliceSliceIntField + *out = make([][]int, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = make([]int, len(*in)) + copy(*out, *in) + } + } + } + if in.SliceManualStructField != nil { + in, out := &in.SliceManualStructField, &out.SliceManualStructField + *out = make([]ManualStruct, len(*in)) + for i := range *in { + (*out)[i] = (*in)[i].DeepCopy() + } + } + if in.ManualSliceField != nil { + out.ManualSliceField = in.ManualSliceField.DeepCopy() + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Struct_PrimitivePointers is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Struct_PrimitivePointers(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Struct_PrimitivePointers) + out := out.(*Struct_Struct_PrimitivePointers) + *out = *in + if err := DeepCopy_wholepkg_Struct_PrimitivePointers(&in.StructField, &out.StructField, c); err != nil { + return err + } + return nil + } +} + +// DeepCopy_wholepkg_Struct_Struct_Primitives is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Struct_Primitives(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Struct_Primitives) + out := out.(*Struct_Struct_Primitives) + *out = *in + return nil + } +} + +// DeepCopy_wholepkg_Struct_Struct_Slices is an autogenerated deepcopy function. +func DeepCopy_wholepkg_Struct_Struct_Slices(in interface{}, out interface{}, c *conversion.Cloner) error { + { + in := in.(*Struct_Struct_Slices) + out := out.(*Struct_Struct_Slices) + *out = *in + if err := DeepCopy_wholepkg_Struct_Slices(&in.StructField, &out.StructField, c); err != nil { + return err + } + return nil + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/defaulter-gen/generators/defaulter.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/defaulter-gen/generators/defaulter.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/defaulter-gen/generators/defaulter.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/defaulter-gen/generators/defaulter.go 2017-05-31 20:30:55.000000000 +0000 @@ -38,13 +38,18 @@ ExtraPeerDirs []string // Always consider these as last-ditch possibilities for conversions. } -// This is the comment tag that carries parameters for defaulter generation. +// These are the comment tags that carry parameters for defaulter generation. const tagName = "k8s:defaulter-gen" +const intputTagName = "k8s:defaulter-gen-input" func extractTag(comments []string) []string { return types.ExtractCommentTags("+", comments)[tagName] } +func extractInputTag(comments []string) []string { + return types.ExtractCommentTags("+", comments)[intputTagName] +} + func checkTag(comments []string, require ...string) bool { values := types.ExtractCommentTags("+", comments)[tagName] if len(require) == 0 { @@ -220,14 +225,22 @@ // If the input had no Go files, for example. continue } + // typesPkg is where the types that needs defaulter are defined. + // Sometimes it is different from pkg. For example, kubernetes core/v1 + // types are defined in vendor/k8s.io/api/core/v1, while pkg is at + // pkg/api/v1. + typesPkg := pkg // Add defaulting functions. getManualDefaultingFunctions(context, pkg, existingDefaulters) var peerPkgs []string if customArgs, ok := arguments.CustomArgs.(*CustomArgs); ok { - if len(customArgs.ExtraPeerDirs) > 0 { - peerPkgs = append(peerPkgs, customArgs.ExtraPeerDirs...) + for _, pkg := range customArgs.ExtraPeerDirs { + if i := strings.Index(pkg, "/vendor/"); i != -1 { + pkg = pkg[i+len("/vendor/"):] + } + peerPkgs = append(peerPkgs, pkg) } } // Make sure our peer-packages are added and fully parsed. @@ -268,8 +281,24 @@ return false } + // if the types are not in the same package where the defaulter functions to be generated + inputTags := extractInputTag(pkg.Comments) + if len(inputTags) > 1 { + panic(fmt.Sprintf("there could only be one input tag, got %#v", inputTags)) + } + if len(inputTags) == 1 { + var err error + typesPkg, err = context.AddDirectory(filepath.Join(pkg.Path, inputTags[0])) + if err != nil { + glog.Fatalf("cannot import package %s", inputTags[0]) + } + // update context.Order to the latest context.Universe + orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)} + context.Order = orderer.OrderUniverse(context.Universe) + } + newDefaulters := defaulterFuncMap{} - for _, t := range pkg.Types { + for _, t := range typesPkg.Types { if !shouldCreateObjectDefaulterFn(t) { continue } @@ -323,21 +352,35 @@ if len(newDefaulters) == 0 { glog.V(5).Infof("no defaulters in package %s", pkg.Name) - continue + } + + 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 + } } packages = append(packages, &generator.DefaultPackage{ PackageName: filepath.Base(pkg.Path), - PackagePath: pkg.Path, + PackagePath: path, HeaderText: header, GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) { return []generator.Generator{ - NewGenDefaulter(arguments.OutputFileBaseName, pkg.Path, existingDefaulters, newDefaulters, peerPkgs), + NewGenDefaulter(arguments.OutputFileBaseName, typesPkg.Path, pkg.Path, existingDefaulters, newDefaulters, peerPkgs), } }, FilterFunc: func(c *generator.Context, t *types.Type) bool { - return t.Name.Package == pkg.Path + return t.Name.Package == typesPkg.Path }, }) } @@ -420,6 +463,10 @@ parent.children = append(parent.children, *child) } } + case types.Alias: + if child := buildCallTreeForType(t.Underlying, false, existingDefaulters, newDefaulters); child != nil { + parent.children = append(parent.children, *child) + } } if len(parent.children) == 0 && len(parent.call) == 0 { //glog.V(6).Infof("decided type %s needs no generation", t.Name) @@ -429,14 +476,15 @@ } const ( - runtimePackagePath = "k8s.io/kubernetes/pkg/runtime" - conversionPackagePath = "k8s.io/kubernetes/pkg/conversion" + runtimePackagePath = "k8s.io/apimachinery/pkg/runtime" + conversionPackagePath = "k8s.io/apimachinery/pkg/conversion" ) // genDefaulter produces a file with a autogenerated conversions. type genDefaulter struct { generator.DefaultGen - targetPackage string + typesPackage string + outputPackage string peerPackages []string newDefaulters defaulterFuncMap existingDefaulters defaulterFuncMap @@ -444,12 +492,13 @@ typesForInit []*types.Type } -func NewGenDefaulter(sanitizedName, targetPackage string, existingDefaulters, newDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator { +func NewGenDefaulter(sanitizedName, typesPackage, outputPackage string, existingDefaulters, newDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator { return &genDefaulter{ DefaultGen: generator.DefaultGen{ OptionalName: sanitizedName, }, - targetPackage: targetPackage, + typesPackage: typesPackage, + outputPackage: outputPackage, peerPackages: peerPkgs, newDefaulters: newDefaulters, existingDefaulters: existingDefaulters, @@ -461,15 +510,15 @@ func (g *genDefaulter) Namers(c *generator.Context) namer.NameSystems { // Have the raw namer for this file track what it imports. return namer.NameSystems{ - "raw": namer.NewRawNamer(g.targetPackage, g.imports), + "raw": namer.NewRawNamer(g.outputPackage, g.imports), } } func (g *genDefaulter) isOtherPackage(pkg string) bool { - if pkg == g.targetPackage { + if pkg == g.outputPackage { return false } - if strings.HasSuffix(pkg, `"`+g.targetPackage+`"`) { + if strings.HasSuffix(pkg, `"`+g.outputPackage+`"`) { return false } return true diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/cmd.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/cmd.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/cmd.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/cmd.go 2017-05-31 20:30:55.000000000 +0000 @@ -137,9 +137,6 @@ d = d[1:] outputPackage = false } - if strings.Contains(d, "-") { - log.Fatalf("Package names must be valid protobuf package identifiers, which allow only [a-z0-9_]: %s", d) - } name := protoSafePackage(d) parts := strings.SplitN(d, "=", 2) if len(parts) > 1 { diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/generator.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/generator.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/generator.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/generator.go 2017-05-31 20:30:55.000000000 +0000 @@ -124,7 +124,7 @@ case types.Interface: return false default: - log.Printf("WARNING: type %q is not protable: %s", t.Kind, t.Name) + log.Printf("WARNING: type %q is not portable: %s", t.Kind, t.Name) return false } } @@ -630,7 +630,12 @@ Extras: make(map[string]string), } - if err := protobufTagToField(tags.Get("protobuf"), &field, m, t, localPackage); err != nil { + protobufTag := tags.Get("protobuf") + if protobufTag == "-" { + continue + } + + if err := protobufTagToField(protobufTag, &field, m, t, localPackage); err != nil { return nil, err } diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/namer.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/namer.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/namer.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/namer.go 2017-05-31 20:30:55.000000000 +0000 @@ -94,7 +94,8 @@ } func protoSafePackage(name string) string { - return strings.Replace(name, "/", ".", -1) + pkg := strings.Replace(name, "/", ".", -1) + return strings.Replace(pkg, "-", "_", -1) } type typeNameSet map[types.Name]*protobufPackage diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/namer_test.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/namer_test.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/go-to-protobuf/protobuf/namer_test.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/go-to-protobuf/protobuf/namer_test.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,50 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package protobuf + +import "testing" + +func TestProtoSafePackage(t *testing.T) { + tests := []struct { + pkg string + expected string + }{ + { + pkg: "foo", + expected: "foo", + }, + { + pkg: "foo/bar", + expected: "foo.bar", + }, + { + pkg: "foo/bar/baz", + expected: "foo.bar.baz", + }, + { + pkg: "foo/bar-baz/x/y-z/q", + expected: "foo.bar_baz.x.y_z.q", + }, + } + + for _, test := range tests { + actual := protoSafePackage(test.pkg) + if e, a := test.expected, actual; e != a { + t.Errorf("%s: expected %s, got %s", test.pkg, e, a) + } + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/byte.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/byte.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/byte.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/byte.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/doc.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/empty.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/empty.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/empty.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/empty.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/int64.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/int64.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/int64.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/int64.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/int.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/int.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/int.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/int.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/string.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/string.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/examples/set-gen/sets/string.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/examples/set-gen/sets/string.go 2017-05-31 20:30:55.000000000 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2016 The Kubernetes Authors. +Copyright 2017 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/execute.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/execute.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/execute.go 2017-02-20 21:48:41.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/execute.go 2017-05-31 20:30:55.000000000 +0000 @@ -251,7 +251,7 @@ } } } - if consts := g.PackageVars(genContext); len(consts) > 0 { + if consts := g.PackageConsts(genContext); len(consts) > 0 { addIndentHeaderComment(&f.Consts, "Package-wide consts from generator %q.", g.Name()) for _, v := range consts { if _, err := fmt.Fprintf(&f.Consts, "%s\n", v); err != nil { diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/generator.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/generator.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/generator.go 2017-02-20 21:48:41.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/generator.go 2017-05-31 20:30:55.000000000 +0000 @@ -206,6 +206,14 @@ // AddDir adds a Go package to the context. The specified path must be a single // go package import path. GOPATH, GOROOT, and the location of your go binary // (`which go`) will all be searched, in the normal Go fashion. +// Deprecated. Please use AddDirectory. func (ctxt *Context) AddDir(path string) error { return ctxt.builder.AddDirTo(path, &ctxt.Universe) } + +// AddDirectory adds a Go package to the context. The specified path must be a +// single go package import path. GOPATH, GOROOT, and the location of your go +// binary (`which go`) will all be searched, in the normal Go fashion. +func (ctxt *Context) AddDirectory(path string) (*types.Package, error) { + return ctxt.builder.AddDirectoryTo(path, &ctxt.Universe) +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/snippet_writer_test.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/snippet_writer_test.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/generator/snippet_writer_test.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/generator/snippet_writer_test.go 2017-05-31 20:30:55.000000000 +0000 @@ -29,7 +29,7 @@ func construct(t *testing.T, files map[string]string) *generator.Context { b := parser.New() for name, src := range files { - if err := b.AddFile("/tmp/"+name, name, []byte(src)); err != nil { + if err := b.AddFileForTest("/tmp/"+name, name, []byte(src)); err != nil { t.Fatal(err) } } @@ -81,7 +81,7 @@ } else { // Dear reader, I apologize for making the worst change // detection test in the history of ever. - if e, a := "snippet_writer_test.go:78", err.Error(); !strings.Contains(a, e) { + if e, a := "snippet_writer_test.go", err.Error(); !strings.Contains(a, e) { t.Errorf("Expected %q but didn't find it in %q", e, a) } } diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/local_parse_test.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/local_parse_test.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/local_parse_test.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/local_parse_test.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,68 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package parser + +import ( + "testing" +) + +func TestImportBuildPackage(t *testing.T) { + b := New() + if _, err := b.importBuildPackage("fake/dep"); err != nil { + t.Fatal(err) + } + if _, ok := b.buildPackages["fake/dep"]; !ok { + t.Errorf("missing expected, but got %v", b.buildPackages) + } + + if len(b.buildPackages) > 1 { + // this would happen if the canonicalization failed to normalize the path + // you'd get a k8s.io/gengo/vendor/fake/dep key too + t.Errorf("missing one, but got %v", b.buildPackages) + } +} + +func TestCanonicalizeImportPath(t *testing.T) { + tcs := []struct { + name string + input string + output string + }{ + { + name: "passthrough", + input: "github.com/foo/bar", + output: "github.com/foo/bar", + }, + { + name: "simple", + input: "github.com/foo/vendor/k8s.io/kubernetes/pkg/api", + output: "k8s.io/kubernetes/pkg/api", + }, + { + name: "deeper", + input: "github.com/foo/bar/vendor/k8s.io/kubernetes/pkg/api", + output: "k8s.io/kubernetes/pkg/api", + }, + } + + for _, tc := range tcs { + actual := canonicalizeImportPath(tc.input) + if string(actual) != tc.output { + t.Errorf("%v: expected %q got %q", tc.name, tc.output, actual) + } + } +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/parse.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/parse.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/parse.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/parse.go 2017-05-31 20:30:55.000000000 +0000 @@ -33,30 +33,38 @@ "k8s.io/gengo/types" ) +// This clarifies when a pkg path has been canonicalized. +type importPathString string + // Builder lets you add all the go files in all the packages that you care // about, then constructs the type source data. type Builder struct { - context *build.Context - buildInfo map[string]*build.Package + context *build.Context + + // Map of package names to more canonical information about the package. + // This might hold the same value for multiple names, e.g. if someone + // referenced ./pkg/name or in the case of vendoring, which canonicalizes + // differently that what humans would type. + buildPackages map[string]*build.Package fset *token.FileSet - // map of package id to list of parsed files - parsed map[string][]parsedFile - // map of package id to absolute path (to prevent overlap) - absPaths map[string]string + // map of package path to list of parsed files + parsed map[importPathString][]parsedFile + // map of package path to absolute path (to prevent overlap) + absPaths map[importPathString]string - // Set by makePackage(), used by importer() and friends. - pkgs map[string]*tc.Package + // Set by typeCheckPackage(), used by importPackage() and friends. + typeCheckedPackages map[importPathString]*tc.Package // Map of package path to whether the user requested it or it was from // an import. - userRequested map[string]bool + userRequested map[importPathString]bool // All comments from everywhere in every parsed file. endLineToCommentGroup map[fileLine]*ast.CommentGroup // map of package to list of packages it imports. - importGraph map[string]map[string]struct{} + importGraph map[importPathString]map[string]struct{} } // parsedFile is for tracking files with name @@ -87,13 +95,14 @@ c.CgoEnabled = false return &Builder{ context: &c, - buildInfo: map[string]*build.Package{}, + buildPackages: map[string]*build.Package{}, + typeCheckedPackages: map[importPathString]*tc.Package{}, fset: token.NewFileSet(), - parsed: map[string][]parsedFile{}, - absPaths: map[string]string{}, - userRequested: map[string]bool{}, + parsed: map[importPathString][]parsedFile{}, + absPaths: map[importPathString]string{}, + userRequested: map[importPathString]bool{}, endLineToCommentGroup: map[fileLine]*ast.CommentGroup{}, - importGraph: map[string]map[string]struct{}{}, + importGraph: map[importPathString]map[string]struct{}{}, } } @@ -105,71 +114,80 @@ // Get package information from the go/build package. Automatically excludes // e.g. test files and files for other platforms-- there is quite a bit of // logic of that nature in the build package. -func (b *Builder) buildPackage(pkgPath string) (*build.Package, error) { - // This is a bit of a hack. The srcDir argument to Import() should - // properly be the dir of the file which depends on the package to be - // imported, so that vendoring can work properly. We assume that there is - // only one level of vendoring, and that the CWD is inside the GOPATH, so - // this should be safe. - cwd, err := os.Getwd() - if err != nil { - return nil, fmt.Errorf("unable to get current directory: %v", err) - } - - // First, find it, so we know what path to use. - pkg, err := b.context.Import(pkgPath, cwd, build.FindOnly) - if err != nil { - return nil, fmt.Errorf("unable to *find* %q: %v", pkgPath, err) - } - - pkgPath = pkg.ImportPath - - if pkg, ok := b.buildInfo[pkgPath]; ok { - return pkg, nil +func (b *Builder) importBuildPackage(dir string) (*build.Package, error) { + if buildPkg, ok := b.buildPackages[dir]; ok { + return buildPkg, nil } - pkg, err = b.context.Import(pkgPath, cwd, build.ImportComment) + // This validates the `package foo // github.com/bar/foo` comments. + buildPkg, err := b.importWithMode(dir, build.ImportComment) if err != nil { if _, ok := err.(*build.NoGoError); !ok { - return nil, fmt.Errorf("unable to import %q: %v", pkgPath, err) + return nil, fmt.Errorf("unable to import %q: %v", dir, err) + } + } + if buildPkg == nil { + // Might be an empty directory. Try to just find the dir. + buildPkg, err = b.importWithMode(dir, build.FindOnly) + if err != nil { + return nil, err } } - b.buildInfo[pkgPath] = pkg - if b.importGraph[pkgPath] == nil { - b.importGraph[pkgPath] = map[string]struct{}{} + // Remember it under the user-provided name. + glog.V(5).Infof("saving buildPackage %s", dir) + b.buildPackages[dir] = buildPkg + canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath) + if dir != string(canonicalPackage) { + // Since `dir` is not the canonical name, see if we knew it under another name. + if buildPkg, ok := b.buildPackages[string(canonicalPackage)]; ok { + return buildPkg, nil + } + // Must be new, save it under the canonical name, too. + glog.V(5).Infof("saving buildPackage %s", canonicalPackage) + b.buildPackages[string(canonicalPackage)] = buildPkg + } + + return buildPkg, nil +} + +// AddFileForTest adds a file to the set, without verifying that the provided +// pkg actually exists on disk. The pkg must be of the form "canonical/pkg/path" +// and the path must be the absolute path to the file. Because this bypasses +// the normal recursive finding of package dependencies (on disk), test should +// sort their test files topologically first, so all deps are resolved by the +// time we need them. +func (b *Builder) AddFileForTest(pkg string, path string, src []byte) error { + if err := b.addFile(importPathString(pkg), path, src, true); err != nil { + return err } - for _, p := range pkg.Imports { - b.importGraph[pkgPath][p] = struct{}{} + if _, err := b.typeCheckPackage(importPathString(pkg)); err != nil { + return err } - return pkg, nil -} - -// AddFile adds a file to the set. The pkg must be of the form -// "canonical/pkg/path" and the path must be the absolute path to the file. -func (b *Builder) AddFile(pkg string, path string, src []byte) error { - return b.addFile(pkg, path, src, true) + return nil } -// addFile adds a file to the set. The pkg must be of the form +// addFile adds a file to the set. The pkgPath must be of the form // "canonical/pkg/path" and the path must be the absolute path to the file. A // flag indicates whether this file was user-requested or just from following // the import graph. -func (b *Builder) addFile(pkg string, path string, src []byte, userRequested bool) error { +func (b *Builder) addFile(pkgPath importPathString, path string, src []byte, userRequested bool) error { + for _, p := range b.parsed[pkgPath] { + if path == p.name { + glog.V(5).Infof("addFile %s %s already parsed, skipping", pkgPath, path) + return nil + } + } + glog.V(6).Infof("addFile %s %s", pkgPath, path) p, err := parser.ParseFile(b.fset, path, src, parser.DeclarationErrors|parser.ParseComments) if err != nil { return err } - dirPath := filepath.Dir(path) - if prev, found := b.absPaths[pkg]; found { - if dirPath != prev { - return fmt.Errorf("package %q (%s) previously resolved to %s", pkg, dirPath, prev) - } - } else { - b.absPaths[pkg] = dirPath - } - b.parsed[pkg] = append(b.parsed[pkg], parsedFile{path, p}) - b.userRequested[pkg] = userRequested + // This is redundant with addDir, but some tests call AddFileForTest, which + // call into here without calling addDir. + b.userRequested[pkgPath] = userRequested || b.userRequested[pkgPath] + + b.parsed[pkgPath] = append(b.parsed[pkgPath], parsedFile{path, p}) for _, c := range p.Comments { position := b.fset.Position(c.End()) b.endLineToCommentGroup[fileLine{position.Filename, position.Line}] = c @@ -177,12 +195,12 @@ // We have to get the packages from this specific file, in case the // user added individual files instead of entire directories. - if b.importGraph[pkg] == nil { - b.importGraph[pkg] = map[string]struct{}{} + if b.importGraph[pkgPath] == nil { + b.importGraph[pkgPath] = map[string]struct{}{} } for _, im := range p.Imports { importedPath := strings.Trim(im.Path.Value, `"`) - b.importGraph[pkg][importedPath] = struct{}{} + b.importGraph[pkgPath][importedPath] = struct{}{} } return nil } @@ -191,45 +209,40 @@ // a single go package in it. GOPATH, GOROOT, and the location of your go // binary (`which go`) will all be searched if dir doesn't literally resolve. func (b *Builder) AddDir(dir string) error { - return b.addDir(dir, true) + _, err := b.importPackage(dir, true) + return err } // AddDirRecursive is just like AddDir, but it also recursively adds // subdirectories; it returns an error only if the path couldn't be resolved; // any directories recursed into without go source are ignored. func (b *Builder) AddDirRecursive(dir string) error { - // This is a bit of a hack. The srcDir argument to Import() should - // properly be the dir of the file which depends on the package to be - // imported, so that vendoring can work properly. We assume that there is - // only one level of vendoring, and that the CWD is inside the GOPATH, so - // this should be safe. - cwd, err := os.Getwd() - if err != nil { - return fmt.Errorf("unable to get current directory: %v", err) - } - - // First, find it, so we know what path to use. - pkg, err := b.context.Import(dir, cwd, build.FindOnly) - if err != nil { - return fmt.Errorf("unable to *find* %q: %v", dir, err) - } - - if err := b.addDir(dir, true); err != nil { + // Add the root. + if _, err := b.importPackage(dir, true); err != nil { glog.Warningf("Ignoring directory %v: %v", dir, err) } - prefix := strings.TrimSuffix(pkg.Dir, strings.TrimSuffix(dir, "/")) - filepath.Walk(pkg.Dir, func(path string, info os.FileInfo, err error) error { + // filepath.Walk includes the root dir, but we already did that, so we'll + // remove that prefix and rebuild a package import path. + prefix := b.buildPackages[dir].Dir + fn := func(path string, info os.FileInfo, err error) error { if info != nil && info.IsDir() { - trimmed := strings.TrimPrefix(path, prefix) - if trimmed != "" { - if err := b.addDir(trimmed, true); err != nil { - glog.Warningf("Ignoring child directory %v: %v", trimmed, err) + rel := strings.TrimPrefix(path, prefix) + if rel != "" { + // Make a pkg path. + pkg := filepath.Join(string(canonicalizeImportPath(b.buildPackages[dir].ImportPath)), rel) + + // Add it. + if _, err := b.importPackage(pkg, true); err != nil { + glog.Warningf("Ignoring child directory %v: %v", pkg, err) } } } return nil - }) + } + if err := filepath.Walk(b.buildPackages[dir].Dir, fn); err != nil { + return err + } return nil } @@ -238,45 +251,67 @@ // generator (rather than just at init time. 'dir' must be a single go package. // GOPATH, GOROOT, and the location of your go binary (`which go`) will all be // searched if dir doesn't literally resolve. +// Deprecated. Please use AddDirectoryTo. func (b *Builder) AddDirTo(dir string, u *types.Universe) error { - if _, found := b.parsed[dir]; !found { - // We want all types from this package, as if they were directly added - // by the user. They WERE added by the user, in effect. - if err := b.addDir(dir, true); err != nil { - return err - } - } else { - // We already had this package, but we want it to be considered as if - // the user addid it directly. - b.userRequested[dir] = true + // We want all types from this package, as if they were directly added + // by the user. They WERE added by the user, in effect. + if _, err := b.importPackage(dir, true); err != nil { + return err + } + return b.findTypesIn(canonicalizeImportPath(b.buildPackages[dir].ImportPath), u) +} + +// AddDirectoryTo adds an entire directory to a given Universe. Unlike AddDir, +// this processes the package immediately, which makes it safe to use from +// within a generator (rather than just at init time. 'dir' must be a single go +// package. GOPATH, GOROOT, and the location of your go binary (`which go`) +// will all be searched if dir doesn't literally resolve. +func (b *Builder) AddDirectoryTo(dir string, u *types.Universe) (*types.Package, error) { + // We want all types from this package, as if they were directly added + // by the user. They WERE added by the user, in effect. + if _, err := b.importPackage(dir, true); err != nil { + return nil, err + } + path := canonicalizeImportPath(b.buildPackages[dir].ImportPath) + if err := b.findTypesIn(path, u); err != nil { + return nil, err } - return b.findTypesIn(dir, u) + return u.Package(string(path)), nil } // The implementation of AddDir. A flag indicates whether this directory was // user-requested or just from following the import graph. func (b *Builder) addDir(dir string, userRequested bool) error { - pkg, err := b.buildPackage(dir) + glog.V(5).Infof("addDir %s", dir) + buildPkg, err := b.importBuildPackage(dir) if err != nil { return err } - // Check in case this package was added (maybe dir was not canonical) - if wasRequested, wasAdded := b.userRequested[dir]; wasAdded { - if !userRequested || userRequested == wasRequested { - return nil + canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath) + pkgPath := canonicalPackage + if dir != string(canonicalPackage) { + glog.V(5).Infof("addDir %s, canonical path is %s", dir, pkgPath) + } + + // Sanity check the pkg dir has not changed. + if prev, found := b.absPaths[pkgPath]; found { + if buildPkg.Dir != prev { + return fmt.Errorf("package %q (%s) previously resolved to %s", pkgPath, buildPkg.Dir, prev) } + } else { + b.absPaths[pkgPath] = buildPkg.Dir } - for _, n := range pkg.GoFiles { + for _, n := range buildPkg.GoFiles { if !strings.HasSuffix(n, ".go") { continue } - absPath := filepath.Join(pkg.Dir, n) + absPath := filepath.Join(buildPkg.Dir, n) data, err := ioutil.ReadFile(absPath) if err != nil { return fmt.Errorf("while loading %q: %v", absPath, err) } - err = b.addFile(dir, absPath, data, userRequested) + err = b.addFile(pkgPath, absPath, data, userRequested) if err != nil { return fmt.Errorf("while parsing %q: %v", absPath, err) } @@ -284,32 +319,59 @@ return nil } -// importer is a function that will be called by the type check package when it -// needs to import a go package. 'path' is the import path. go1.5 changes the -// interface, and importAdapter below implements the new interface in terms of -// the old one. -func (b *Builder) importer(imports map[string]*tc.Package, path string) (*tc.Package, error) { - if pkg, ok := imports[path]; ok { - return pkg, nil +// importPackage is a function that will be called by the type check package when it +// needs to import a go package. 'path' is the import path. +func (b *Builder) importPackage(dir string, userRequested bool) (*tc.Package, error) { + glog.V(5).Infof("importPackage %s", dir) + var pkgPath = importPathString(dir) + + // Get the canonical path if we can. + if buildPkg := b.buildPackages[dir]; buildPkg != nil { + canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath) + glog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage) + pkgPath = canonicalPackage } + + // If we have not seen this before, process it now. ignoreError := false - if _, ours := b.parsed[path]; !ours { + if _, found := b.parsed[pkgPath]; !found { // Ignore errors in paths that we're importing solely because // they're referenced by other packages. ignoreError = true - if err := b.addDir(path, false); err != nil { + + // Add it. + if err := b.addDir(dir, userRequested); err != nil { return nil, err } + + // Get the canonical path now that it has been added. + if buildPkg := b.buildPackages[dir]; buildPkg != nil { + canonicalPackage := canonicalizeImportPath(buildPkg.ImportPath) + glog.V(5).Infof("importPackage %s, canonical path is %s", dir, canonicalPackage) + pkgPath = canonicalPackage + } } - pkg, err := b.typeCheckPackage(path) + + // If it was previously known, just check that the user-requestedness hasn't + // changed. + b.userRequested[pkgPath] = userRequested || b.userRequested[pkgPath] + + // Run the type checker. We may end up doing this to pkgs that are already + // done, or are in the queue to be done later, but it will short-circuit, + // and we can't miss pkgs that are only depended on. + pkg, err := b.typeCheckPackage(pkgPath) if err != nil { - if ignoreError && pkg != nil { - glog.V(2).Infof("type checking encountered some errors in %q, but ignoring.\n", path) - } else { + switch { + case ignoreError && pkg != nil: + glog.V(2).Infof("type checking encountered some issues in %q, but ignoring.\n", pkgPath) + case !ignoreError && pkg != nil: + glog.V(2).Infof("type checking encountered some errors in %q\n", pkgPath) + return nil, err + default: return nil, err } } - imports[path] = pkg + return pkg, nil } @@ -318,85 +380,58 @@ } func (a importAdapter) Import(path string) (*tc.Package, error) { - return a.b.importer(a.b.pkgs, path) + return a.b.importPackage(path, false) } // typeCheckPackage will attempt to return the package even if there are some // errors, so you may check whether the package is nil or not even if you get // an error. -func (b *Builder) typeCheckPackage(id string) (*tc.Package, error) { - if pkg, ok := b.pkgs[id]; ok { +func (b *Builder) typeCheckPackage(pkgPath importPathString) (*tc.Package, error) { + glog.V(5).Infof("typeCheckPackage %s", pkgPath) + if pkg, ok := b.typeCheckedPackages[pkgPath]; ok { if pkg != nil { + glog.V(6).Infof("typeCheckPackage %s already done", pkgPath) return pkg, nil } // We store a nil right before starting work on a package. So // if we get here and it's present and nil, that means there's // another invocation of this function on the call stack // already processing this package. - return nil, fmt.Errorf("circular dependency for %q", id) + return nil, fmt.Errorf("circular dependency for %q", pkgPath) } - parsedFiles, ok := b.parsed[id] + parsedFiles, ok := b.parsed[pkgPath] if !ok { - return nil, fmt.Errorf("No files for pkg %q: %#v", id, b.parsed) + return nil, fmt.Errorf("No files for pkg %q: %#v", pkgPath, b.parsed) } files := make([]*ast.File, len(parsedFiles)) for i := range parsedFiles { files[i] = parsedFiles[i].file } - b.pkgs[id] = nil + b.typeCheckedPackages[pkgPath] = nil c := tc.Config{ IgnoreFuncBodies: true, - // Note that importAdater can call b.import which calls this + // Note that importAdapter can call b.importPackage which calls this // method. So there can't be cycles in the import graph. Importer: importAdapter{b}, Error: func(err error) { - glog.V(2).Infof("type checker error: %v\n", err) + glog.V(2).Infof("type checker: %v\n", err) }, } - pkg, err := c.Check(id, b.fset, files, nil) - b.pkgs[id] = pkg // record the result whether or not there was an error + pkg, err := c.Check(string(pkgPath), b.fset, files, nil) + b.typeCheckedPackages[pkgPath] = pkg // record the result whether or not there was an error return pkg, err } -func (b *Builder) makeAllPackages() error { - // Take a snapshot to iterate, since this will recursively mutate b.parsed. - keys := []string{} - for id := range b.parsed { - keys = append(keys, id) - } - for _, id := range keys { - if _, err := b.makePackage(id); err != nil { - return err - } - } - return nil -} - -func (b *Builder) makePackage(id string) (*tc.Package, error) { - if b.pkgs == nil { - b.pkgs = map[string]*tc.Package{} - } - - // We have to check here even though we made a new one above, - // because typeCheckPackage follows the import graph, which may - // cause a package to be filled before we get to it in this - // loop. - if pkg, done := b.pkgs[id]; done { - return pkg, nil - } - return b.typeCheckPackage(id) -} - // FindPackages fetches a list of the user-imported packages. // Note that you need to call b.FindTypes() first. func (b *Builder) FindPackages() []string { result := []string{} - for pkgPath := range b.pkgs { + for pkgPath := range b.typeCheckedPackages { if b.userRequested[pkgPath] { // Since walkType is recursive, all types that are in packages that // were directly mentioned will be included. We don't need to // include all types in all transitive packages, though. - result = append(result, pkgPath) + result = append(result, string(pkgPath)) } } return result @@ -405,13 +440,15 @@ // FindTypes finalizes the package imports, and searches through all the // packages for types. func (b *Builder) FindTypes() (types.Universe, error) { - if err := b.makeAllPackages(); err != nil { - return nil, err - } - u := types.Universe{} + // Take a snapshot of pkgs to iterate, since this will recursively mutate + // b.parsed. + keys := []importPathString{} for pkgPath := range b.parsed { + keys = append(keys, pkgPath) + } + for _, pkgPath := range keys { if err := b.findTypesIn(pkgPath, &u); err != nil { return nil, err } @@ -421,22 +458,32 @@ // findTypesIn finalizes the package import and searches through the package // for types. -func (b *Builder) findTypesIn(pkgPath string, u *types.Universe) error { - pkg, err := b.makePackage(pkgPath) - if err != nil { - return err +func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error { + glog.V(5).Infof("findTypesIn %s", pkgPath) + pkg := b.typeCheckedPackages[pkgPath] + if pkg == nil { + return fmt.Errorf("findTypesIn(%s): package is not known", pkgPath) } if !b.userRequested[pkgPath] { // Since walkType is recursive, all types that the // packages they asked for depend on will be included. // But we don't need to include all types in all // *packages* they depend on. + glog.V(5).Infof("findTypesIn %s: package is not user requested", pkgPath) return nil } + // We're keeping this package. This call will create the record. + u.Package(string(pkgPath)).Name = pkg.Name() + u.Package(string(pkgPath)).Path = pkg.Path() + u.Package(string(pkgPath)).SourcePath = b.absPaths[pkgPath] + for _, f := range b.parsed[pkgPath] { if strings.HasSuffix(f.name, "/doc.go") { - tp := u.Package(pkgPath) + tp := u.Package(string(pkgPath)) + // findTypesIn might be called multiple times. Clean up tp.Comments + // to avoid repeatedly fill same comments to it. + tp.Comments = []string{} for i := range f.file.Comments { tp.Comments = append(tp.Comments, splitLines(f.file.Comments[i].Text())...) } @@ -480,12 +527,30 @@ } } for p := range b.importGraph[pkgPath] { - u.AddImports(pkgPath, p) + u.AddImports(string(pkgPath), p) } - u.Package(pkgPath).Name = pkg.Name() return nil } +func (b *Builder) importWithMode(dir string, mode build.ImportMode) (*build.Package, error) { + // This is a bit of a hack. The srcDir argument to Import() should + // properly be the dir of the file which depends on the package to be + // imported, so that vendoring can work properly and local paths can + // resolve. We assume that there is only one level of vendoring, and that + // the CWD is inside the GOPATH, so this should be safe. Nobody should be + // using local (relative) paths except on the CLI, so CWD is also + // sufficient. + cwd, err := os.Getwd() + if err != nil { + return nil, fmt.Errorf("unable to get current directory: %v", err) + } + buildPkg, err := b.context.Import(dir, cwd, mode) + if err != nil { + return nil, err + } + return buildPkg, nil +} + // if there's a comment on the line `lines` before pos, return its text, otherwise "". func (b *Builder) priorCommentLines(pos token.Pos, lines int) *ast.CommentGroup { position := b.fset.Position(pos) @@ -656,16 +721,16 @@ } return out case *tc.Named: + var out *types.Type switch t.Underlying().(type) { case *tc.Named, *tc.Basic, *tc.Map, *tc.Slice: name := tcNameToName(t.String()) - out := u.Type(name) + out = u.Type(name) if out.Kind != types.Unknown { return out } out.Kind = types.Alias out.Underlying = b.walkType(u, nil, t.Underlying()) - return out default: // tc package makes everything "named" with an // underlying anonymous type--we remove that annoying @@ -675,20 +740,19 @@ if out := u.Type(name); out.Kind != types.Unknown { return out // short circuit if we've already made this. } - out := b.walkType(u, &name, t.Underlying()) - 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++ { - if out.Methods == nil { - out.Methods = map[string]*types.Type{} - } - out.Methods[t.Method(i).Name()] = b.walkType(u, nil, t.Method(i).Type()) + 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 { + for i := 0; i < t.NumMethods(); i++ { + if out.Methods == nil { + out.Methods = map[string]*types.Type{} } + out.Methods[t.Method(i).Name()] = b.walkType(u, nil, t.Method(i).Type()) } - return out } + return out default: out := u.Type(name) if out.Kind != types.Unknown { @@ -721,3 +785,13 @@ out.Underlying = b.walkType(u, nil, in.Type()) return out } + +// canonicalizeImportPath takes an import path and returns the actual package. +// It doesn't support nested vendoring. +func canonicalizeImportPath(importPath string) importPathString { + if !strings.Contains(importPath, "/vendor/") { + return importPathString(importPath) + } + + return importPathString(importPath[strings.Index(importPath, "/vendor/")+len("/vendor/"):]) +} diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/parse_test.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/parse_test.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/parser/parse_test.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/parser/parse_test.go 2017-05-31 20:30:55.000000000 +0000 @@ -52,10 +52,16 @@ } } -func construct(t *testing.T, files map[string]string, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) { +type file struct { + path string + contents string +} + +// Pass files in topological order - deps first! +func construct(t *testing.T, files []file, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) { b := parser.New() - for name, src := range files { - if err := b.AddFile(filepath.Dir(name), name, []byte(src)); err != nil { + for _, f := range files { + if err := b.AddFileForTest(filepath.Dir(f.path), f.path, []byte(f.contents)); err != nil { t.Fatal(err) } } @@ -69,48 +75,51 @@ } func TestBuilder(t *testing.T) { - var testFiles = map[string]string{ - "base/foo/proto/foo.go": ` -package foo - -import ( - "base/common/proto" -) - -type Blah struct { - common.Object - Count int64 - Frobbers map[string]*Frobber - Baz []Object - Nickname *string - NumberIsAFavorite map[int]bool -} - -type Frobber struct { - Name string - Amount int64 -} - -type Object struct { - common.Object -} - -func AFunc(obj1 common.Object, obj2 Object) Frobber { -} - -var AVar Frobber - -var ( - AnotherVar = Frobber{} -) -`, - "base/common/proto/common.go": ` -package common + var testFiles = []file{ + { + path: "base/common/proto/common.go", contents: ` + package common -type Object struct { - ID int64 -} -`, + type Object struct { + ID int64 + } + `, + }, { + path: "base/foo/proto/foo.go", contents: ` + package foo + + import ( + "base/common/proto" + ) + + type Blah struct { + common.Object + Count int64 + Frobbers map[string]*Frobber + Baz []Object + Nickname *string + NumberIsAFavorite map[int]bool + } + + type Frobber struct { + Name string + Amount int64 + } + + type Object struct { + common.Object + } + + func AFunc(obj1 common.Object, obj2 Object) Frobber { + } + + var AVar Frobber + + var ( + AnotherVar = Frobber{} + ) + `, + }, } var tmplText = ` @@ -195,24 +204,25 @@ } func TestStructParse(t *testing.T) { - var structTest = map[string]string{ - "base/foo/proto/foo.go": ` -package foo - -// Blah is a test. -// A test, I tell you. -type Blah struct { - // A is the first field. - A int64 ` + "`" + `json:"a"` + "`" + ` - - // B is the second field. - // Multiline comments work. - B string ` + "`" + `json:"b"` + "`" + ` -} -`, + var structTest = file{ + path: "base/foo/proto/foo.go", + contents: ` + package foo + + // Blah is a test. + // A test, I tell you. + type Blah struct { + // A is the first field. + A int64 ` + "`" + `json:"a"` + "`" + ` + + // B is the second field. + // Multiline comments work. + B string ` + "`" + `json:"b"` + "`" + ` + } + `, } - _, u, o := construct(t, structTest, namer.NewPublicNamer(0)) + _, u, o := construct(t, []file{structTest}, namer.NewPublicNamer(0)) t.Logf("%#v", o) blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"}) if blahT == nil { @@ -239,36 +249,40 @@ func TestParseSecondClosestCommentLines(t *testing.T) { const fileName = "base/foo/proto/foo.go" testCases := []struct { - testFile map[string]string + testFile file expected []string }{ { - map[string]string{fileName: `package foo -// Blah's SecondClosestCommentLines. -// Another line. - -// Blah is a test. -// A test, I tell you. -type Blah struct { - a int -} -`}, - []string{"Blah's SecondClosestCommentLines.", "Another line."}, + testFile: file{ + path: fileName, contents: ` + package foo + // Blah's SecondClosestCommentLines. + // Another line. + + // Blah is a test. + // A test, I tell you. + type Blah struct { + a int + } + `}, + expected: []string{"Blah's SecondClosestCommentLines.", "Another line."}, }, { - map[string]string{fileName: `package foo -// Blah's SecondClosestCommentLines. -// Another line. - -type Blah struct { - a int -} -`}, - []string{"Blah's SecondClosestCommentLines.", "Another line."}, + testFile: file{ + path: fileName, contents: ` + package foo + // Blah's SecondClosestCommentLines. + // Another line. + + type Blah struct { + a int + } + `}, + expected: []string{"Blah's SecondClosestCommentLines.", "Another line."}, }, } for _, test := range testCases { - _, u, o := construct(t, test.testFile, namer.NewPublicNamer(0)) + _, u, o := construct(t, []file{test.testFile}, namer.NewPublicNamer(0)) t.Logf("%#v", o) blahT := u.Type(types.Name{Package: "base/foo/proto", Name: "Blah"}) if e, a := test.expected, blahT.SecondClosestCommentLines; !reflect.DeepEqual(e, a) { @@ -278,35 +292,35 @@ } func TestTypeKindParse(t *testing.T) { - var testFiles = map[string]string{ - "a/foo.go": "package a\ntype Test string\n", - "b/foo.go": "package b\ntype Test map[int]string\n", - "c/foo.go": "package c\ntype Test []string\n", - "d/foo.go": "package d\ntype Test struct{a int; b struct{a int}; c map[int]string; d *string}\n", - "e/foo.go": "package e\ntype Test *string\n", - "f/foo.go": ` -package f -import ( - "a" - "b" -) -type Test []a.Test -type Test2 *a.Test -type Test3 map[a.Test]b.Test -type Test4 struct { - a struct {a a.Test; b b.Test} - b map[a.Test]b.Test - c *a.Test - d []a.Test - e []string -} -`, - "g/foo.go": ` -package g -type Test func(a, b string) (c, d string) -func (t Test) Method(a, b string) (c, d string) { return t(a, b) } -type Interface interface{Method(a, b string) (c, d string)} -`, + var testFiles = []file{ + {path: "a/foo.go", contents: "package a\ntype Test string\n"}, + {path: "b/foo.go", contents: "package b\ntype Test map[int]string\n"}, + {path: "c/foo.go", contents: "package c\ntype Test []string\n"}, + {path: "d/foo.go", contents: "package d\ntype Test struct{a int; b struct{a int}; c map[int]string; d *string}\n"}, + {path: "e/foo.go", contents: "package e\ntype Test *string\n"}, + {path: "f/foo.go", contents: ` + package f + import ( + "a" + "b" + ) + type Test []a.Test + type Test2 *a.Test + type Test3 map[a.Test]b.Test + type Test4 struct { + a struct {a a.Test; b b.Test} + b map[a.Test]b.Test + c *a.Test + d []a.Test + e []string + } + `}, + {path: "g/foo.go", contents: ` + package g + type Test func(a, b string) (c, d string) + func (t Test) Method(a, b string) (c, d string) { return t(a, b) } + type Interface interface{Method(a, b string) (c, d string)} + `}, } // Check that the right types are found, and the namers give the expected names. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/.travis.yml golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/.travis.yml --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/.travis.yml 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/.travis.yml 2017-05-31 20:30:55.000000000 +0000 @@ -7,6 +7,7 @@ go_import_path: k8s.io/gengo script: + - find . -name Makefile | xargs -n1 dirname | while read DIR; do make -C $DIR test; done - go test -v ./... - go run ./examples/set-gen/main.go -i k8s.io/gengo/examples/set-gen/sets/types -o ./examples/set-gen/sets --verify-only - go run ./examples/import-boss/main.go -i k8s.io/gengo/... --verify-only diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/types/types.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/types/types.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/types/types.go 2017-02-20 21:49:27.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/types/types.go 2017-05-31 20:30:55.000000000 +0000 @@ -94,14 +94,18 @@ // Canonical name of this package-- its path. Path string + // The location this package was loaded from + SourcePath string + // Short name of this package; the name that appears in the // 'package x' line. Name string - // DocComments from doc.go, if any. + // The comment right above the package declaration in doc.go, if any. DocComments []string - // Comments from doc.go, if any. + // All comments from doc.go, if any. + // TODO: remove Comments and use DocComments everywhere. Comments []string // Types within this package, indexed by their name (*not* including @@ -160,7 +164,7 @@ 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 // responsibility to finish construction of the variable by setting Underlying // to the correct type. diff -Nru golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/vendor/fake/dep/doc.go golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/vendor/fake/dep/doc.go --- golang-github-kubernetes-gengo-0.0~git20161024.0.6a1c24d/vendor/fake/dep/doc.go 1970-01-01 00:00:00.000000000 +0000 +++ golang-github-kubernetes-gengo-0.0~git20170531.0.c79c13d/vendor/fake/dep/doc.go 2017-05-31 20:30:55.000000000 +0000 @@ -0,0 +1,3 @@ +// this exists as a fake vendored dependency so that the vendor path canonicalization +// can be reliably tested +package dep