Repository navigation
Honor exclusions when compiling protobuf files - #336
Merged
Merged
Conversation
Match exclusions on path boundaries and pass the discovered files directly to protoc so excluded siblings cannot be picked up again.
stephanos
commented
Nov 24, 2026
| } | ||
|
|
||
| for i := 0; i < len(exclusions); i++ { | ||
| if strings.HasPrefix(path, exclusions[i]) { |
Contributor
Author
There was a problem hiding this comment.
Bug: For example, excluding temporal/api_next also matches temporal/api_next_other.
stephanos
commented
Nov 24, 2026
|
|
||
| for i := 0; i < len(protoDirs); i++ { | ||
| dir := protoDirs[i] | ||
| files, err := filepath.Glob(filepath.Join(dir, "*.proto")) |
Contributor
Author
There was a problem hiding this comment.
Bug: This glob adds excluded files back. Once discovery finds any included proto in this directory, the glob passes every sibling to protoc, including the files the walker skipped.
Reject file paths with a clear error and test that excluded directories leave similarly named siblings eligible for compilation.
Clean directory paths before matching exclusions and shorten the flag help.
Verify the descriptor output and rejected file paths through one table-driven compile test.
mavemuri
approved these changes
Nov 30, 2026
|
|
||
| relPath, relErr := filepath.Rel(root, path) | ||
| for _, exclusion := range exclusions { | ||
| exact := path == exclusion || relErr == nil && relPath == exclusion |
Contributor
There was a problem hiding this comment.
Suggested change
| exact := path == exclusion || relErr == nil && relPath == exclusion | |
| exact := path == exclusion || (relErr == nil && relPath == exclusion) |
| } | ||
|
|
||
| prefix := exclusion + string(filepath.Separator) | ||
| if exact || strings.HasPrefix(path, prefix) || relErr == nil && strings.HasPrefix(relPath, prefix) { |
Contributor
There was a problem hiding this comment.
Suggested change
| if exact || strings.HasPrefix(path, prefix) || relErr == nil && strings.HasPrefix(relPath, prefix) { | |
| if exact || strings.HasPrefix(path, prefix) || (relErr == nil && strings.HasPrefix(relPath, prefix)) { |
| if strings.HasPrefix(path, exclusions[i]) { | ||
| return fs.SkipDir | ||
|
|
||
| relPath, relErr := filepath.Rel(root, path) |
Contributor
There was a problem hiding this comment.
wdyt about checking relErr here itself? exact/path==exclusion would not care about the error but this relErr shouldnt really happen anyway, itll clear up the relErr checks further down
| wantFiles []string | ||
| wantError string | ||
| }{ | ||
| { |
Contributor
There was a problem hiding this comment.
maybe add some full path TCs too?
Check the Rel error up front so the exclusion matching does not need to guard on it, and add full-path exclusion cases. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
stephanos
enabled auto-merge (squash)
December 2, 2026 03:35
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changed?
Match directory exclusions on path boundaries, reject file exclusions, and pass only the discovered proto files to
protoc.Why?
Prefix matching could exclude similarly named directories, and globbing after discovery could reintroduce skipped files.
How did you test it?
Ran
go test -count=1 ./cmd/protogenand verified that the CLI rejects a file exclusion.Potential risks
Callers passing a file path to
--excludenow receive a CLI error.