perf(solc): add iterator function for finding sol files (#1480)
This commit is contained in:
parent
d509f7a7c6
commit
cca3fcec93
|
@ -119,13 +119,25 @@ impl ProjectPathsConfig {
|
|||
Ok(Source::read_all_from(&self.scripts)?)
|
||||
}
|
||||
|
||||
/// Returns the combined set solidity file paths for `Self::sources` and `Self::tests`
|
||||
/// Returns true if the there is at least one solidity file in this config.
|
||||
///
|
||||
/// See also, `Self::input_files()`
|
||||
pub fn has_input_files(&self) -> bool {
|
||||
self.input_files_iter().next().is_some()
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields all solidity file paths for `Self::sources`, `Self::tests`
|
||||
/// and `Self::scripts`
|
||||
pub fn input_files_iter(&self) -> impl Iterator<Item = PathBuf> + '_ {
|
||||
utils::source_files_iter(&self.sources)
|
||||
.chain(utils::source_files_iter(&self.tests))
|
||||
.chain(utils::source_files_iter(&self.scripts))
|
||||
}
|
||||
|
||||
/// Returns the combined set solidity file paths for `Self::sources`, `Self::tests` and
|
||||
/// `Self::scripts`
|
||||
pub fn input_files(&self) -> Vec<PathBuf> {
|
||||
utils::source_files(&self.sources)
|
||||
.into_iter()
|
||||
.chain(utils::source_files(&self.tests))
|
||||
.chain(utils::source_files(&self.scripts))
|
||||
.collect()
|
||||
self.input_files_iter().collect()
|
||||
}
|
||||
|
||||
/// Returns the combined set of `Self::read_sources` + `Self::read_tests` + `Self::read_scripts`
|
||||
|
|
|
@ -72,6 +72,22 @@ pub fn find_version_pragma(contract: &str) -> Option<Match> {
|
|||
RE_SOL_PRAGMA_VERSION.captures(contract)?.name("version")
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields all solidity/yul files funder under the given root path or the
|
||||
/// `root` itself, if it is a sol/yul file
|
||||
///
|
||||
/// This also follows symlinks.
|
||||
pub fn source_files_iter(root: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
|
||||
WalkDir::new(root)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|e| e.file_type().is_file())
|
||||
.filter(|e| {
|
||||
e.path().extension().map(|ext| (ext == "sol") || (ext == "yul")).unwrap_or_default()
|
||||
})
|
||||
.map(|e| e.path().into())
|
||||
}
|
||||
|
||||
/// Returns a list of absolute paths to all the solidity files under the root, or the file itself,
|
||||
/// if the path is a solidity file.
|
||||
///
|
||||
|
@ -86,16 +102,7 @@ pub fn find_version_pragma(contract: &str) -> Option<Match> {
|
|||
/// let sources = utils::source_files("./contracts");
|
||||
/// ```
|
||||
pub fn source_files(root: impl AsRef<Path>) -> Vec<PathBuf> {
|
||||
WalkDir::new(root)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|e| e.file_type().is_file())
|
||||
.filter(|e| {
|
||||
e.path().extension().map(|ext| (ext == "sol") || (ext == "yul")).unwrap_or_default()
|
||||
})
|
||||
.map(|e| e.path().into())
|
||||
.collect()
|
||||
source_files_iter(root).collect()
|
||||
}
|
||||
|
||||
/// Returns a list of _unique_ paths to all folders under `root` that contain at least one solidity
|
||||
|
|
Loading…
Reference in New Issue