From e1b46132919090871a5d8578648d1fb54cb1fc8f Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Fri, 6 Oct 2017 10:11:00 +0200 Subject: [PATCH] sync(k8s.io/gengo): 70ad626ed2d7a483d89d2c4c56364d60b48ee8fc --- Godeps/Godeps.json | 20 ++++++++-------- vendor/k8s.io/gengo/args/args.go | 27 ++++++++++++++------- vendor/k8s.io/gengo/parser/parse.go | 37 ++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 89d05ac049f..ace22c9733b 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -3042,43 +3042,43 @@ }, { "ImportPath": "k8s.io/gengo/args", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/examples/import-boss/generators", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/generators", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/examples/set-gen/sets", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/generator", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/namer", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/parser", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/gengo/types", - "Rev": "9e661e9308f078838e266cca1c673922088c0ea4" + "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc" }, { "ImportPath": "k8s.io/heapster/metrics/api/v1/types", diff --git a/vendor/k8s.io/gengo/args/args.go b/vendor/k8s.io/gengo/args/args.go index 1a9a47884c5..ad9a83480db 100644 --- a/vendor/k8s.io/gengo/args/args.go +++ b/vendor/k8s.io/gengo/args/args.go @@ -39,13 +39,12 @@ import ( // Default returns a defaulted GeneratorArgs. You may change the defaults // before calling AddFlags. func Default() *GeneratorArgs { - generatorArgs := &GeneratorArgs{ - OutputBase: DefaultSourceTree(), - GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"), - GeneratedBuildTag: "ignore_autogenerated", + return &GeneratorArgs{ + OutputBase: DefaultSourceTree(), + GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"), + GeneratedBuildTag: "ignore_autogenerated", + defaultCommandLineFlags: true, } - generatorArgs.AddFlags(pflag.CommandLine) - return generatorArgs } // GeneratorArgs has arguments that are passed to generators. @@ -76,6 +75,15 @@ type GeneratorArgs struct { // Any custom arguments go here CustomArgs interface{} + + // Whether to use default command line flags + defaultCommandLineFlags bool +} + +// WithoutDefaultFlagParsing disables implicit addition of command line flags and parsing. +func (g *GeneratorArgs) WithoutDefaultFlagParsing() *GeneratorArgs { + g.defaultCommandLineFlags = false + return g } func (g *GeneratorArgs) AddFlags(fs *pflag.FlagSet) { @@ -148,8 +156,11 @@ func DefaultSourceTree() string { // If you don't need any non-default behavior, use as: // args.Default().Execute(...) func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error { - pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) - pflag.Parse() + if g.defaultCommandLineFlags { + g.AddFlags(pflag.CommandLine) + pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) + pflag.Parse() + } b, err := g.NewBuilder() if err != nil { diff --git a/vendor/k8s.io/gengo/parser/parse.go b/vendor/k8s.io/gengo/parser/parse.go index 2288a0e473d..d2bfed30c59 100644 --- a/vendor/k8s.io/gengo/parser/parse.go +++ b/vendor/k8s.io/gengo/parser/parse.go @@ -27,6 +27,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strings" "github.com/golang/glog" @@ -425,13 +426,20 @@ func (b *Builder) typeCheckPackage(pkgPath importPathString) (*tc.Package, error // FindPackages fetches a list of the user-imported packages. // Note that you need to call b.FindTypes() first. func (b *Builder) FindPackages() []string { + // Iterate packages in a predictable order. + pkgPaths := []string{} + for k := range b.typeCheckedPackages { + pkgPaths = append(pkgPaths, string(k)) + } + sort.Strings(pkgPaths) + result := []string{} - for pkgPath := range b.typeCheckedPackages { - if b.userRequested[pkgPath] { + for _, pkgPath := range pkgPaths { + if b.userRequested[importPathString(pkgPath)] { // Since walkType is recursive, all types that are in packages that // were directly mentioned will be included. We don't need to // include all types in all transitive packages, though. - result = append(result, string(pkgPath)) + result = append(result, pkgPath) } } return result @@ -440,16 +448,17 @@ func (b *Builder) FindPackages() []string { // FindTypes finalizes the package imports, and searches through all the // packages for types. func (b *Builder) FindTypes() (types.Universe, error) { - u := types.Universe{} - // Take a snapshot of pkgs to iterate, since this will recursively mutate - // b.parsed. - keys := []importPathString{} + // b.parsed. Iterate in a predictable order. + pkgPaths := []string{} for pkgPath := range b.parsed { - keys = append(keys, pkgPath) + pkgPaths = append(pkgPaths, string(pkgPath)) } - for _, pkgPath := range keys { - if err := b.findTypesIn(pkgPath, &u); err != nil { + sort.Strings(pkgPaths) + + u := types.Universe{} + for _, pkgPath := range pkgPaths { + if err := b.findTypesIn(importPathString(pkgPath), &u); err != nil { return nil, err } } @@ -526,7 +535,13 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error b.addVariable(*u, nil, tv) } } - for p := range b.importGraph[pkgPath] { + + importedPkgs := []string{} + for k := range b.importGraph[pkgPath] { + importedPkgs = append(importedPkgs, string(k)) + } + sort.Strings(importedPkgs) + for _, p := range importedPkgs { u.AddImports(string(pkgPath), p) } return nil