-
Notifications
You must be signed in to change notification settings - Fork 6
Walk proto dirs instead of manually specifying files #19
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
Conversation
This file contains 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
443f571
to
6663fd3
Compare
ecpullen
approved these changes
Apr 4, 2025
lib/proto/build.rs
Outdated
Comment on lines
31
to
55
fn fetch_proto_dirs( | ||
proto_package_dir: &Path, | ||
proto_version: usize, | ||
ignore_modules: Vec<&str>, | ||
) -> std::io::Result<Vec<PathBuf>> { | ||
let version_str = format!("v{proto_version}"); | ||
|
||
let ignore_components = ignore_modules | ||
.iter() | ||
.map(|module| Component::Normal(OsStr::new(module))) | ||
.collect::<Vec<_>>(); | ||
|
||
let proto_paths = WalkDir::new(proto_package_dir) | ||
.into_iter() | ||
.filter(|entry| { | ||
let entry = if let Ok(entry) = entry { | ||
entry | ||
} else { | ||
return false; | ||
}; | ||
|
||
entry.path().extension().is_some_and(|ext| ext == "proto") | ||
&& entry | ||
.path() | ||
.components() | ||
.any(|comp| comp == Component::Normal(OsStr::new(&version_str))) | ||
&& !entry | ||
.path() | ||
.components() | ||
.any(|comp| ignore_components.contains(&comp)) | ||
}) | ||
.collect::<Result<Vec<_>, _>>()?; | ||
|
||
Ok(proto_paths | ||
.iter() | ||
.map(|entry| entry.path().to_path_buf()) | ||
.collect::<Vec<PathBuf>>()) | ||
} |
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.
Is this any cleaner?
Suggested change
fn fetch_proto_dirs( | |
proto_package_dir: &Path, | |
proto_version: usize, | |
ignore_modules: Vec<&str>, | |
) -> std::io::Result<Vec<PathBuf>> { | |
let version_str = format!("v{proto_version}"); | |
let ignore_components = ignore_modules | |
.iter() | |
.map(|module| Component::Normal(OsStr::new(module))) | |
.collect::<Vec<_>>(); | |
let proto_paths = WalkDir::new(proto_package_dir) | |
.into_iter() | |
.filter(|entry| { | |
let entry = if let Ok(entry) = entry { | |
entry | |
} else { | |
return false; | |
}; | |
entry.path().extension().is_some_and(|ext| ext == "proto") | |
&& entry | |
.path() | |
.components() | |
.any(|comp| comp == Component::Normal(OsStr::new(&version_str))) | |
&& !entry | |
.path() | |
.components() | |
.any(|comp| ignore_components.contains(&comp)) | |
}) | |
.collect::<Result<Vec<_>, _>>()?; | |
Ok(proto_paths | |
.iter() | |
.map(|entry| entry.path().to_path_buf()) | |
.collect::<Vec<PathBuf>>()) | |
} | |
fn fetch_proto_dirs( | |
proto_package_dir: &Path, | |
proto_version: usize, | |
ignore_modules: &[&str], | |
) -> std::io::Result<Vec<PathBuf>> { | |
let version_str = format!("v{proto_version}"); | |
Ok(WalkDir::new(proto_package_dir) | |
.into_iter() | |
// Remove all files that don't have read permission | |
.filter_map(|e| e.ok()) | |
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "proto")) | |
.filter(|entry| entry.path().components().filter_map(|comp| comp.as_os_str().to_str()).any(|comp| comp == version_str)) | |
.filter(|entry| !entry.path().components().filter_map(|comp| comp.as_os_str().to_str()).any(|comp| ignore_modules.contains(&comp))) | |
.map(|entry| entry.path().to_path_buf()).collect()) | |
} |
6663fd3
to
8675ce9
Compare
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.
Issue Number:
Reference the issue this PR fixes.
Description of Changes:
Provide a clear and concise explanation of what changes you made and why.
Testing Done:
How did you test your changes? Share details like steps, tools used, or results.
Terms of contribution:
By submitting this pull request, I agree that this contribution is licensed under the terms of the Apache License, Version 2.0.
Thanks for submitting your pull request! We will review it as soon as possible.