aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-14 18:03:45 +0000
committerAleksey Kladov <[email protected]>2020-02-14 18:03:45 +0000
commit5acb467894053cb0342eb6ded4d162b4a6912483 (patch)
treeca367a3b7a23f96d2149f3f14b908f099c48dc9e
parentcd956a191f8cb32573be7a78139ad322051e949e (diff)
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 cebb14abc..25b64301c 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -9,7 +9,7 @@ mod ast_src;
9 9
10use anyhow::Context; 10use anyhow::Context;
11use std::{ 11use std::{
12 env, fs, 12 env,
13 io::Write, 13 io::Write,
14 path::{Path, PathBuf}, 14 path::{Path, PathBuf},
15 process::{Command, Stdio}, 15 process::{Command, Stdio},
@@ -17,7 +17,7 @@ use std::{
17 17
18use crate::{ 18use crate::{
19 codegen::Mode, 19 codegen::Mode,
20 not_bash::{fs2, pushd, run}, 20 not_bash::{fs2, pushd, rm_rf, run},
21}; 21};
22 22
23pub use anyhow::Result; 23pub use anyhow::Result;
@@ -139,7 +139,7 @@ pub fn run_pre_cache() -> Result<()> {
139 } 139 }
140 } 140 }
141 141
142 fs::remove_file("./target/.rustc_info.json")?; 142 fs2::remove_file("./target/.rustc_info.json")?;
143 let to_delete = ["ra_", "heavy_test"]; 143 let to_delete = ["ra_", "heavy_test"];
144 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() { 144 for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
145 for entry in Path::new(dir).read_dir()? { 145 for entry in Path::new(dir).read_dir()? {
@@ -153,11 +153,6 @@ pub fn run_pre_cache() -> Result<()> {
153 Ok(()) 153 Ok(())
154} 154}
155 155
156fn rm_rf(path: &Path) -> Result<()> {
157 if path.is_file() { fs::remove_file(path) } else { fs::remove_dir_all(path) }
158 .with_context(|| format!("failed to remove {:?}", path))
159}
160
161pub fn run_release(dry_run: bool) -> Result<()> { 156pub fn run_release(dry_run: bool) -> Result<()> {
162 if !dry_run { 157 if !dry_run {
163 run!("git switch release")?; 158 run!("git switch release")?;
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index 1a7cb7114..3e30e7279 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -4,7 +4,7 @@ use std::{
4 env, 4 env,
5 ffi::OsStr, 5 ffi::OsStr,
6 fs, 6 fs,
7 path::PathBuf, 7 path::{Path, PathBuf},
8 process::{Command, Stdio}, 8 process::{Command, Stdio},
9}; 9};
10 10
@@ -31,6 +31,16 @@ pub mod fs2 {
31 fs::copy(from, to) 31 fs::copy(from, to)
32 .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display())) 32 .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display()))
33 } 33 }
34
35 pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
36 let path = path.as_ref();
37 fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display()))
38 }
39
40 pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
41 let path = path.as_ref();
42 fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
43 }
34} 44}
35 45
36macro_rules! _run { 46macro_rules! _run {
@@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> {
64 Ok(()) 74 Ok(())
65} 75}
66 76
77pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> {
78 let path = path.as_ref();
79 if path.is_file() {
80 fs2::remove_file(path)
81 } else {
82 fs2::remove_dir_all(path)
83 }
84}
85
67pub fn ls(glob: &str) -> Result<Vec<PathBuf>> { 86pub fn ls(glob: &str) -> Result<Vec<PathBuf>> {
68 let cwd = Env::with(|env| env.cwd()); 87 let cwd = Env::with(|env| env.cwd());
69 let mut res = Vec::new(); 88 let mut res = Vec::new();