aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2020-03-21 15:04:28 +0000
committerJosh Mcguigan <[email protected]>2020-03-21 16:39:45 +0000
commit90c66470f9d87fd61a9d80b6f29e53e85a0a340e (patch)
treef70d3fb1cac9b15ca595876211b0325e0d021fc5 /xtask/src
parent5e827bd948ea206328b126345ab8e909978b3b9b (diff)
gen_assists_docs skip hidden files
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs10
-rw-r--r--xtask/src/lib.rs16
2 files changed, 19 insertions, 7 deletions
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs
index 6da5ca89e..31d606535 100644
--- a/xtask/src/codegen/gen_assists_docs.rs
+++ b/xtask/src/codegen/gen_assists_docs.rs
@@ -4,7 +4,7 @@ use std::{fs, path::Path};
4 4
5use crate::{ 5use crate::{
6 codegen::{self, extract_comment_blocks_with_empty_lines, Mode}, 6 codegen::{self, extract_comment_blocks_with_empty_lines, Mode},
7 project_root, Result, 7 project_root, rust_files, Result,
8}; 8};
9 9
10pub fn generate_assists_docs(mode: Mode) -> Result<()> { 10pub fn generate_assists_docs(mode: Mode) -> Result<()> {
@@ -46,12 +46,8 @@ fn reveal_hash_comments(text: &str) -> String {
46 46
47fn collect_assists() -> Result<Vec<Assist>> { 47fn collect_assists() -> Result<Vec<Assist>> {
48 let mut res = Vec::new(); 48 let mut res = Vec::new();
49 for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? { 49 for path in rust_files(&project_root().join(codegen::ASSISTS_DIR)) {
50 let entry = entry?; 50 collect_file(&mut res, path.as_path())?;
51 let path = entry.path();
52 if path.is_file() {
53 collect_file(&mut res, path.as_path())?;
54 }
55 } 51 }
56 res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id)); 52 res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
57 return Ok(res); 53 return Ok(res);
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};
20use walkdir::{DirEntry, WalkDir};
20 21
21use crate::{ 22use 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
41pub 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
40pub fn run_rustfmt(mode: Mode) -> Result<()> { 56pub fn run_rustfmt(mode: Mode) -> Result<()> {
41 let _dir = pushd(project_root()); 57 let _dir = pushd(project_root());
42 ensure_rustfmt()?; 58 ensure_rustfmt()?;