-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support only updating existing BUILD files #1921
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,27 @@ import ( | |
gzflag "github.com/bazelbuild/bazel-gazelle/flag" | ||
) | ||
|
||
// GenerationModeType represents one of the generation modes. | ||
type GenerationModeType string | ||
|
||
// Generation modes | ||
const ( | ||
// Update: update and maintain existing BUILD files | ||
GenerationModeUpdate GenerationModeType = "update" | ||
|
||
// Create: create new and update existing BUILD files | ||
GenerationModeCreate GenerationModeType = "create" | ||
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about |
||
) | ||
|
||
// TODO(#472): store location information to validate each exclude. They | ||
// may be set in one directory and used in another. Excludes work on | ||
// declared generated files, so we can't just stat. | ||
|
||
type walkConfig struct { | ||
excludes []string | ||
ignore bool | ||
follow []string | ||
updateOnly bool | ||
excludes []string | ||
ignore bool | ||
follow []string | ||
} | ||
|
||
const walkName = "_walk" | ||
|
@@ -70,7 +83,7 @@ func (*Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) | |
func (*Configurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error { return nil } | ||
|
||
func (*Configurer) KnownDirectives() []string { | ||
return []string{"exclude", "follow", "ignore"} | ||
return []string{"generation_mode", "exclude", "follow", "ignore"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the directive named used by the Aspect plugins today. I think we need something better here that doesn't include the word "mode" which already has a meaning within gazelle. Ideas? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build_file_action? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to try to this patch at Airtable. I am thinking instead of manually specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think different repos will have different preferences and we can't really make any assumptions based on which files exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming you are in David's situation, could you still leverage I'm asking because adding a new directive comes with a complexity cost that may not be justified if it doesn't address many use cases. Do you see a way to simplify what a language would need to do to get this behavior without adding a new directive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed my hack described in the issue to a patch that's essentially the same as this PR. The hack required manually walking the fs (in addition to gazelle walking it) which is bad in many ways, performance being a big one. I think no matter what a new API is needed so gazelle can generate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add docs for the new directive. I don't have an idea, but would prefer a more descriptive term if we can find one. We already have a |
||
} | ||
|
||
func (cr *Configurer) Configure(c *config.Config, rel string, f *rule.File) { | ||
|
@@ -82,6 +95,8 @@ func (cr *Configurer) Configure(c *config.Config, rel string, f *rule.File) { | |
if f != nil { | ||
for _, d := range f.Directives { | ||
switch d.Key { | ||
case "generation_mode": | ||
wcCopy.updateOnly = GenerationModeType(strings.TrimSpace(d.Value)) == GenerationModeUpdate | ||
case "exclude": | ||
if err := checkPathMatchPattern(path.Join(rel, d.Value)); err != nil { | ||
log.Printf("the exclusion pattern is not valid %q: %s", path.Join(rel, d.Value), err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this private to the package?