Repository: cross-rs/cross
Pull request #941 (2022-07-11 21:16:56)

replace walkdir with ripgreps ignore crate


Patch:
diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml
index 0dd4b00..0da1820 100644
--- a/.github/actions/setup-rust/action.yml
+++ b/.github/actions/setup-rust/action.yml
@@ -15,6 +15,10 @@ inputs:
 runs:
   using: composite
   steps:
+    # Work around for sporadic issues with rustup self-update on windows
+    - run: rustup set auto-self-update disable
+      if: contains(runner.os, 'windows')
+      shell: bash
     - name: Install Rust toolchain
       uses: actions-rs/toolchain@v1
       with:
diff --git a/Cargo.lock b/Cargo.lock
index d0056e8..d8e0b13 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -64,6 +64,15 @@ version = "1.3.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
 
+[[package]]
+name = "bstr"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
+dependencies = [
+ "memchr",
+]
+
 [[package]]
 name = "cc"
 version = "1.0.73"
@@ -174,6 +183,7 @@ dependencies = [
  "dunce",
  "eyre",
  "home",
+ "ignore",
  "libc",
  "nix",
  "once_cell",
@@ -193,6 +203,16 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+]
+
 [[package]]
 name = "ctrlc"
 version = "3.2.2"
@@ -254,6 +274,12 @@ dependencies = [
  "instant",
 ]
 
+[[package]]
+name = "fnv"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+
 [[package]]
 name = "getrandom"
 version = "0.2.7"
@@ -271,6 +297,19 @@ version = "0.26.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
 
+[[package]]
+name = "globset"
+version = "0.4.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a"
+dependencies = [
+ "aho-corasick",
+ "bstr",
+ "fnv",
+ "log",
+ "regex",
+]
+
 [[package]]
 name = "hashbrown"
 version = "0.12.2"
@@ -301,6 +340,24 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "ignore"
+version = "0.4.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d"
+dependencies = [
+ "crossbeam-utils",
+ "globset",
+ "lazy_static",
+ "log",
+ "memchr",
+ "regex",
+ "same-file",
+ "thread_local",
+ "walkdir",
+ "winapi-util",
+]
+
 [[package]]
 name = "indenter"
 version = "0.3.3"
@@ -356,6 +413,15 @@ version = "0.5.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
 
+[[package]]
+name = "log"
+version = "0.4.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
+dependencies = [
+ "cfg-if",
+]
+
 [[package]]
 name = "memchr"
 version = "2.5.0"
diff --git a/Cargo.toml b/Cargo.toml
index 9df2e9d..a743533 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -63,7 +63,7 @@ lto = true
 [dev-dependencies]
 regex = "1"
 once_cell = "1"
-walkdir = "2"
+ignore = "0.4"
 
 [package.metadata.release]
 dev-version = false


Test patch:
diff --git a/ci/test-bisect.sh b/ci/test-bisect.sh
index 4db9a5a..e61ac67 100755
--- a/ci/test-bisect.sh
+++ b/ci/test-bisect.sh
@@ -32,10 +32,12 @@ main() {
     # shellcheck disable=SC2016
     echo '#!/usr/bin/env bash
 export CROSS_CUSTOM_TOOLCHAIN=1
-exec "${CROSS}" run --target '"${TARGET}" > bisect.sh
+"${CROSS}" run --target '"${TARGET}"'
+cargo -V | grep 2022-06
+' > bisect.sh
     chmod +x bisect.sh
 
-    if ! err=$(cargo bisect-rustc --script=./bisect.sh --target "${TARGET}" 2>&1 >/dev/null); then
+    if ! err=$(cargo bisect-rustc --start 2022-07-01 --end 2022-07-03 --script=./bisect.sh --target "${TARGET}" 2>&1); then
         if [[ "${err}" != *"does not reproduce the regression"* ]]; then
             echo "${err}"
             exit 1
diff --git a/src/tests.rs b/src/tests.rs
index 4dc02ea..b037457 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -27,11 +27,10 @@ pub fn get_cargo_workspace() -> &'static Path {
 
 pub fn walk_dir<'a>(
     root: &'_ Path,
-    skip: &'a [impl AsRef<OsStr>],
-    ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + 'static,
-) -> impl Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>> + 'a {
-    walkdir::WalkDir::new(root)
-        .into_iter()
+    skip: &'static [impl AsRef<OsStr> + Send + Sync + 'a],
+    ext: impl for<'s> Fn(Option<&'s std::ffi::OsStr>) -> bool + Sync + Send + 'static,
+) -> impl Iterator<Item = Result<ignore::DirEntry, ignore::Error>> {
+    ignore::WalkBuilder::new(root)
         .filter_entry(move |e| {
             if skip
                 .iter()
@@ -39,11 +38,12 @@ pub fn walk_dir<'a>(
                 .any(|dir| e.file_name() == dir)
             {
                 return false;
-            } else if e.file_type().is_dir() {
+            } else if e.file_type().map_or(false, |f| f.is_dir()) {
                 return true;
             }
             ext(e.path().extension())
         })
+        .build()
 }
 
 #[test]
@@ -134,9 +134,10 @@ release: {version}
 fn check_newlines() -> crate::Result<()> {
     for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
         let file = file?;
-        if !file.file_type().is_file() {
+        if !file.file_type().map_or(true, |f| f.is_file()) {
             continue;
         }
+        eprintln!("File: {:?}", file.path());
         assert!(
             crate::file::read(file.path())
                 .unwrap_or_else(|_| String::from("\n"))
diff --git a/src/tests/toml.rs b/src/tests/toml.rs
index 377bdb7..fb4f9c1 100644
--- a/src/tests/toml.rs
+++ b/src/tests/toml.rs
@@ -30,7 +30,7 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
 
     for dir_entry in walk {
         let dir_entry = dir_entry?;
-        if dir_entry.file_type().is_dir() {
+        if dir_entry.file_type().map_or(true, |f| f.is_dir()) {
             continue;
         }
         eprintln!("File: {:?}", dir_entry.path());