Don't skip all directories when tidy-checking
This commit is contained in:
parent
dd19135b04
commit
436afdf1fe
@ -10,7 +10,7 @@ fn main() {
|
|||||||
let version_str = version_str.trim();
|
let version_str = version_str.trim();
|
||||||
walk::walk(
|
walk::walk(
|
||||||
&root_path,
|
&root_path,
|
||||||
|path| {
|
|path, _is_dir| {
|
||||||
walk::filter_dirs(path)
|
walk::filter_dirs(path)
|
||||||
// We exempt these as they require the placeholder
|
// We exempt these as they require the placeholder
|
||||||
// for their operation
|
// for their operation
|
||||||
|
@ -95,7 +95,7 @@ fn check_section<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
walk(path, filter_dirs, &mut |entry, contents| {
|
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
|
||||||
let file = &entry.path().display();
|
let file = &entry.path().display();
|
||||||
|
|
||||||
let mut lines = contents.lines().enumerate().peekable();
|
let mut lines = contents.lines().enumerate().peekable();
|
||||||
|
@ -103,36 +103,40 @@ mod os_impl {
|
|||||||
|
|
||||||
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
||||||
// (e.g. using `git ls-files`).
|
// (e.g. using `git ls-files`).
|
||||||
walk_no_read(&[path], |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
|
walk_no_read(
|
||||||
let file = entry.path();
|
&[path],
|
||||||
let extension = file.extension();
|
|path, _is_dir| filter_dirs(path) || path.ends_with("src/etc"),
|
||||||
let scripts = ["py", "sh", "ps1"];
|
&mut |entry| {
|
||||||
if scripts.into_iter().any(|e| extension == Some(OsStr::new(e))) {
|
let file = entry.path();
|
||||||
return;
|
let extension = file.extension();
|
||||||
}
|
let scripts = ["py", "sh", "ps1"];
|
||||||
|
if scripts.into_iter().any(|e| extension == Some(OsStr::new(e))) {
|
||||||
if t!(is_executable(&file), file) {
|
|
||||||
let rel_path = file.strip_prefix(path).unwrap();
|
|
||||||
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
|
|
||||||
|
|
||||||
if ALLOWED.contains(&git_friendly_path.as_str()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new("git")
|
if t!(is_executable(&file), file) {
|
||||||
.arg("ls-files")
|
let rel_path = file.strip_prefix(path).unwrap();
|
||||||
.arg(&git_friendly_path)
|
let git_friendly_path = rel_path.to_str().unwrap().replace("\\", "/");
|
||||||
.current_dir(path)
|
|
||||||
.stderr(Stdio::null())
|
if ALLOWED.contains(&git_friendly_path.as_str()) {
|
||||||
.output()
|
return;
|
||||||
.unwrap_or_else(|e| {
|
}
|
||||||
panic!("could not run git ls-files: {e}");
|
|
||||||
});
|
let output = Command::new("git")
|
||||||
let path_bytes = rel_path.as_os_str().as_bytes();
|
.arg("ls-files")
|
||||||
if output.status.success() && output.stdout.starts_with(path_bytes) {
|
.arg(&git_friendly_path)
|
||||||
tidy_error!(bad, "binary checked into source: {}", file.display());
|
.current_dir(path)
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.output()
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
panic!("could not run git ls-files: {e}");
|
||||||
|
});
|
||||||
|
let path_bytes = rel_path.as_os_str().as_bytes();
|
||||||
|
if output.status.success() && output.stdout.starts_with(path_bytes) {
|
||||||
|
tidy_error!(bad, "binary checked into source: {}", file.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,21 @@ use std::path::Path;
|
|||||||
const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";
|
const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";
|
||||||
|
|
||||||
pub fn check(test_dir: &Path, bad: &mut bool) {
|
pub fn check(test_dir: &Path, bad: &mut bool) {
|
||||||
walk(test_dir, |path| filter_dirs(path) || filter_not_rust(path), &mut |entry, contents| {
|
walk(
|
||||||
for (i, line) in contents.lines().enumerate() {
|
test_dir,
|
||||||
if line.contains("borrowck_graphviz_postflow") {
|
|path, _is_dir| filter_dirs(path) || filter_not_rust(path),
|
||||||
tidy_error!(bad, "{}:{}: {}", entry.path().display(), i + 1, GRAPHVIZ_POSTFLOW_MSG);
|
&mut |entry, contents| {
|
||||||
|
for (i, line) in contents.lines().enumerate() {
|
||||||
|
if line.contains("borrowck_graphviz_postflow") {
|
||||||
|
tidy_error!(
|
||||||
|
bad,
|
||||||
|
"{}:{}: {}",
|
||||||
|
entry.path().display(),
|
||||||
|
i + 1,
|
||||||
|
GRAPHVIZ_POSTFLOW_MSG
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ fn is_edition_2021(mut line: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
walk(path, |path| filter_dirs(path), &mut |entry, contents| {
|
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
|
||||||
let file = entry.path();
|
let file = entry.path();
|
||||||
let filename = file.file_name().unwrap();
|
let filename = file.file_name().unwrap();
|
||||||
if filename != "Cargo.toml" {
|
if filename != "Cargo.toml" {
|
||||||
|
@ -129,7 +129,7 @@ fn check_error_codes_docs(
|
|||||||
|
|
||||||
let mut no_longer_emitted_codes = Vec::new();
|
let mut no_longer_emitted_codes = Vec::new();
|
||||||
|
|
||||||
walk(&docs_path, |_| false, &mut |entry, contents| {
|
walk(&docs_path, |_, _| false, &mut |entry, contents| {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
// Error if the file isn't markdown.
|
// Error if the file isn't markdown.
|
||||||
@ -321,7 +321,7 @@ fn check_error_codes_used(
|
|||||||
|
|
||||||
let mut found_codes = Vec::new();
|
let mut found_codes = Vec::new();
|
||||||
|
|
||||||
walk_many(search_paths, filter_dirs, &mut |entry, contents| {
|
walk_many(search_paths, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
// Return early if we aren't looking at a source file.
|
// Return early if we aren't looking at a source file.
|
||||||
|
@ -102,7 +102,7 @@ pub fn check(
|
|||||||
&tests_path.join("rustdoc-ui"),
|
&tests_path.join("rustdoc-ui"),
|
||||||
&tests_path.join("rustdoc"),
|
&tests_path.join("rustdoc"),
|
||||||
],
|
],
|
||||||
|path| {
|
|path, _is_dir| {
|
||||||
filter_dirs(path)
|
filter_dirs(path)
|
||||||
|| filter_not_rust(path)
|
|| filter_not_rust(path)
|
||||||
|| path.file_name() == Some(OsStr::new("features.rs"))
|
|| path.file_name() == Some(OsStr::new("features.rs"))
|
||||||
@ -478,7 +478,7 @@ fn map_lib_features(
|
|||||||
) {
|
) {
|
||||||
walk(
|
walk(
|
||||||
base_src_path,
|
base_src_path,
|
||||||
|path| filter_dirs(path) || path.ends_with("tests"),
|
|path, _is_dir| filter_dirs(path) || path.ends_with("tests"),
|
||||||
&mut |entry, contents| {
|
&mut |entry, contents| {
|
||||||
let file = entry.path();
|
let file = entry.path();
|
||||||
let filename = file.file_name().unwrap().to_string_lossy();
|
let filename = file.file_name().unwrap().to_string_lossy();
|
||||||
|
@ -11,7 +11,7 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
|
|||||||
|
|
||||||
walk_no_read(
|
walk_no_read(
|
||||||
&[&path.join("mir-opt")],
|
&[&path.join("mir-opt")],
|
||||||
|path| path.file_name() == Some("README.md".as_ref()),
|
|path, _is_dir| path.file_name() == Some("README.md".as_ref()),
|
||||||
&mut |file| {
|
&mut |file| {
|
||||||
let filepath = file.path();
|
let filepath = file.path();
|
||||||
if filepath.extension() == Some("rs".as_ref()) {
|
if filepath.extension() == Some("rs".as_ref()) {
|
||||||
|
@ -67,7 +67,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||||||
// Sanity check that the complex parsing here works.
|
// Sanity check that the complex parsing here works.
|
||||||
let mut saw_target_arch = false;
|
let mut saw_target_arch = false;
|
||||||
let mut saw_cfg_bang = false;
|
let mut saw_cfg_bang = false;
|
||||||
walk(path, filter_dirs, &mut |entry, contents| {
|
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
|
||||||
let file = entry.path();
|
let file = entry.path();
|
||||||
let filestr = file.to_string_lossy().replace("\\", "/");
|
let filestr = file.to_string_lossy().replace("\\", "/");
|
||||||
if !filestr.ends_with(".rs") {
|
if !filestr.ends_with(".rs") {
|
||||||
|
@ -5,10 +5,7 @@ use std::path::Path;
|
|||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
crate::walk::walk(
|
crate::walk::walk(
|
||||||
&path.join("rustdoc-gui"),
|
&path.join("rustdoc-gui"),
|
||||||
|p| {
|
|p, is_dir| !is_dir && p.extension().map_or(true, |e| e != "goml"),
|
||||||
// If there is no extension, it's very likely a folder and we want to go into it.
|
|
||||||
p.extension().map(|e| e != "goml").unwrap_or(false)
|
|
||||||
},
|
|
||||||
&mut |entry, content| {
|
&mut |entry, content| {
|
||||||
for line in content.lines() {
|
for line in content.lines() {
|
||||||
if !line.starts_with("// ") {
|
if !line.starts_with("// ") {
|
||||||
|
@ -227,7 +227,7 @@ fn is_unexplained_ignore(extension: &str, line: &str) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
fn skip(path: &Path) -> bool {
|
fn skip(path: &Path, is_dir: bool) -> bool {
|
||||||
if path.file_name().map_or(false, |name| name.to_string_lossy().starts_with(".#")) {
|
if path.file_name().map_or(false, |name| name.to_string_lossy().starts_with(".#")) {
|
||||||
// vim or emacs temporary file
|
// vim or emacs temporary file
|
||||||
return true;
|
return true;
|
||||||
@ -237,8 +237,15 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't check extensions for directories
|
||||||
|
if is_dir {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let extensions = ["rs", "py", "js", "sh", "c", "cpp", "h", "md", "css", "ftl", "goml"];
|
let extensions = ["rs", "py", "js", "sh", "c", "cpp", "h", "md", "css", "ftl", "goml"];
|
||||||
if extensions.iter().all(|e| path.extension() != Some(OsStr::new(e))) {
|
|
||||||
|
// NB: don't skip paths without extensions (or else we'll skip all directories and will only check top level files)
|
||||||
|
if path.extension().map_or(true, |ext| !extensions.iter().any(|e| ext == OsStr::new(e))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ struct RevisionInfo<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
crate::walk::walk(path, filter_not_rust, &mut |entry, content| {
|
crate::walk::walk(path, |path, _is_dir| filter_not_rust(path), &mut |entry, content| {
|
||||||
let file = entry.path().display();
|
let file = entry.path().display();
|
||||||
let mut header_map = BTreeMap::new();
|
let mut header_map = BTreeMap::new();
|
||||||
iter_header(content, &mut |cfg, directive| {
|
iter_header(content, &mut |cfg, directive| {
|
||||||
|
@ -51,7 +51,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
|||||||
check_entries(&path, bad);
|
check_entries(&path, bad);
|
||||||
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
|
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
|
||||||
let paths = [ui.as_path(), ui_fulldeps.as_path()];
|
let paths = [ui.as_path(), ui_fulldeps.as_path()];
|
||||||
crate::walk::walk_no_read(&paths, |_| false, &mut |entry| {
|
crate::walk::walk_no_read(&paths, |_, _| false, &mut |entry| {
|
||||||
let file_path = entry.path();
|
let file_path = entry.path();
|
||||||
if let Some(ext) = file_path.extension() {
|
if let Some(ext) = file_path.extension() {
|
||||||
if ext == "stderr" || ext == "stdout" {
|
if ext == "stderr" || ext == "stdout" {
|
||||||
|
@ -20,9 +20,9 @@ pub fn check(root_path: &Path, bad: &mut bool) {
|
|||||||
&& !(path.starts_with(&core_tests) || path.starts_with(&core_benches))
|
&& !(path.starts_with(&core_tests) || path.starts_with(&core_benches))
|
||||||
};
|
};
|
||||||
|
|
||||||
let skip = move |path: &Path| {
|
let skip = move |path: &Path, is_dir| {
|
||||||
let file_name = path.file_name().unwrap_or_default();
|
let file_name = path.file_name().unwrap_or_default();
|
||||||
if path.is_dir() {
|
if is_dir {
|
||||||
filter_dirs(path)
|
filter_dirs(path)
|
||||||
|| path.ends_with("src/doc")
|
|| path.ends_with("src/doc")
|
||||||
|| (file_name == "tests" || file_name == "benches") && !is_core(path)
|
|| (file_name == "tests" || file_name == "benches") && !is_core(path)
|
||||||
|
@ -41,7 +41,7 @@ pub fn filter_not_rust(path: &Path) -> bool {
|
|||||||
|
|
||||||
pub fn walk(
|
pub fn walk(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path, bool) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
) {
|
) {
|
||||||
walk_many(&[path], skip, f);
|
walk_many(&[path], skip, f);
|
||||||
@ -49,7 +49,7 @@ pub fn walk(
|
|||||||
|
|
||||||
pub fn walk_many(
|
pub fn walk_many(
|
||||||
paths: &[&Path],
|
paths: &[&Path],
|
||||||
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path, bool) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
) {
|
) {
|
||||||
let mut contents = Vec::new();
|
let mut contents = Vec::new();
|
||||||
@ -67,14 +67,16 @@ pub fn walk_many(
|
|||||||
|
|
||||||
pub(crate) fn walk_no_read(
|
pub(crate) fn walk_no_read(
|
||||||
paths: &[&Path],
|
paths: &[&Path],
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Send + Sync + 'static + Fn(&Path, bool) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry),
|
f: &mut dyn FnMut(&DirEntry),
|
||||||
) {
|
) {
|
||||||
let mut walker = ignore::WalkBuilder::new(paths[0]);
|
let mut walker = ignore::WalkBuilder::new(paths[0]);
|
||||||
for path in &paths[1..] {
|
for path in &paths[1..] {
|
||||||
walker.add(path);
|
walker.add(path);
|
||||||
}
|
}
|
||||||
let walker = walker.filter_entry(move |e| !skip(e.path()));
|
let walker = walker.filter_entry(move |e| {
|
||||||
|
!skip(e.path(), e.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
|
||||||
|
});
|
||||||
for entry in walker.build() {
|
for entry in walker.build() {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
if entry.file_type().map_or(true, |kind| kind.is_dir() || kind.is_symlink()) {
|
if entry.file_type().map_or(true, |kind| kind.is_dir() || kind.is_symlink()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user