Merge pull request #46742 from caesarxuchao/update-gengo

Automatic merge from submit-queue (batch tested with PRs 40760, 46706, 46783, 46742, 46751)

Update gengo to the latest
This commit is contained in:
Kubernetes Submit Queue 2017-06-03 18:30:44 -07:00 committed by GitHub
commit 17f0918bb9
15 changed files with 256 additions and 24 deletions

20
Godeps/Godeps.json generated
View File

@ -2864,43 +2864,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",

View File

@ -16,6 +16,7 @@ go_library(
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [

View File

@ -0,0 +1,32 @@
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by defaulter-gen. Do not edit it manually!
package v1alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

View File

@ -15,6 +15,7 @@ go_library(
"types.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [

View File

@ -0,0 +1,32 @@
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by defaulter-gen. Do not edit it manually!
package v1alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

View File

@ -16,6 +16,7 @@ go_library(
"types.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [

View File

@ -0,0 +1,32 @@
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by defaulter-gen. Do not edit it manually!
package v1alpha1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

View File

@ -19,3 +19,14 @@ limitations under the License.
// This file was autogenerated by defaulter-gen. Do not edit it manually!
package v1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
return nil
}

View File

@ -17,6 +17,7 @@ go_library(
"types.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
tags = ["automanaged"],
deps = [

View File

@ -0,0 +1,48 @@
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by defaulter-gen. Do not edit it manually!
package v1beta1
import (
runtime "k8s.io/apimachinery/pkg/runtime"
)
// RegisterDefaults adds defaulters functions to the given scheme.
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
scheme.AddTypeDefaultingFunc(&CustomResourceDefinition{}, func(obj interface{}) { SetObjectDefaults_CustomResourceDefinition(obj.(*CustomResourceDefinition)) })
scheme.AddTypeDefaultingFunc(&CustomResourceDefinitionList{}, func(obj interface{}) {
SetObjectDefaults_CustomResourceDefinitionList(obj.(*CustomResourceDefinitionList))
})
return nil
}
func SetObjectDefaults_CustomResourceDefinition(in *CustomResourceDefinition) {
SetDefaults_CustomResourceDefinition(in)
SetDefaults_CustomResourceDefinitionSpec(&in.Spec)
}
func SetObjectDefaults_CustomResourceDefinitionList(in *CustomResourceDefinitionList) {
for i := range in.Items {
a := &in.Items[i]
SetObjectDefaults_CustomResourceDefinition(a)
}
}

View File

@ -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,

View File

@ -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

View File

@ -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)
}

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

@ -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())...)
}

5
vendor/k8s.io/gengo/types/types.go generated vendored
View File

@ -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