main.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright 2016 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. // conversion-gen is a tool for auto-generating Conversion functions.
  14. //
  15. // Given a list of input directories, it will scan for "peer" packages and
  16. // generate functions that efficiently convert between same-name types in each
  17. // package. For any pair of types that has a
  18. // `Convert_<pkg1>_<type>_To_<pkg2>_<Type()`
  19. // function (and its reciprocal), it will simply call that. use standard value
  20. // assignment whenever possible. The resulting file will be stored in the same
  21. // directory as the processed source package.
  22. //
  23. // Generation is governed by comment tags in the source. Any package may
  24. // request Conversion generation by including a comment in the file-comments of
  25. // one file, of the form:
  26. // // +k8s:conversion-gen=<import-path-of-peer-package>
  27. //
  28. // When generating for a package, individual types or fields of structs may opt
  29. // out of Conversion generation by specifying a comment on the of the form:
  30. // // +k8s:conversion-gen=false
  31. package main
  32. import (
  33. "k8s.io/kubernetes/cmd/libs/go2idl/args"
  34. "k8s.io/kubernetes/cmd/libs/go2idl/conversion-gen/generators"
  35. "github.com/golang/glog"
  36. "github.com/spf13/pflag"
  37. )
  38. func main() {
  39. arguments := args.Default()
  40. // Override defaults.
  41. arguments.OutputFileBaseName = "conversion_generated"
  42. // Custom args.
  43. customArgs := &generators.CustomArgs{
  44. ExtraPeerDirs: []string{
  45. "k8s.io/kubernetes/pkg/api",
  46. "k8s.io/kubernetes/pkg/api/v1",
  47. "k8s.io/kubernetes/pkg/api/unversioned",
  48. "k8s.io/kubernetes/pkg/conversion",
  49. "k8s.io/kubernetes/pkg/runtime",
  50. },
  51. }
  52. pflag.CommandLine.StringSliceVar(&customArgs.ExtraPeerDirs, "extra-peer-dirs", customArgs.ExtraPeerDirs,
  53. "Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.")
  54. arguments.CustomArgs = customArgs
  55. // Run it.
  56. if err := arguments.Execute(
  57. generators.NameSystems(),
  58. generators.DefaultNameSystem(),
  59. generators.Packages,
  60. ); err != nil {
  61. glog.Fatalf("Error: %v", err)
  62. }
  63. glog.V(2).Info("Completed successfully.")
  64. }