diff options
Diffstat (limited to 'xtask/src/lib.rs')
-rw-r--r-- | xtask/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index e1472e85d..4f01f84fb 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs | |||
@@ -17,6 +17,7 @@ use std::{ | |||
17 | path::{Path, PathBuf}, | 17 | path::{Path, PathBuf}, |
18 | process::{Command, Stdio}, | 18 | process::{Command, Stdio}, |
19 | }; | 19 | }; |
20 | use walkdir::{DirEntry, WalkDir}; | ||
20 | 21 | ||
21 | use crate::{ | 22 | use crate::{ |
22 | codegen::Mode, | 23 | codegen::Mode, |
@@ -37,6 +38,21 @@ pub fn project_root() -> PathBuf { | |||
37 | .to_path_buf() | 38 | .to_path_buf() |
38 | } | 39 | } |
39 | 40 | ||
41 | pub fn rust_files(path: &Path) -> impl Iterator<Item = PathBuf> { | ||
42 | let iter = WalkDir::new(path); | ||
43 | return iter | ||
44 | .into_iter() | ||
45 | .filter_entry(|e| !is_hidden(e)) | ||
46 | .map(|e| e.unwrap()) | ||
47 | .filter(|e| !e.file_type().is_dir()) | ||
48 | .map(|e| e.into_path()) | ||
49 | .filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false)); | ||
50 | |||
51 | fn is_hidden(entry: &DirEntry) -> bool { | ||
52 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
53 | } | ||
54 | } | ||
55 | |||
40 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 56 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
41 | let _dir = pushd(project_root()); | 57 | let _dir = pushd(project_root()); |
42 | ensure_rustfmt()?; | 58 | ensure_rustfmt()?; |