mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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).
This commit is contained in:
parent
4e046a8dc5
commit
903a2db90a
@ -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, "+-*")
|
||||
|
@ -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!
|
||||
|
@ -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!
|
||||
|
@ -37,6 +37,7 @@ bind-pods-burst
|
||||
bind-pods-qps
|
||||
build-only
|
||||
build-services
|
||||
build-tag
|
||||
cadvisor-port
|
||||
cert-dir
|
||||
certificate-authority
|
||||
|
Loading…
Reference in New Issue
Block a user