Merge pull request #27921 from smarterclayton/conversion_bugs

Automatic merge from submit-queue

Make generated build tag parameterizable for go2idl

Downstream generators that want to reuse the upstream generated types
need to be able to define a different ignore tag (so that they can see
the already generated types).

@wojtek-t allows third parties to reuse conversions in api/v1 (for instance) because otherwise they are hidden when go2idl parses the dependency packages.
This commit is contained in:
k8s-merge-robot 2016-07-04 00:45:26 -07:00 committed by GitHub
commit 37edcc8242
4 changed files with 18 additions and 13 deletions

View File

@ -39,8 +39,9 @@ import (
// before calling AddFlags.
func Default() *GeneratorArgs {
generatorArgs := &GeneratorArgs{
OutputBase: DefaultSourceTree(),
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt"),
OutputBase: DefaultSourceTree(),
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/kubernetes/hack/boilerplate/boilerplate.go.txt"),
GeneratedBuildTag: "ignore_autogenerated",
}
generatorArgs.AddFlags(pflag.CommandLine)
return generatorArgs
@ -66,6 +67,12 @@ type GeneratorArgs struct {
// If true, only verify, don't write anything.
VerifyOnly bool
// GeneratedBuildTag is the tag used to identify code generated by execution
// of this type. Each generator should use a different tag, and different
// groups of generators (external API that depends on Kube generations) should
// keep tags distinct as well.
GeneratedBuildTag string
// Any custom arguments go here
CustomArgs interface{}
}
@ -77,6 +84,7 @@ func (g *GeneratorArgs) AddFlags(fs *pflag.FlagSet) {
fs.StringVarP(&g.GoHeaderFilePath, "go-header-file", "h", g.GoHeaderFilePath, "File containing boilerplate header text. The string YEAR will be replaced with the current 4-digit year.")
fs.BoolVar(&g.VerifyOnly, "verify-only", g.VerifyOnly, "If true, only verify existing output, do not write anything.")
fs.BoolVar(&g.Recursive, "recursive", g.VerifyOnly, "If true, recurse into all children of input directories.")
fs.StringVar(&g.GeneratedBuildTag, "build-tag", g.GeneratedBuildTag, "A Go build tag to use to identify files generated by this command. Should be unique.")
}
// LoadGoBoilerplate loads the boilerplate file passed to --go-header-file.
@ -94,7 +102,7 @@ func (g *GeneratorArgs) LoadGoBoilerplate() ([]byte, error) {
func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
b := parser.New()
// Ignore all auto-generated files.
b.AddBuildTags("ignore_autogenerated")
b.AddBuildTags(g.GeneratedBuildTag)
for _, d := range g.InputDirs {
d = strings.TrimLeft(d, "+-*")

View File

@ -210,10 +210,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
inputs := sets.NewString(arguments.InputDirs...)
packages := generator.Packages{}
header := append([]byte(
`// +build !ignore_autogenerated
`), boilerplate...)
header := append([]byte(fmt.Sprintf("// +build !%s\n\n", arguments.GeneratedBuildTag)), boilerplate...)
header = append(header, []byte(
`
// This file was autogenerated by conversion-gen. Do not edit it manually!

View File

@ -99,10 +99,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
}
packages := generator.Packages{}
header := append([]byte(
`// +build !ignore_autogenerated
`), boilerplate...)
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!
@ -121,10 +118,12 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
// avoid having to make a reflection call.
canInlineTypeFn := func(c *generator.Context, t *types.Type) bool {
// types must be public structs or have a custom DeepCopy_<method> already defined
if !copyableWithinPackage(t, explicitInputs.Has(t.Name.Package)) && !publicCopyFunctionDefined(c, t) {
if publicCopyFunctionDefined(c, t) {
return true
}
if !copyableWithinPackage(t, explicitInputs.Has(t.Name.Package)) {
return false
}
// only packages within the restricted range can be inlined
for _, s := range restrictRange {
if strings.HasPrefix(t.Name.Package, s) {

View File

@ -37,6 +37,7 @@ bind-pods-burst
bind-pods-qps
build-only
build-services
build-tag
cadvisor-port
cert-dir
certificate-authority