-
Notifications
You must be signed in to change notification settings - Fork 346
Add type exclusion filters for buf generate #3624
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
7aab46c
Add exclude_options configuration for generation
emcfarlane e2608aa
Fix lint issues and file iter
emcfarlane d05d210
Use protoreflect for remapping
emcfarlane 5940c75
Remap dependencies
emcfarlane f763966
Refactor for image filtering
emcfarlane 4935430
Refactor for include and exclude of types
emcfarlane 400f958
Fix handling of extensions
emcfarlane 2a66cf2
Fix import types
emcfarlane 2c4378d
Fix extension inclusions
emcfarlane a0b373e
Checkpoint
emcfarlane 11a88a9
Refactor for transitive closure
emcfarlane 99902e6
Cleanup testcase
emcfarlane b5b7daa
Cleanup
emcfarlane e2c5f8b
Fix import dropping for options
emcfarlane 8e286f4
Fix build
emcfarlane cb5a8ee
Mutate in place
emcfarlane 00ebe13
Add mutate in place option
emcfarlane 20b720b
Update docs
emcfarlane 3cec9b8
Fix generation per image
emcfarlane 5997223
Cleanup
emcfarlane 764626a
Cleanup
emcfarlane dc449ef
Remove gosec workarounds
emcfarlane 90cc4a0
Cleanup
emcfarlane cffd97c
Remove pointers from trailing slice
emcfarlane b460387
Drop extension TODO
emcfarlane e531a7a
Add types and options for inputs and plugins
emcfarlane 2a2017a
Sort key parts
emcfarlane 49cf91c
Only exclusion of types
emcfarlane 07ea2e0
Docs
emcfarlane c43b74e
Remove inclusion of extension restriction
emcfarlane 347120a
Merge branch 'main' into ed/excludeOptions
emcfarlane d66e197
Add exclude-types flag
emcfarlane 883527c
Add CHANGELOG
emcfarlane 5decf0b
Add testcases
emcfarlane e07f2b7
Fix lint
emcfarlane a3f2055
Cleanup
emcfarlane b8ed6d7
Cleanup
emcfarlane cbfb29f
Cleanup
emcfarlane 13c3882
Use slices.Backward
emcfarlane 3124c00
Improve generator key
emcfarlane eaf49d2
Fix unused deps
emcfarlane 59f5d78
Add unused deps testcase
emcfarlane 07152c5
Fix changelog
emcfarlane bf07344
Merge branch 'main' into ed/excludeOptions
emcfarlane cd43600
Fix mutate in place source code locations
emcfarlane f291c2a
Update docs
emcfarlane e78e983
Fix name pluginConfigForKey
emcfarlane e39dddd
Fix pluginConfig ref for local job
emcfarlane 56c5fda
Fix indexedPluginConfig consistency
emcfarlane 9a80424
Update --exclude-types comment
emcfarlane 60dbf41
Remove dead comment
emcfarlane a57873e
Clarify test comment
emcfarlane 986a33f
Use IncludeTypes
emcfarlane e7de3e8
Clarify input config ExcludeType docs
emcfarlane d7849e1
Remove options == nil checks
emcfarlane 62dc5d4
Move exclude set
emcfarlane 4c75c24
Move TODO for globs
emcfarlane cd9d8a1
Improve excludeElement extendee check
emcfarlane 219ff4b
Clarify hasOption on unknown types
emcfarlane c20a21c
Doc check is import used
emcfarlane 9e8f745
TODO for better enclosing isDirty check
emcfarlane bc52487
Clarify input config docs for ExcludeTypes
emcfarlane 7b12e98
Do TODO for enclosingType
emcfarlane 5035d61
Simplify default check
emcfarlane 12ce214
Fix include method but exclude input or output
emcfarlane f5cfcd5
Fix empty oneofs
emcfarlane 01f7b09
Fix spacing
emcfarlane f5398e5
Cleanup
emcfarlane 62b4402
Check extendee valid for extension inclusions
emcfarlane 1696cca
Use IncludeTypes naming
emcfarlane 584bde7
Use includeTypes names
emcfarlane 1585379
Merge branch 'main' into ed/excludeOptions
emcfarlane 304f0af
Set options as unrecognized bytes
emcfarlane 698e350
Revert "Set options as unrecognized bytes"
emcfarlane d57a7d9
Move import check to closure
emcfarlane 7b1f6bf
Fix docs
emcfarlane d327c23
Add range check
emcfarlane b4c1f56
Remove options remap
emcfarlane b6a92ee
Remap depencies to catch changes
emcfarlane 412b940
Fix race on bufimage.NewImageForProto
emcfarlane c6b0e6a
Fix source paths remaps for deps
emcfarlane 3c13e37
Format testdata
emcfarlane 1c78fc9
Test consecutive fitlers
emcfarlane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
private/bufpkg/bufimage/bufimageutil/testdata/oneofs/a.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| syntax = "proto3"; | ||
| package pkg; | ||
| import "google/protobuf/descriptor.proto"; | ||
|
|
||
| message Foo { | ||
| oneof oneofFoo { | ||
| option (oneof_foo) = "str"; | ||
| string foo = 1; | ||
| FooEnum foo_enum = 2; | ||
| } | ||
| oneof oneofBar { | ||
| option (oneof_bar) = "str"; | ||
| Bar bar = 3; | ||
| Bar.BarNested bar_nested = 4; | ||
| } | ||
| } | ||
|
|
||
| enum FooEnum { | ||
| FOO_ENUM_X = 0; | ||
| FOO_ENUM_Y = 1; | ||
| } | ||
| message Bar { | ||
| string bar = 1; | ||
| message BarNested { | ||
| string bar = 1; | ||
| } | ||
| } | ||
| extend google.protobuf.OneofOptions { | ||
| optional string oneof_foo = 50000; | ||
| optional string oneof_bar = 50001; | ||
| } |
Empty file.
148 changes: 148 additions & 0 deletions
148
private/bufpkg/bufimage/bufimageutil/testdata/oneofs/pkg.Foo.exclude-bar.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| -- a.proto -- | ||
| syntax = "proto3"; | ||
| package pkg; | ||
| import "google/protobuf/descriptor.proto"; | ||
| message Foo { | ||
| oneof oneofFoo { | ||
| option (oneof_foo) = "str"; | ||
| string foo = 1; | ||
| } | ||
| } | ||
| extend google.protobuf.OneofOptions { | ||
| string oneof_foo = 50000; | ||
| } | ||
| -- google/protobuf/descriptor.proto -- | ||
| syntax = "proto2"; | ||
| package google.protobuf; | ||
| option cc_enable_arenas = true; | ||
| option csharp_namespace = "Google.Protobuf.Reflection"; | ||
| option go_package = "google.golang.org/protobuf/types/descriptorpb"; | ||
| option java_outer_classname = "DescriptorProtos"; | ||
| option java_package = "com.google.protobuf"; | ||
| option objc_class_prefix = "GPB"; | ||
| option optimize_for = SPEED; | ||
| message FeatureSet { | ||
| optional FieldPresence field_presence = 1 [ | ||
| edition_defaults = { value: "EXPLICIT", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "IMPLICIT", edition: EDITION_PROTO3 }, | ||
| edition_defaults = { value: "EXPLICIT", edition: EDITION_2023 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional EnumType enum_type = 2 [ | ||
| edition_defaults = { value: "CLOSED", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "OPEN", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_ENUM, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional RepeatedFieldEncoding repeated_field_encoding = 3 [ | ||
| edition_defaults = { value: "EXPANDED", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "PACKED", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional Utf8Validation utf8_validation = 4 [ | ||
| edition_defaults = { value: "NONE", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "VERIFY", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional MessageEncoding message_encoding = 5 [ | ||
| edition_defaults = { value: "LENGTH_PREFIXED", edition: EDITION_LEGACY }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional JsonFormat json_format = 6 [ | ||
| edition_defaults = { value: "LEGACY_BEST_EFFORT", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "ALLOW", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_MESSAGE, | ||
| targets = TARGET_TYPE_ENUM, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| enum EnumType { | ||
| ENUM_TYPE_UNKNOWN = 0; | ||
| OPEN = 1; | ||
| CLOSED = 2; | ||
| } | ||
| enum FieldPresence { | ||
| FIELD_PRESENCE_UNKNOWN = 0; | ||
| EXPLICIT = 1; | ||
| IMPLICIT = 2; | ||
| LEGACY_REQUIRED = 3; | ||
| } | ||
| enum JsonFormat { | ||
| JSON_FORMAT_UNKNOWN = 0; | ||
| ALLOW = 1; | ||
| LEGACY_BEST_EFFORT = 2; | ||
| } | ||
| enum MessageEncoding { | ||
| MESSAGE_ENCODING_UNKNOWN = 0; | ||
| LENGTH_PREFIXED = 1; | ||
| DELIMITED = 2; | ||
| } | ||
| enum RepeatedFieldEncoding { | ||
| REPEATED_FIELD_ENCODING_UNKNOWN = 0; | ||
| PACKED = 1; | ||
| EXPANDED = 2; | ||
| } | ||
| enum Utf8Validation { | ||
| UTF8_VALIDATION_UNKNOWN = 0; | ||
| VERIFY = 2; | ||
| NONE = 3; | ||
| reserved 1; | ||
| } | ||
| extensions 1000 to 9994 [ | ||
| declaration = { | ||
| number: 1000, | ||
| full_name: ".pb.cpp", | ||
| type: ".pb.CppFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 1001, | ||
| full_name: ".pb.java", | ||
| type: ".pb.JavaFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 1002, | ||
| full_name: ".pb.go", | ||
| type: ".pb.GoFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 9990, | ||
| full_name: ".pb.proto1", | ||
| type: ".pb.Proto1Features" | ||
| } | ||
| ]; | ||
| extensions 9995 to 9999, 10000; | ||
| reserved 999; | ||
| } | ||
| message OneofOptions { | ||
| optional FeatureSet features = 1; | ||
| repeated UninterpretedOption uninterpreted_option = 999; | ||
| extensions 1000 to max; | ||
| } | ||
| message UninterpretedOption { | ||
| repeated NamePart name = 2; | ||
| optional string identifier_value = 3; | ||
| optional uint64 positive_int_value = 4; | ||
| optional int64 negative_int_value = 5; | ||
| optional double double_value = 6; | ||
| optional bytes string_value = 7; | ||
| optional string aggregate_value = 8; | ||
| message NamePart { | ||
| required string name_part = 1; | ||
| required bool is_extension = 2; | ||
| } | ||
| } |
156 changes: 156 additions & 0 deletions
156
private/bufpkg/bufimage/bufimageutil/testdata/oneofs/pkg.Foo.exclude-partial.txtar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| -- a.proto -- | ||
| syntax = "proto3"; | ||
| package pkg; | ||
| import "google/protobuf/descriptor.proto"; | ||
| message Bar { | ||
| string bar = 1; | ||
| } | ||
| message Foo { | ||
| oneof oneofFoo { | ||
| option (oneof_foo) = "str"; | ||
| string foo = 1; | ||
| } | ||
| oneof oneofBar { | ||
| option (oneof_bar) = "str"; | ||
| Bar bar = 3; | ||
| } | ||
| } | ||
| extend google.protobuf.OneofOptions { | ||
| string oneof_foo = 50000; | ||
| string oneof_bar = 50001; | ||
| } | ||
| -- google/protobuf/descriptor.proto -- | ||
| syntax = "proto2"; | ||
| package google.protobuf; | ||
| option cc_enable_arenas = true; | ||
| option csharp_namespace = "Google.Protobuf.Reflection"; | ||
| option go_package = "google.golang.org/protobuf/types/descriptorpb"; | ||
| option java_outer_classname = "DescriptorProtos"; | ||
| option java_package = "com.google.protobuf"; | ||
| option objc_class_prefix = "GPB"; | ||
| option optimize_for = SPEED; | ||
| message FeatureSet { | ||
| optional FieldPresence field_presence = 1 [ | ||
| edition_defaults = { value: "EXPLICIT", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "IMPLICIT", edition: EDITION_PROTO3 }, | ||
| edition_defaults = { value: "EXPLICIT", edition: EDITION_2023 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional EnumType enum_type = 2 [ | ||
| edition_defaults = { value: "CLOSED", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "OPEN", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_ENUM, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional RepeatedFieldEncoding repeated_field_encoding = 3 [ | ||
| edition_defaults = { value: "EXPANDED", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "PACKED", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional Utf8Validation utf8_validation = 4 [ | ||
| edition_defaults = { value: "NONE", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "VERIFY", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional MessageEncoding message_encoding = 5 [ | ||
| edition_defaults = { value: "LENGTH_PREFIXED", edition: EDITION_LEGACY }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_FIELD, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| optional JsonFormat json_format = 6 [ | ||
| edition_defaults = { value: "LEGACY_BEST_EFFORT", edition: EDITION_LEGACY }, | ||
| edition_defaults = { value: "ALLOW", edition: EDITION_PROTO3 }, | ||
| feature_support = { edition_introduced: EDITION_2023 }, | ||
| retention = RETENTION_RUNTIME, | ||
| targets = TARGET_TYPE_MESSAGE, | ||
| targets = TARGET_TYPE_ENUM, | ||
| targets = TARGET_TYPE_FILE | ||
| ]; | ||
| enum EnumType { | ||
| ENUM_TYPE_UNKNOWN = 0; | ||
| OPEN = 1; | ||
| CLOSED = 2; | ||
| } | ||
| enum FieldPresence { | ||
| FIELD_PRESENCE_UNKNOWN = 0; | ||
| EXPLICIT = 1; | ||
| IMPLICIT = 2; | ||
| LEGACY_REQUIRED = 3; | ||
| } | ||
| enum JsonFormat { | ||
| JSON_FORMAT_UNKNOWN = 0; | ||
| ALLOW = 1; | ||
| LEGACY_BEST_EFFORT = 2; | ||
| } | ||
| enum MessageEncoding { | ||
| MESSAGE_ENCODING_UNKNOWN = 0; | ||
| LENGTH_PREFIXED = 1; | ||
| DELIMITED = 2; | ||
| } | ||
| enum RepeatedFieldEncoding { | ||
| REPEATED_FIELD_ENCODING_UNKNOWN = 0; | ||
| PACKED = 1; | ||
| EXPANDED = 2; | ||
| } | ||
| enum Utf8Validation { | ||
| UTF8_VALIDATION_UNKNOWN = 0; | ||
| VERIFY = 2; | ||
| NONE = 3; | ||
| reserved 1; | ||
| } | ||
| extensions 1000 to 9994 [ | ||
| declaration = { | ||
| number: 1000, | ||
| full_name: ".pb.cpp", | ||
| type: ".pb.CppFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 1001, | ||
| full_name: ".pb.java", | ||
| type: ".pb.JavaFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 1002, | ||
| full_name: ".pb.go", | ||
| type: ".pb.GoFeatures" | ||
| }, | ||
| declaration = { | ||
| number: 9990, | ||
| full_name: ".pb.proto1", | ||
| type: ".pb.Proto1Features" | ||
| } | ||
| ]; | ||
| extensions 9995 to 9999, 10000; | ||
| reserved 999; | ||
| } | ||
| message OneofOptions { | ||
| optional FeatureSet features = 1; | ||
| repeated UninterpretedOption uninterpreted_option = 999; | ||
| extensions 1000 to max; | ||
| } | ||
| message UninterpretedOption { | ||
| repeated NamePart name = 2; | ||
| optional string identifier_value = 3; | ||
| optional uint64 positive_int_value = 4; | ||
| optional int64 negative_int_value = 5; | ||
| optional double double_value = 6; | ||
| optional bytes string_value = 7; | ||
| optional string aggregate_value = 8; | ||
| message NamePart { | ||
| required string name_part = 1; | ||
| required bool is_extension = 2; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.