-
Notifications
You must be signed in to change notification settings - Fork 15
feat: skip global registration for internal generated code #82
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
Open
aaronc
wants to merge
7
commits into
main
Choose a base branch
from
aaronc/internal-skip-register
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b153e55
feat: skip global registration for internal generated code
aaronc 9a9aa31
Merge branch 'main' of github.com:cosmos/cosmos-proto into aaronc/int…
aaronc cf1389f
fixes
aaronc c7be699
simplify, add test
aaronc 66a110f
add tests
aaronc 484e22f
add CHANGELOG.md
aaronc 4559af0
Merge branch 'main' into aaronc/internal-skip-register
aaronc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <!-- | ||
| Guiding Principles: | ||
|
|
||
| Changelogs are for humans, not machines. | ||
| There should be an entry for every single version. | ||
| The same types of changes should be grouped. | ||
| Versions and sections should be linkable. | ||
| The latest version comes first. | ||
| The release date of each version is displayed. | ||
| Mention whether you follow Semantic Versioning. | ||
|
|
||
| Usage: | ||
|
|
||
| Change log entries are to be added to the Unreleased section under the | ||
| appropriate stanza (see below). Each entry should ideally include a tag and | ||
| the Github issue reference in the following format: | ||
|
|
||
| * (<tag>) \#<issue-number> message | ||
|
|
||
| The issue numbers will later be link-ified during the release process so you do | ||
| not have to worry about including a link manually, but you can if you wish. | ||
|
|
||
| Types of changes (Stanzas): | ||
|
|
||
| "Features" for new features. | ||
| "Improvements" for changes in existing functionality. | ||
| "Deprecated" for soon-to-be removed features. | ||
| "Bug Fixes" for any bug fixes. | ||
| "Client Breaking" for breaking Protobuf, gRPC and REST routes used by end-users. | ||
| "CLI Breaking" for breaking CLI commands. | ||
| "API Breaking" for breaking exported APIs used by developers building on SDK. | ||
| Ref: https://keepachangelog.com/en/1.0.0/ | ||
| --> | ||
|
|
||
| # Changelog | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Features | ||
|
|
||
| * [#82](https://github.com/cosmos/cosmos-proto/pull/82) generated code in `internal` go packages is not registered with the global protobuf registry allowing modules to have internal protobuf generated types that are not exposed in public APIs and do not affect global protobuf registration. |
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,17 @@ | ||
| package protoc | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestIsInternalPackage(t *testing.T) { | ||
| require.True(t, isInternalPackage("internal")) | ||
| require.True(t, isInternalPackage("example/internal")) | ||
| require.True(t, isInternalPackage("example.com/internal")) | ||
| require.True(t, isInternalPackage("example.com/internal/foo")) | ||
| require.False(t, isInternalPackage("example")) | ||
| require.False(t, isInternalPackage("example.com")) | ||
| require.False(t, isInternalPackage("example.com/false")) | ||
| } |
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
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,16 @@ | ||
| package test3 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/protobuf/reflect/protoregistry" | ||
| ) | ||
|
|
||
| func TestInternalNotRegistered(t *testing.T) { | ||
| _, err := protoregistry.GlobalTypes.FindMessageByName((&TestAllTypes{}).ProtoReflect().Descriptor().FullName()) | ||
| require.Error(t, err) | ||
|
|
||
| _, err = protoregistry.GlobalFiles.FindFileByPath("internal/testprotos/test3/test_import.proto") | ||
| require.Error(t, err) | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
| package runtime | ||
|
|
||
| import ( | ||
| "google.golang.org/protobuf/reflect/protoreflect" | ||
| "google.golang.org/protobuf/reflect/protoregistry" | ||
| ) | ||
|
|
||
| // NullRegistry is an implementation of the interfaces used to register generated | ||
| // types and file descriptors that does nothing. This is used to generated | ||
| // protobuf files in internal packages that are not registered with the global registry. | ||
| type NullRegistry struct{} | ||
|
|
||
| func (NullRegistry) RegisterMessage(protoreflect.MessageType) error { return nil } | ||
| func (NullRegistry) RegisterEnum(protoreflect.EnumType) error { return nil } | ||
| func (NullRegistry) RegisterExtension(protoreflect.ExtensionType) error { return nil } | ||
| func (NullRegistry) RegisterFile(protoreflect.FileDescriptor) error { return nil } | ||
|
|
||
| func (NullRegistry) FindFileByPath(path string) (protoreflect.FileDescriptor, error) { | ||
| return protoregistry.GlobalFiles.FindFileByPath(path) | ||
| } | ||
| func (NullRegistry) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { | ||
| return protoregistry.GlobalFiles.FindDescriptorByName(name) | ||
| } |
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.