Skip to content

Commit 5acb467

Browse files
committed
Move rm_rf to not-bash
1 parent cd956a1 commit 5acb467

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

xtask/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ mod ast_src;
99

1010
use anyhow::Context;
1111
use std::{
12-
env, fs,
12+
env,
1313
io::Write,
1414
path::{Path, PathBuf},
1515
process::{Command, Stdio},
1616
};
1717

1818
use crate::{
1919
codegen::Mode,
20-
not_bash::{fs2, pushd, run},
20+
not_bash::{fs2, pushd, rm_rf, run},
2121
};
2222

2323
pub use anyhow::Result;
@@ -139,7 +139,7 @@ pub fn run_pre_cache() -> Result<()> {
139139
}
140140
}
141141

142-
fs::remove_file("./target/.rustc_info.json")?;
142+
fs2::remove_file("./target/.rustc_info.json")?;
143143
let to_delete = ["ra_", "heavy_test"];
144144
for &dir in ["./target/debug/deps", "target/debug/.fingerprint"].iter() {
145145
for entry in Path::new(dir).read_dir()? {
@@ -153,11 +153,6 @@ pub fn run_pre_cache() -> Result<()> {
153153
Ok(())
154154
}
155155

156-
fn 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-
161156
pub fn run_release(dry_run: bool) -> Result<()> {
162157
if !dry_run {
163158
run!("git switch release")?;

xtask/src/not_bash.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
env,
55
ffi::OsStr,
66
fs,
7-
path::PathBuf,
7+
path::{Path, PathBuf},
88
process::{Command, Stdio},
99
};
1010

@@ -31,6 +31,16 @@ pub mod fs2 {
3131
fs::copy(from, to)
3232
.with_context(|| format!("Failed to copy {} to {}", from.display(), to.display()))
3333
}
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+
}
3444
}
3545

3646
macro_rules! _run {
@@ -64,6 +74,15 @@ pub fn rm(glob: &str) -> Result<()> {
6474
Ok(())
6575
}
6676

77+
pub 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+
6786
pub fn ls(glob: &str) -> Result<Vec<PathBuf>> {
6887
let cwd = Env::with(|env| env.cwd());
6988
let mut res = Vec::new();

0 commit comments

Comments
 (0)