Skip to content
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

Add clean to buf.gen.yaml #3130

Merged
merged 5 commits into from
Aug 1, 2024
Merged

Add clean to buf.gen.yaml #3130

merged 5 commits into from
Aug 1, 2024

Conversation

doriable
Copy link
Member

@doriable doriable commented Jul 4, 2024

As a quick follow-up to #3124 and in response to #3124 (comment),
this adds a clean config key to v2 buf.gen.yaml, for example:

version: v2
clean: true
plugins:
  - local: custom-gen-go
    out: gen/go
    opt: paths=source_relative
    strategy: directory
  - protoc_builtin: java
    out: gen/java

When running buf generate with the above configs, the outs set to each plugin
(e.g. gen/go and gen/java) will be removed before code generation is run.

If buf generate --clean flag is set, then that will always take precedence, even if
clean: false in the configuration. And likewise, if buf generate --clean=false,
and clean: true in the configuration, then we would not delete the out directories.

@doriable doriable requested a review from bufdev July 4, 2024 21:01
Copy link
Contributor

github-actions bot commented Jul 4, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 1, 2024, 10:19 PM

@bufdev
Copy link
Member

bufdev commented Jul 5, 2024

I'm not sure why I'd want this - why would I want per-plugin config of cleanup?

@doriable
Copy link
Member Author

doriable commented Jul 5, 2024

I'm not sure why I'd want this - why would I want per-plugin config of cleanup?

This is based on @timostamm's comment, which I agree with

I think it would also be nice to have the flag available in buf.gen.yaml next to out. Then users don't have to specify the flag all the time. And specifying the flag next to the out directory path makes it more obvious what is going to be deleted.

It's convenient not having to specify the flag all the time/have it explicitly set in configurations so users can easily reference it. And it does make the association with out very clear.

@bufdev
Copy link
Member

bufdev commented Jul 5, 2024

Why would I want to set it on a per-plugin basis? What's an example of where I'd want to clean for one plugin, but not for another?

Perhaps I could want to do this globally, would be interested what that'd look like from a config perspective.

oliversun9 and others added 2 commits July 18, 2024 13:19
This PR targets branch `add-buf-gen-yaml-clean` and moves `clean` to
`buf.gen.yaml`'s top level, from the plugin level.

---------

Co-authored-by: Doria Keung <doriable@users.noreply.github.com>
@doriable doriable changed the title Add clean to plugin configs in buf.gen.yaml Add clean_plugin_outs to buf.gen.yaml Jul 18, 2024
@bufdev bufdev changed the title Add clean_plugin_outs to buf.gen.yaml Add clean to buf.gen.yaml Aug 1, 2024
@bufdev
Copy link
Member

bufdev commented Aug 1, 2024

Updated to clean instead of clean_plugin_outs - I think we should just match the flag.

@bufdev
Copy link
Member

bufdev commented Aug 1, 2024

buf.build/docs needs to be updated

@doriable doriable merged commit 72d6cc3 into main Aug 1, 2024
13 checks passed
@doriable doriable deleted the add-buf-gen-yaml-clean branch August 1, 2024 22:53
emcfarlane pushed a commit that referenced this pull request Aug 2, 2024
As a quick follow-up to #3124 and in response to
#3124 (comment),
this adds a `clean` config key to `v2` `buf.gen.yaml`, for example:

```yaml
version: v2
clean: true
plugins:
  - local: custom-gen-go
    out: gen/go
    opt: paths=source_relative
    strategy: directory
  - protoc_builtin: java
    out: gen/java
```

When running `buf generate` with the above configs, the outs set to each
plugin
(e.g. `gen/go` and `gen/java`) will be removed before code generation is
run.

If `buf generate --clean` flag is set, then that will always take
precedence, even if
`clean: false` in the configuration. And likewise, if `buf generate
--clean=false`,
and `clean: true` in the configuration, then we would not delete the out
directories.

---------

Co-authored-by: Oliver Sun <73540835+oliversun9@users.noreply.github.com>
Co-authored-by: Oliver Sun <osun@buf.build>
Co-authored-by: bufdev <4228796+bufdev@users.noreply.github.com>
Co-authored-by: bufdev <bufdev-github@buf.build>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants