Skip to content

Commit 71cec62

Browse files
committed
Rename --build-tags to --load-build-tags and add 'ignore_autogenerated' as a default
1 parent 0236649 commit 71cec62

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

cmd/controller-gen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func main() {
195195
cmd.Flags().CountVarP(&whichLevel, "which-markers", "w", "print out all markers available with the requested generators\n(up to -www for the most detailed output, or -wwww for json output)")
196196
cmd.Flags().CountVarP(&helpLevel, "detailed-help", "h", "print out more detailed help\n(up to -hhh for the most detailed output, or -hhhh for json output)")
197197
cmd.Flags().BoolVar(&showVersion, "version", false, "show version")
198-
cmd.Flags().StringSliceVar(&buildTags, "build-tags", nil, "build tags to use when loading Go packages")
198+
cmd.Flags().StringSliceVar(&buildTags, "load-build-tags", []string{"ignore_autogenerated"}, "build tags to use when loading Go packages")
199199
cmd.Flags().Bool("help", false, "print out usage and a summary of options")
200200
oldUsage := cmd.UsageFunc()
201201
cmd.SetUsageFunc(func(c *cobra.Command) error {

pkg/loader/loader.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,14 @@ func LoadRootsWithConfig(cfg *packages.Config, roots ...string) ([]*Package, err
374374
if l.cfg.Fset == nil {
375375
l.cfg.Fset = token.NewFileSet()
376376
}
377-
// put our build flags first so that callers can override them
378-
l.cfg.BuildFlags = append([]string{"-tags", "ignore_autogenerated"}, l.cfg.BuildFlags...)
377+
378+
// put our build flags first so that callers can override them.
379+
//
380+
// NOTE: if callers provide their own `-tags` flag, then our hardcoded `ignore_autogenerated` tag
381+
// will be ignored. Callers that provide custom tags MUST include `ignore_autogenerated` in their
382+
// custom tag set if they want that tag to remain active. Users can explicitly pass custom build
383+
// flags with `-tags=""` to disable use of the default `ignore_autogenerated` tag.
384+
l.cfg.BuildFlags = append([]string{"-tags=ignore_autogenerated"}, l.cfg.BuildFlags...)
379385

380386
// Visit the import graphs of the loaded, root packages. If an imported
381387
// package refers to another loaded, root package, then replace the

0 commit comments

Comments
 (0)