diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-21 18:27:23 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-21 18:27:23 +0000 |
commit | fdb12f3e0ecf827d10f81ba4dd0824a3bdce1c97 (patch) | |
tree | 31d89ca9d79afa29c54d30e3a9fa2679d44bd976 /xtask | |
parent | a2b5fbb07660f192166f96523680ea31c470736a (diff) | |
parent | 90c66470f9d87fd61a9d80b6f29e53e85a0a340e (diff) |
Merge #3672
3672: gen_assists_docs skip hidden files r=JoshMcguigan a=JoshMcguigan
Fixes #3670
Skips hidden files when generating assist docs, which fixes an issue where the tests would fail while an editor has created a temp file in the assists directory.
There is similar logic [here](https://github.com/rust-analyzer/rust-analyzer/blob/2720e2374be951bb762ff2815dd67c7ffe3419b7/xtask/tests/tidy-tests/main.rs#L157), although in that case the `DirEntry` is a `walkdir::DirEntry` rather than a `fs::DirEntry`. Also, it's not immediately clear that it is worth moving this functionality to somewhere accessible from both of these places and creating dependencies in this way. Let me know if this is off the mark.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 10 | ||||
-rw-r--r-- | xtask/src/lib.rs | 16 | ||||
-rw-r--r-- | xtask/tests/tidy-tests/main.rs | 21 |
3 files changed, 21 insertions, 26 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 | ||
5 | use crate::{ | 5 | use 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 | ||
10 | pub fn generate_assists_docs(mode: Mode) -> Result<()> { | 10 | pub fn generate_assists_docs(mode: Mode) -> Result<()> { |
@@ -46,12 +46,8 @@ fn reveal_hash_comments(text: &str) -> String { | |||
46 | 46 | ||
47 | fn collect_assists() -> Result<Vec<Assist>> { | 47 | fn 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 | }; |
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()?; |
diff --git a/xtask/tests/tidy-tests/main.rs b/xtask/tests/tidy-tests/main.rs index 5ae86c87c..80911a68e 100644 --- a/xtask/tests/tidy-tests/main.rs +++ b/xtask/tests/tidy-tests/main.rs | |||
@@ -5,13 +5,12 @@ use std::{ | |||
5 | path::{Path, PathBuf}, | 5 | path::{Path, PathBuf}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use walkdir::{DirEntry, WalkDir}; | 8 | use xtask::{not_bash::fs2, project_root, rust_files}; |
9 | use xtask::{not_bash::fs2, project_root}; | ||
10 | 9 | ||
11 | #[test] | 10 | #[test] |
12 | fn rust_files_are_tidy() { | 11 | fn rust_files_are_tidy() { |
13 | let mut tidy_docs = TidyDocs::default(); | 12 | let mut tidy_docs = TidyDocs::default(); |
14 | for path in rust_files() { | 13 | for path in rust_files(&project_root().join("crates")) { |
15 | let text = fs2::read_to_string(&path).unwrap(); | 14 | let text = fs2::read_to_string(&path).unwrap(); |
16 | check_todo(&path, &text); | 15 | check_todo(&path, &text); |
17 | check_trailing_ws(&path, &text); | 16 | check_trailing_ws(&path, &text); |
@@ -142,19 +141,3 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool { | |||
142 | 141 | ||
143 | false | 142 | false |
144 | } | 143 | } |
145 | |||
146 | fn rust_files() -> impl Iterator<Item = PathBuf> { | ||
147 | let crates = project_root().join("crates"); | ||
148 | let iter = WalkDir::new(crates); | ||
149 | return iter | ||
150 | .into_iter() | ||
151 | .filter_entry(|e| !is_hidden(e)) | ||
152 | .map(|e| e.unwrap()) | ||
153 | .filter(|e| !e.file_type().is_dir()) | ||
154 | .map(|e| e.into_path()) | ||
155 | .filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false)); | ||
156 | |||
157 | fn is_hidden(entry: &DirEntry) -> bool { | ||
158 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
159 | } | ||
160 | } | ||