main.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // deepcopy-gen is a tool for auto-generating DeepCopy functions.
  14. //
  15. // Given a list of input directories, it will generate functions that
  16. // efficiently perform a full deep-copy of each type. For any type that
  17. // offers a `.DeepCopy()` method, it will simply call that. Otherwise it will
  18. // use standard value assignment whenever possible. If that is not possible it
  19. // will try to call its own generated copy function for the type, if the type is
  20. // within the allowed root packages. Failing that, it will fall back on
  21. // `conversion.Cloner.DeepCopy(val)` to make the copy. The resulting file will
  22. // be stored in the same directory as the processed source package.
  23. //
  24. // Generation is governed by comment tags in the source. Any package may
  25. // request DeepCopy generation by including a comment in the file-comments of
  26. // one file, of the form:
  27. // // +k8s:deepcopy-gen=package
  28. //
  29. // Packages can request that the generated DeepCopy functions be registered
  30. // with an `init()` function call to `Scheme.AddGeneratedDeepCopyFuncs()` by
  31. // changing the tag to:
  32. // // +k8s:deepcopy-gen=package,register
  33. //
  34. // DeepCopy functions can be generated for individual types, rather than the
  35. // entire package by specifying a comment on the type definion of the form:
  36. // // +k8s:deepcopy-gen=true
  37. //
  38. // When generating for a whole package, individual types may opt out of
  39. // DeepCopy generation by specifying a comment on the of the form:
  40. // // +k8s:deepcopy-gen=false
  41. //
  42. // Note that registration is a whole-package option, and is not available for
  43. // individual types.
  44. package main
  45. import (
  46. "k8s.io/kubernetes/cmd/libs/go2idl/args"
  47. "k8s.io/kubernetes/cmd/libs/go2idl/deepcopy-gen/generators"
  48. "github.com/golang/glog"
  49. "github.com/spf13/pflag"
  50. )
  51. func main() {
  52. arguments := args.Default()
  53. // Override defaults.
  54. arguments.OutputFileBaseName = "deepcopy_generated"
  55. // Custom args.
  56. customArgs := &generators.CustomArgs{}
  57. pflag.CommandLine.StringSliceVar(&customArgs.BoundingDirs, "bounding-dirs", customArgs.BoundingDirs,
  58. "Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
  59. arguments.CustomArgs = customArgs
  60. // Run it.
  61. if err := arguments.Execute(
  62. generators.NameSystems(),
  63. generators.DefaultNameSystem(),
  64. generators.Packages,
  65. ); err != nil {
  66. glog.Fatalf("Error: %v", err)
  67. }
  68. glog.V(2).Info("Completed successfully.")
  69. }