mirror of https://github.com/k3s-io/k3s
update gengo godep
parent
052cd6d30b
commit
a3f4a8bd52
|
@ -2860,43 +2860,43 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/args",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/deepcopy-gen/generators",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/defaulter-gen/generators",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/import-boss/generators",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/generators",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/examples/set-gen/sets",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/generator",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/namer",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/parser",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/gengo/types",
|
||||
"Rev": "4b7dfb7a2f42f66d9f5dfdf2c1557f409eac0869"
|
||||
"Rev": "c79c13d131b0a8f42d05faa6491c12e94ccc6f30"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/heapster/metrics/api/v1/types",
|
||||
|
|
|
@ -196,7 +196,6 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
expandedPath := strings.TrimPrefix(pkg.SourcePath, arguments.OutputBase)
|
||||
if strings.Contains(expandedPath, "/vendor/") {
|
||||
path = expandedPath
|
||||
glog.V(3).Infof(" %s", path)
|
||||
}
|
||||
}
|
||||
packages = append(packages,
|
||||
|
|
|
@ -38,13 +38,18 @@ type CustomArgs struct {
|
|||
ExtraPeerDirs []string // Always consider these as last-ditch possibilities for conversions.
|
||||
}
|
||||
|
||||
// This is the comment tag that carries parameters for defaulter generation.
|
||||
// These are the comment tags that carry parameters for defaulter generation.
|
||||
const tagName = "k8s:defaulter-gen"
|
||||
const intputTagName = "k8s:defaulter-gen-input"
|
||||
|
||||
func extractTag(comments []string) []string {
|
||||
return types.ExtractCommentTags("+", comments)[tagName]
|
||||
}
|
||||
|
||||
func extractInputTag(comments []string) []string {
|
||||
return types.ExtractCommentTags("+", comments)[intputTagName]
|
||||
}
|
||||
|
||||
func checkTag(comments []string, require ...string) bool {
|
||||
values := types.ExtractCommentTags("+", comments)[tagName]
|
||||
if len(require) == 0 {
|
||||
|
@ -220,6 +225,11 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
// If the input had no Go files, for example.
|
||||
continue
|
||||
}
|
||||
// typesPkg is where the types that needs defaulter are defined.
|
||||
// Sometimes it is different from pkg. For example, kubernetes core/v1
|
||||
// types are defined in vendor/k8s.io/api/core/v1, while pkg is at
|
||||
// pkg/api/v1.
|
||||
typesPkg := pkg
|
||||
|
||||
// Add defaulting functions.
|
||||
getManualDefaultingFunctions(context, pkg, existingDefaulters)
|
||||
|
@ -271,8 +281,24 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
return false
|
||||
}
|
||||
|
||||
// if the types are not in the same package where the defaulter functions to be generated
|
||||
inputTags := extractInputTag(pkg.Comments)
|
||||
if len(inputTags) > 1 {
|
||||
panic(fmt.Sprintf("there could only be one input tag, got %#v", inputTags))
|
||||
}
|
||||
if len(inputTags) == 1 {
|
||||
var err error
|
||||
typesPkg, err = context.AddDirectory(filepath.Join(pkg.Path, inputTags[0]))
|
||||
if err != nil {
|
||||
glog.Fatalf("cannot import package %s", inputTags[0])
|
||||
}
|
||||
// update context.Order to the latest context.Universe
|
||||
orderer := namer.Orderer{Namer: namer.NewPublicNamer(1)}
|
||||
context.Order = orderer.OrderUniverse(context.Universe)
|
||||
}
|
||||
|
||||
newDefaulters := defaulterFuncMap{}
|
||||
for _, t := range pkg.Types {
|
||||
for _, t := range typesPkg.Types {
|
||||
if !shouldCreateObjectDefaulterFn(t) {
|
||||
continue
|
||||
}
|
||||
|
@ -328,18 +354,33 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
|
|||
glog.V(5).Infof("no defaulters in package %s", pkg.Name)
|
||||
}
|
||||
|
||||
path := pkg.Path
|
||||
// if the source path is within a /vendor/ directory (for example,
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1), allow
|
||||
// generation to output to the proper relative path (under vendor).
|
||||
// Otherwise, the generator will create the file in the wrong location
|
||||
// in the output directory.
|
||||
// TODO: build a more fundamental concept in gengo for dealing with modifications
|
||||
// to vendored packages.
|
||||
if strings.HasPrefix(pkg.SourcePath, arguments.OutputBase) {
|
||||
expandedPath := strings.TrimPrefix(pkg.SourcePath, arguments.OutputBase)
|
||||
if strings.Contains(expandedPath, "/vendor/") {
|
||||
path = expandedPath
|
||||
}
|
||||
}
|
||||
|
||||
packages = append(packages,
|
||||
&generator.DefaultPackage{
|
||||
PackageName: filepath.Base(pkg.Path),
|
||||
PackagePath: pkg.Path,
|
||||
PackagePath: path,
|
||||
HeaderText: header,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
return []generator.Generator{
|
||||
NewGenDefaulter(arguments.OutputFileBaseName, pkg.Path, existingDefaulters, newDefaulters, peerPkgs),
|
||||
NewGenDefaulter(arguments.OutputFileBaseName, typesPkg.Path, pkg.Path, existingDefaulters, newDefaulters, peerPkgs),
|
||||
}
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return t.Name.Package == pkg.Path
|
||||
return t.Name.Package == typesPkg.Path
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -442,7 +483,8 @@ const (
|
|||
// genDefaulter produces a file with a autogenerated conversions.
|
||||
type genDefaulter struct {
|
||||
generator.DefaultGen
|
||||
targetPackage string
|
||||
typesPackage string
|
||||
outputPackage string
|
||||
peerPackages []string
|
||||
newDefaulters defaulterFuncMap
|
||||
existingDefaulters defaulterFuncMap
|
||||
|
@ -450,12 +492,13 @@ type genDefaulter struct {
|
|||
typesForInit []*types.Type
|
||||
}
|
||||
|
||||
func NewGenDefaulter(sanitizedName, targetPackage string, existingDefaulters, newDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator {
|
||||
func NewGenDefaulter(sanitizedName, typesPackage, outputPackage string, existingDefaulters, newDefaulters defaulterFuncMap, peerPkgs []string) generator.Generator {
|
||||
return &genDefaulter{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: sanitizedName,
|
||||
},
|
||||
targetPackage: targetPackage,
|
||||
typesPackage: typesPackage,
|
||||
outputPackage: outputPackage,
|
||||
peerPackages: peerPkgs,
|
||||
newDefaulters: newDefaulters,
|
||||
existingDefaulters: existingDefaulters,
|
||||
|
@ -467,15 +510,15 @@ func NewGenDefaulter(sanitizedName, targetPackage string, existingDefaulters, ne
|
|||
func (g *genDefaulter) Namers(c *generator.Context) namer.NameSystems {
|
||||
// Have the raw namer for this file track what it imports.
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.targetPackage, g.imports),
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genDefaulter) isOtherPackage(pkg string) bool {
|
||||
if pkg == g.targetPackage {
|
||||
if pkg == g.outputPackage {
|
||||
return false
|
||||
}
|
||||
if strings.HasSuffix(pkg, `"`+g.targetPackage+`"`) {
|
||||
if strings.HasSuffix(pkg, `"`+g.outputPackage+`"`) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -206,6 +206,14 @@ func NewContext(b *parser.Builder, nameSystems namer.NameSystems, canonicalOrder
|
|||
// AddDir adds a Go package to the context. The specified path must be a single
|
||||
// go package import path. GOPATH, GOROOT, and the location of your go binary
|
||||
// (`which go`) will all be searched, in the normal Go fashion.
|
||||
// Deprecated. Please use AddDirectory.
|
||||
func (ctxt *Context) AddDir(path string) error {
|
||||
return ctxt.builder.AddDirTo(path, &ctxt.Universe)
|
||||
}
|
||||
|
||||
// AddDirectory adds a Go package to the context. The specified path must be a
|
||||
// single go package import path. GOPATH, GOROOT, and the location of your go
|
||||
// binary (`which go`) will all be searched, in the normal Go fashion.
|
||||
func (ctxt *Context) AddDirectory(path string) (*types.Package, error) {
|
||||
return ctxt.builder.AddDirectoryTo(path, &ctxt.Universe)
|
||||
}
|
||||
|
|
|
@ -251,6 +251,7 @@ func (b *Builder) AddDirRecursive(dir string) error {
|
|||
// generator (rather than just at init time. 'dir' must be a single go package.
|
||||
// GOPATH, GOROOT, and the location of your go binary (`which go`) will all be
|
||||
// searched if dir doesn't literally resolve.
|
||||
// Deprecated. Please use AddDirectoryTo.
|
||||
func (b *Builder) AddDirTo(dir string, u *types.Universe) error {
|
||||
// We want all types from this package, as if they were directly added
|
||||
// by the user. They WERE added by the user, in effect.
|
||||
|
@ -260,6 +261,24 @@ func (b *Builder) AddDirTo(dir string, u *types.Universe) error {
|
|||
return b.findTypesIn(canonicalizeImportPath(b.buildPackages[dir].ImportPath), u)
|
||||
}
|
||||
|
||||
// AddDirectoryTo adds an entire directory to a given Universe. Unlike AddDir,
|
||||
// this processes the package immediately, which makes it safe to use from
|
||||
// within a generator (rather than just at init time. 'dir' must be a single go
|
||||
// package. GOPATH, GOROOT, and the location of your go binary (`which go`)
|
||||
// will all be searched if dir doesn't literally resolve.
|
||||
func (b *Builder) AddDirectoryTo(dir string, u *types.Universe) (*types.Package, error) {
|
||||
// We want all types from this package, as if they were directly added
|
||||
// by the user. They WERE added by the user, in effect.
|
||||
if _, err := b.importPackage(dir, true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path := canonicalizeImportPath(b.buildPackages[dir].ImportPath)
|
||||
if err := b.findTypesIn(path, u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return u.Package(string(path)), nil
|
||||
}
|
||||
|
||||
// The implementation of AddDir. A flag indicates whether this directory was
|
||||
// user-requested or just from following the import graph.
|
||||
func (b *Builder) addDir(dir string, userRequested bool) error {
|
||||
|
@ -462,6 +481,9 @@ func (b *Builder) findTypesIn(pkgPath importPathString, u *types.Universe) error
|
|||
for _, f := range b.parsed[pkgPath] {
|
||||
if strings.HasSuffix(f.name, "/doc.go") {
|
||||
tp := u.Package(string(pkgPath))
|
||||
// findTypesIn might be called multiple times. Clean up tp.Comments
|
||||
// to avoid repeatedly fill same comments to it.
|
||||
tp.Comments = []string{}
|
||||
for i := range f.file.Comments {
|
||||
tp.Comments = append(tp.Comments, splitLines(f.file.Comments[i].Text())...)
|
||||
}
|
||||
|
|
|
@ -101,10 +101,11 @@ type Package struct {
|
|||
// 'package x' line.
|
||||
Name string
|
||||
|
||||
// DocComments from doc.go, if any.
|
||||
// The comment right above the package declaration in doc.go, if any.
|
||||
DocComments []string
|
||||
|
||||
// Comments from doc.go, if any.
|
||||
// All comments from doc.go, if any.
|
||||
// TODO: remove Comments and use DocComments everywhere.
|
||||
Comments []string
|
||||
|
||||
// Types within this package, indexed by their name (*not* including
|
||||
|
|
Loading…
Reference in New Issue