func generateDeepCopies(t *testing.T, version string) bytes.Buffer { g := runtime.NewDeepCopyGenerator(api.Scheme.Raw()) g.OverwritePackage(version, "") testedVersion := version if version == "api" { testedVersion = api.Scheme.Raw().InternalVersion } for _, knownType := range api.Scheme.KnownTypes(testedVersion) { if err := g.AddType(knownType); err != nil { glog.Errorf("error while generating deep-copy functions for %v: %v", knownType, err) } } var functions bytes.Buffer functionsWriter := bufio.NewWriter(&functions) if err := g.WriteImports(functionsWriter, version); err != nil { t.Fatalf("couldn't generate deep-copy function imports: %v", err) } if err := g.WriteDeepCopyFunctions(functionsWriter); err != nil { t.Fatalf("couldn't generate deep-copy functions: %v", err) } if err := g.RegisterDeepCopyFunctions(functionsWriter, version); err != nil { t.Fatalf("couldn't generate deep-copy function names: %v", err) } if err := functionsWriter.Flush(); err != nil { t.Fatalf("error while flushing writer") } return functions }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() var funcOut io.Writer if *functionDest == "-" { funcOut = os.Stdout } else { file, err := os.Create(*functionDest) if err != nil { glog.Fatalf("Couldn't open %v: %v", *functionDest, err) } defer file.Close() funcOut = file } knownVersion := *version registerTo := "api.Scheme" if knownVersion == "api" { knownVersion = api.Scheme.Raw().InternalVersion registerTo = "Scheme" } pkgPath := path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", knownVersion) generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw(), pkgPath, util.NewStringSet("github.com/GoogleCloudPlatform/kubernetes")) generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api") if len(*overwrites) > 0 { for _, overwrite := range strings.Split(*overwrites, ",") { if !strings.Contains(overwrite, "=") { glog.Fatalf("Invalid overwrite syntax: %s", overwrite) } vals := strings.Split(overwrite, "=") generator.OverwritePackage(vals[0], vals[1]) } } for _, knownType := range api.Scheme.KnownTypes(knownVersion) { if err := generator.AddType(knownType); err != nil { glog.Errorf("error while generating deep copy functions for %v: %v", knownType, err) } } generator.RepackImports() if err := generator.WriteImports(funcOut); err != nil { glog.Fatalf("error while writing imports: %v", err) } if err := generator.WriteDeepCopyFunctions(funcOut); err != nil { glog.Fatalf("error while writing deep copy functions: %v", err) } if err := generator.RegisterDeepCopyFunctions(funcOut, registerTo); err != nil { glog.Fatalf("error while registering deep copy functions: %v", err) } }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() var funcOut io.Writer if *functionDest == "-" { funcOut = os.Stdout } else { file, err := os.Create(*functionDest) if err != nil { glog.Fatalf("Couldn't open %v: %v", *functionDest, err) } defer file.Close() funcOut = file } knownVersion := *version if knownVersion == "api" { knownVersion = api.Scheme.Raw().InternalVersion } generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw(), "github.com/openshift/origin/pkg/api", util.NewStringSet("github.com/openshift/origin")) apiShort := generator.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api") generator.ReplaceType("github.com/GoogleCloudPlatform/kubernetes/pkg/util", "empty", struct{}{}) for _, overwrite := range strings.Split(*overwrites, ",") { vals := strings.Split(overwrite, "=") generator.OverwritePackage(vals[0], vals[1]) } for _, knownType := range api.Scheme.KnownTypes(knownVersion) { if !strings.Contains(knownType.PkgPath(), "openshift/origin") { continue } if err := generator.AddType(knownType); err != nil { glog.Errorf("error while generating deep copy functions for %v: %v", knownType, err) } } generator.RepackImports() if err := generator.WriteImports(funcOut); err != nil { glog.Fatalf("error while writing imports: %v", err) } if err := generator.WriteDeepCopyFunctions(funcOut); err != nil { glog.Fatalf("error while writing deep copy functions: %v", err) } if err := generator.RegisterDeepCopyFunctions(funcOut, fmt.Sprintf("%s.Scheme", apiShort)); err != nil { glog.Fatalf("error while registering deep copy functions: %v", err) } }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() var funcOut io.Writer if *functionDest == "-" { funcOut = os.Stdout } else { file, err := os.Create(*functionDest) if err != nil { glog.Fatalf("Couldn't open %v: %v", *functionDest, err) } defer file.Close() funcOut = file } knownVersion := *version if knownVersion == "api" { knownVersion = api.Scheme.Raw().InternalVersion } generator := pkg_runtime.NewDeepCopyGenerator(api.Scheme.Raw()) for _, overwrite := range strings.Split(*overwrites, ",") { vals := strings.Split(overwrite, "=") generator.OverwritePackage(vals[0], vals[1]) } for _, knownType := range api.Scheme.KnownTypes(knownVersion) { if err := generator.AddType(knownType); err != nil { glog.Errorf("error while generating deep copy functions for %v: %v", knownType, err) } } if err := generator.WriteImports(funcOut, *version); err != nil { glog.Fatalf("error while writing imports: %v", err) } if err := generator.WriteDeepCopyFunctions(funcOut); err != nil { glog.Fatalf("error while writing deep copy functions: %v", err) } if err := generator.RegisterDeepCopyFunctions(funcOut, *version); err != nil { glog.Fatalf("error while registering deep copy functions: %v", err) } }
func generateDeepCopies(t *testing.T, version string) bytes.Buffer { testedVersion := version registerTo := "api.Scheme" if testedVersion == "api" { testedVersion = api.Scheme.Raw().InternalVersion registerTo = "Scheme" } g := runtime.NewDeepCopyGenerator(api.Scheme.Raw(), path.Join("github.com/GoogleCloudPlatform/kubernetes/pkg/api", testedVersion), util.NewStringSet("github.com/GoogleCloudPlatform/kubernetes")) g.AddImport("github.com/GoogleCloudPlatform/kubernetes/pkg/api") g.OverwritePackage(version, "") for _, knownType := range api.Scheme.KnownTypes(testedVersion) { if err := g.AddType(knownType); err != nil { glog.Errorf("error while generating deep-copy functions for %v: %v", knownType, err) } } var functions bytes.Buffer functionsWriter := bufio.NewWriter(&functions) g.RepackImports() if err := g.WriteImports(functionsWriter); err != nil { t.Fatalf("couldn't generate deep-copy function imports: %v", err) } if err := g.WriteDeepCopyFunctions(functionsWriter); err != nil { t.Fatalf("couldn't generate deep-copy functions: %v", err) } if err := g.RegisterDeepCopyFunctions(functionsWriter, registerTo); err != nil { t.Fatalf("couldn't generate deep-copy function names: %v", err) } if err := functionsWriter.Flush(); err != nil { t.Fatalf("error while flushing writer") } return functions }