sync(k8s.io/gengo): 70ad626ed2d7a483d89d2c4c56364d60b48ee8fc

This commit is contained in:
Dr. Stefan Schimanski 2017-10-06 10:11:00 +02:00
parent 4f00d3a67d
commit e1b4613291
3 changed files with 55 additions and 29 deletions

20
Godeps/Godeps.json generated
View File

@ -3042,43 +3042,43 @@
}, },
{ {
"ImportPath": "k8s.io/gengo/args", "ImportPath": "k8s.io/gengo/args",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators", "ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators", "ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/import-boss/generators", "ImportPath": "k8s.io/gengo/examples/import-boss/generators",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/generators", "ImportPath": "k8s.io/gengo/examples/set-gen/generators",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/examples/set-gen/sets", "ImportPath": "k8s.io/gengo/examples/set-gen/sets",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/generator", "ImportPath": "k8s.io/gengo/generator",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/namer", "ImportPath": "k8s.io/gengo/namer",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/parser", "ImportPath": "k8s.io/gengo/parser",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/gengo/types", "ImportPath": "k8s.io/gengo/types",
"Rev": "9e661e9308f078838e266cca1c673922088c0ea4" "Rev": "70ad626ed2d7a483d89d2c4c56364d60b48ee8fc"
}, },
{ {
"ImportPath": "k8s.io/heapster/metrics/api/v1/types", "ImportPath": "k8s.io/heapster/metrics/api/v1/types",

27
vendor/k8s.io/gengo/args/args.go generated vendored
View File

@ -39,13 +39,12 @@ import (
// Default returns a defaulted GeneratorArgs. You may change the defaults // Default returns a defaulted GeneratorArgs. You may change the defaults
// before calling AddFlags. // before calling AddFlags.
func Default() *GeneratorArgs { func Default() *GeneratorArgs {
generatorArgs := &GeneratorArgs{ return &GeneratorArgs{
OutputBase: DefaultSourceTree(), OutputBase: DefaultSourceTree(),
GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"), GoHeaderFilePath: filepath.Join(DefaultSourceTree(), "k8s.io/gengo/boilerplate/boilerplate.go.txt"),
GeneratedBuildTag: "ignore_autogenerated", GeneratedBuildTag: "ignore_autogenerated",
defaultCommandLineFlags: true,
} }
generatorArgs.AddFlags(pflag.CommandLine)
return generatorArgs
} }
// GeneratorArgs has arguments that are passed to generators. // GeneratorArgs has arguments that are passed to generators.
@ -76,6 +75,15 @@ type GeneratorArgs struct {
// Any custom arguments go here // Any custom arguments go here
CustomArgs interface{} 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) { 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: // If you don't need any non-default behavior, use as:
// args.Default().Execute(...) // args.Default().Execute(...)
func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error { func (g *GeneratorArgs) Execute(nameSystems namer.NameSystems, defaultSystem string, pkgs func(*generator.Context, *GeneratorArgs) generator.Packages) error {
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) if g.defaultCommandLineFlags {
pflag.Parse() g.AddFlags(pflag.CommandLine)
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
pflag.Parse()
}
b, err := g.NewBuilder() b, err := g.NewBuilder()
if err != nil { if err != nil {

37
vendor/k8s.io/gengo/parser/parse.go generated vendored
View File

@ -27,6 +27,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"github.com/golang/glog" "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. // FindPackages fetches a list of the user-imported packages.
// Note that you need to call b.FindTypes() first. // Note that you need to call b.FindTypes() first.
func (b *Builder) FindPackages() []string { 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{} result := []string{}
for pkgPath := range b.typeCheckedPackages { for _, pkgPath := range pkgPaths {
if b.userRequested[pkgPath] { if b.userRequested[importPathString(pkgPath)] {
// Since walkType is recursive, all types that are in packages that // Since walkType is recursive, all types that are in packages that
// were directly mentioned will be included. We don't need to // were directly mentioned will be included. We don't need to
// include all types in all transitive packages, though. // include all types in all transitive packages, though.
result = append(result, string(pkgPath)) result = append(result, pkgPath)
} }
} }
return result return result
@ -440,16 +448,17 @@ func (b *Builder) FindPackages() []string {
// FindTypes finalizes the package imports, and searches through all the // FindTypes finalizes the package imports, and searches through all the
// packages for types. // packages for types.
func (b *Builder) FindTypes() (types.Universe, error) { func (b *Builder) FindTypes() (types.Universe, error) {
u := types.Universe{}
// Take a snapshot of pkgs to iterate, since this will recursively mutate // Take a snapshot of pkgs to iterate, since this will recursively mutate
// b.parsed. // b.parsed. Iterate in a predictable order.
keys := []importPathString{} pkgPaths := []string{}
for pkgPath := range b.parsed { for pkgPath := range b.parsed {
keys = append(keys, pkgPath) pkgPaths = append(pkgPaths, string(pkgPath))
} }
for _, pkgPath := range keys { sort.Strings(pkgPaths)
if err := b.findTypesIn(pkgPath, &u); err != nil {
u := types.Universe{}
for _, pkgPath := range pkgPaths {
if err := b.findTypesIn(importPathString(pkgPath), &u); err != nil {
return nil, err return nil, err
} }
} }
@ -526,7 +535,13 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error
b.addVariable(*u, nil, tv) 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) u.AddImports(string(pkgPath), p)
} }
return nil return nil