Skip to content

Commit

Permalink
Merge pull request #55233 from sttts/sttts-codegen-comment-blocks
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 55233, 55927, 55903, 54867, 55940). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

code-generators: remove distinction of 1st and 2nd comment block for tags

Follow-up for kubernetes/kubernetes#53579.

Fixes #53893.

```release-note
Allow code-generator tags in the 2nd closest comment block and directly above a statement.
```

Kubernetes-commit: 3b4be46683faa952c92a6dcdd9e67714583cdbef
  • Loading branch information
k8s-publish-robot committed Nov 29, 2017
2 parents 3f195b4 + 9173542 commit f880bc3
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/client-gen/generators/client_generator.go
Expand Up @@ -163,7 +163,7 @@ func packageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
},
}
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
} else {
// User has not specified any override for this group version.
// filter out types which dont have genclient.
if tags := util.MustParseClientGenTags(t.SecondClosestCommentLines); !tags.GenerateClient {
if tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)); !tags.GenerateClient {
continue
}
}
Expand Down Expand Up @@ -395,7 +395,7 @@ type tagOverrideNamer struct {
}

func (n *tagOverrideNamer) Name(t *types.Type) string {
if nameOverride := extractTag(n.tagName, t.SecondClosestCommentLines); nameOverride != "" {
if nameOverride := extractTag(n.tagName, append(t.SecondClosestCommentLines, t.CommentLines...)); nameOverride != "" {
return nameOverride
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/client-gen/generators/fake/fake_client_generator.go
Expand Up @@ -79,7 +79,7 @@ func PackageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, cli
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
return util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/client-gen/generators/fake/generator_fake_for_group.go
Expand Up @@ -73,7 +73,7 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io

sw.Do(groupClientTemplate, m)
for _, t := range g.types {
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/client-gen/generators/fake/generator_fake_for_type.go
Expand Up @@ -69,7 +69,7 @@ func genStatus(t *types.Type) bool {
}
}

tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return hasStatus && !tags.NoStatus
}

Expand All @@ -87,7 +87,7 @@ func hasObjectMeta(t *types.Type) bool {
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/client-gen/generators/generator_for_group.go
Expand Up @@ -105,7 +105,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
sw.Do(groupInterfaceTemplate, m)
sw.Do(groupClientTemplate, m)
for _, t := range g.types {
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/client-gen/generators/generator_for_type.go
Expand Up @@ -67,14 +67,14 @@ func genStatus(t *types.Type) bool {
break
}
}
return hasStatus && !util.MustParseClientGenTags(t.SecondClosestCommentLines).NoStatus
return hasStatus && !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).NoStatus
}

// GenerateType makes the body of a file implementing the individual typed client for type t.
func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package)
tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/informer-gen/generators/informer.go
Expand Up @@ -72,7 +72,7 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
informerFor := "InformerFor"

tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/informer-gen/generators/packages.go
Expand Up @@ -71,7 +71,7 @@ func generatedBy() string {
func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
generatingForPackage := false
for _, t := range p.Types {
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
continue
}
generatingForPackage = true
Expand Down Expand Up @@ -176,7 +176,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat

var typesToGenerate []*types.Type
for _, t := range p.Types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if !tags.GenerateClient || tags.NoVerbs || !tags.HasVerb("list") || !tags.HasVerb("watch") {
continue
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func groupPackage(basePackage string, groupVersions clientgentypes.GroupVersions
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
},
}
Expand Down Expand Up @@ -351,7 +351,7 @@ func versionPackage(basePackage string, groupPkgName string, gv clientgentypes.G
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lister-gen/generators/expansion.go
Expand Up @@ -43,7 +43,7 @@ func (g *expansionGenerator) Filter(c *generator.Context, t *types.Type) bool {
func (g *expansionGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
for _, t := range g.types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if _, err := os.Stat(filepath.Join(g.packagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
sw.Do(expansionInterfaceTemplate, t)
if !tags.NonNamespaced {
Expand Down
8 changes: 4 additions & 4 deletions cmd/lister-gen/generators/lister.go
Expand Up @@ -118,7 +118,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat

var typesToGenerate []*types.Type
for _, t := range p.Types {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if !tags.GenerateClient || !tags.HasVerb("list") || !tags.HasVerb("get") {
continue
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func Packages(context *generator.Context, arguments *args.GeneratorArgs) generat
return generators
},
FilterFunc: func(c *generator.Context, t *types.Type) bool {
tags := util.MustParseClientGenTags(t.SecondClosestCommentLines)
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("get")
},
})
Expand All @@ -174,7 +174,7 @@ func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
generatingForPackage := false
for _, t := range p.Types {
// filter out types which dont have genclient.
if !util.MustParseClientGenTags(t.SecondClosestCommentLines).GenerateClient {
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
continue
}
generatingForPackage = true
Expand Down Expand Up @@ -238,7 +238,7 @@ func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io
"objectMeta": g.objectMeta,
}

tags, err := util.ParseClientGenTags(t.SecondClosestCommentLines)
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
if err != nil {
return err
}
Expand Down

0 comments on commit f880bc3

Please sign in to comment.