main.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // deepcopy-gen is a tool for auto-generating DeepCopy functions.
  2. //
  3. // Given a list of input directories, it will generate DeepCopy and DeepCopyInto
  4. // methods that efficiently perform a full deep-copy of each type. If these
  5. // already exist (are predefined by the developer), they are used instead of
  6. // generating new ones.
  7. //
  8. // If interfaces are referenced in types, it is expected that corresponding
  9. // DeepCopyInterfaceName methods exist, e.g. DeepCopyObject for runtime.Object.
  10. // These can be predefined by the developer or generated through tags, see below.
  11. // They must be added to the interfaces themselves manually, e.g.
  12. // type Object interface {
  13. // ...
  14. // DeepCopyObject() Object
  15. // }
  16. //
  17. // All generation is governed by comment tags in the source. Any package may
  18. // request DeepCopy generation by including a comment in the file-comments of
  19. // one file, of the form:
  20. // // +bili:deepcopy-gen=package
  21. //
  22. // DeepCopy functions can be generated for individual types, rather than the
  23. // entire package by specifying a comment on the type definion of the form:
  24. // // +bili:deepcopy-gen=true
  25. //
  26. // When generating for a whole package, individual types may opt out of
  27. // DeepCopy generation by specifying a comment on the type definition of the form:
  28. // // +bili:deepcopy-gen=false
  29. //
  30. // Additional DeepCopyInterfaceName methods can be generated by sepcifying a
  31. // comment on the type definition of the form:
  32. // // +bili:deepcopy-gen:interfaces=k8s.io/kubernetes/runtime.Object,k8s.io/kubernetes/runtime.List
  33. // This leads to the generation of DeepCopyObject and DeepCopyList with the given
  34. // interfaces as return types. We say that the tagged type implements deepcopy for the
  35. // interfaces.
  36. //
  37. // The deepcopy funcs for interfaces using "+bili:deepcopy-gen:interfaces" use the pointer
  38. // of the type as receiver. For those special cases where the non-pointer object should
  39. // implement the interface, this can be done with:
  40. // // +bili:deepcopy-gen:nonpointer-interfaces=true
  41. package main
  42. import (
  43. "flag"
  44. "go-common/app/tool/gengo/args"
  45. "go-common/app/tool/gengo/cmd/deepcopy-gen/generators"
  46. "github.com/golang/glog"
  47. )
  48. func main() {
  49. arguments := args.Default()
  50. // Override defaults.
  51. arguments.OutputFileBaseName = "deepcopy_generated"
  52. // Custom args.
  53. customArgs := &generators.CustomArgs{}
  54. flag.CommandLine.Var(&customArgs.BoundingDirs, "bounding-dirs", "Comma-separated list of import paths which bound the types for which deep-copies will be generated.")
  55. arguments.CustomArgs = customArgs
  56. // Run it.
  57. if err := arguments.Execute(
  58. generators.NameSystems(),
  59. generators.DefaultNameSystem(),
  60. generators.Packages,
  61. ); err != nil {
  62. glog.Fatalf("Error: %v", err)
  63. }
  64. glog.V(2).Info("Completed successfully.")
  65. }