Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make generated build tag parameterizable for go2idl #27921

Merged
merged 2 commits into from
Jul 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions cmd/libs/go2idl/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{}
}
Expand All @@ -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.
Expand All @@ -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, "+-*")
Expand Down
5 changes: 1 addition & 4 deletions cmd/libs/go2idl/conversion-gen/generators/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
11 changes: 5 additions & 6 deletions cmd/libs/go2idl/deepcopy-gen/generators/deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions hack/verify-flags/known-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bind-pods-burst
bind-pods-qps
build-only
build-services
build-tag
cadvisor-port
cert-dir
certificate-authority
Expand Down