mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 02:34:03 +00:00
Merge pull request #128259 from dinhxuanvu/conversion-build-tag
Restore build-tag for conversion and defaulter gen
This commit is contained in:
commit
d9b95ea94f
@ -20,6 +20,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/gengo/v2"
|
||||
)
|
||||
|
||||
// DefaultBasePeerDirs are the peer-dirs nearly everybody will use, i.e. those coming from
|
||||
@ -57,13 +59,20 @@ type Args struct {
|
||||
// GoHeaderFile is the path to a boilerplate header file for generated
|
||||
// code.
|
||||
GoHeaderFile string
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// New returns default arguments for the generator.
|
||||
func New() *Args {
|
||||
return &Args{
|
||||
BasePeerDirs: DefaultBasePeerDirs,
|
||||
SkipUnsafe: false,
|
||||
BasePeerDirs: DefaultBasePeerDirs,
|
||||
SkipUnsafe: false,
|
||||
GeneratedBuildTag: gengo.StdBuildTag,
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,6 +90,7 @@ func (args *Args) AddFlags(fs *pflag.FlagSet) {
|
||||
"If true, will not generate code using unsafe pointer conversions; resulting code may be slower.")
|
||||
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
fs.StringVar(&args.GeneratedBuildTag, "build-tag", args.GeneratedBuildTag, "A Go build tag to use to identify files generated by this command. Should be unique.")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -196,7 +196,7 @@ func getManualConversionFunctions(context *generator.Context, pkg *types.Package
|
||||
}
|
||||
|
||||
func GetTargets(context *generator.Context, args *args.Args) []generator.Target {
|
||||
boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, gengo.StdBuildTag, gengo.StdGeneratedBy)
|
||||
boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, args.GeneratedBuildTag, gengo.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
myTargets,
|
||||
gengo.StdBuildTag,
|
||||
args.GeneratedBuildTag,
|
||||
pflag.Args(),
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
|
@ -20,17 +20,27 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"k8s.io/gengo/v2"
|
||||
)
|
||||
|
||||
type Args struct {
|
||||
OutputFile string
|
||||
ExtraPeerDirs []string // Always consider these as last-ditch possibilities for conversions.
|
||||
GoHeaderFile string
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// New returns default arguments for the generator.
|
||||
func New() *Args {
|
||||
return &Args{}
|
||||
return &Args{
|
||||
GeneratedBuildTag: gengo.StdBuildTag,
|
||||
}
|
||||
}
|
||||
|
||||
// AddFlags add the generator flags to the flag set.
|
||||
@ -41,6 +51,7 @@ func (args *Args) AddFlags(fs *pflag.FlagSet) {
|
||||
"Comma-separated list of import paths which are considered, after tag-specified peers, for conversions.")
|
||||
fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
|
||||
"the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
|
||||
fs.StringVar(&args.GeneratedBuildTag, "build-tag", args.GeneratedBuildTag, "A Go build tag to use to identify files generated by this command. Should be unique.")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
|
@ -222,7 +222,7 @@ func getManualDefaultingFunctions(context *generator.Context, pkg *types.Package
|
||||
}
|
||||
|
||||
func GetTargets(context *generator.Context, args *args.Args) []generator.Target {
|
||||
boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, gengo.StdBuildTag, gengo.StdGeneratedBy)
|
||||
boilerplate, err := gengo.GoBoilerplate(args.GoHeaderFile, args.GeneratedBuildTag, gengo.StdGeneratedBy)
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func main() {
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
myTargets,
|
||||
gengo.StdBuildTag,
|
||||
args.GeneratedBuildTag,
|
||||
pflag.Args(),
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user