about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2020-02-14 19:03:45 +0100
committerAleksey Kladov <aleksey.kladov@gmail.com>2020-02-14 19:03:45 +0100
commit5acb467894053cb0342eb6ded4d162b4a6912483 (patch)
treeca367a3b7a23f96d2149f3f14b908f099c48dc9e
parentcd956a191f8cb32573be7a78139ad322051e949e (diff)
downloadrust-5acb467894053cb0342eb6ded4d162b4a6912483.tar.gz
rust-5acb467894053cb0342eb6ded4d162b4a6912483.zip
Move rm_rf to not-bash
-rw-r--r--xtask/src/lib.rs11
-rw-r--r--xtask/src/not_bash.rs21
2 files changed, 23 insertions, 9 deletions
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index cebb14abcf6..25b64301c77 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -9,7 +9,7 @@ mod ast_src;
 
 use anyhow::Context;
 use std::{
-    env, fs,
+    env,
     io::Write,
     path::{Path, PathBuf},
     process::{Command, Stdio},
@@ -17,7 +17,7 @@ use std::{
 
 use crate::{
     codegen::Mode,
-    not_bash::{fs2, pushd, run},
+    not_bash::{fs2, pushd, rm_rf, run},
 };
 
 pub use anyhow::Result;
@@ -139,7 +139,7 @@ pub fn run_pre_cache() -> Result<()> {
         }
     }
 
-    fs::remove_file("./target/.rustc_info.json")?;
+    fs2::remove_file("./target/.rustc_info.json")?;
     let to_delete = ["ra_", "heavy_test"];
     for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
         for entry in Path::new(dir).read_dir()? {
@@ -153,11 +153,6 @@ pub fn run_pre_cache() -> Result<()> {
     Ok(())
 }
 
-fn rm_rf(path: &Path) -> Result<()> {
-    if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
-        .with_context(|| format!("failed to remove {:?}", path))
-}
-
 pub fn run_release(dry_run: bool) -> Result<()> {
     if !dry_run {
         run!("git switch release")?;
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index 1a7cb7114e9..3e30e7279ff 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -4,7 +4,7 @@ use std::{
     env,
     ffi::OsStr,
     fs,
-    path::PathBuf,
+    path::{Path, PathBuf},
     process::{Command, Stdio},
 };
 
@@ -31,6 +31,16 @@ pub mod fs2 {
         fs::copy(from, to)
             .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display()))
     }
+
+    pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
+        let path = path.as_ref();
+        fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display()))
+    }
+
+    pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
+        let path = path.as_ref();
+        fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
+    }
 }
 
 macro_rules! _run {
@@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> {
     Ok(())
 }
 
+pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
+    let path = path.as_ref();
+    if path.is_file() {
+        fs2::remove_file(path)
+    } else {
+        fs2::remove_dir_all(path)
+    }
+}
+
 pub fn ls(glob: &str) -> Result<Vec<PathBuf>> {
     let cwd = Env::with(|env| env.cwd());
     let mut res = Vec::new();