aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--xtask/Cargo.toml1
-rw-r--r--xtask/src/dist.rs2
-rw-r--r--xtask/src/not_bash.rs47
4 files changed, 12 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 867a6c1dc..cec4462f2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -386,6 +386,12 @@ dependencies = [
386] 386]
387 387
388[[package]] 388[[package]]
389name = "fs-err"
390version = "2.3.0"
391source = "registry+https://github.com/rust-lang/crates.io-index"
392checksum = "c1a51f8b7158efbe531f7baa74e38e49fbc41239e5d66720bb37ed39c27c241a"
393
394[[package]]
389name = "fsevent" 395name = "fsevent"
390version = "2.0.2" 396version = "2.0.2"
391source = "registry+https://github.com/rust-lang/crates.io-index" 397source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1875,6 +1881,7 @@ version = "0.1.0"
1875dependencies = [ 1881dependencies = [
1876 "anyhow", 1882 "anyhow",
1877 "flate2", 1883 "flate2",
1884 "fs-err",
1878 "pico-args", 1885 "pico-args",
1879 "proc-macro2", 1886 "proc-macro2",
1880 "quote", 1887 "quote",
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 0750b5657..01a838825 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -18,4 +18,5 @@ quote = "1.0.2"
18ungrammar = "1.1.3" 18ungrammar = "1.1.3"
19walkdir = "2.3.1" 19walkdir = "2.3.1"
20write-json = "0.1.0" 20write-json = "0.1.0"
21fs-err = "2.3"
21# Avoid adding more dependencies to this crate 22# Avoid adding more dependencies to this crate
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index 01d903cde..aa7d94967 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -115,7 +115,7 @@ impl Patch {
115 self 115 self
116 } 116 }
117 117
118 fn commit(&self) -> Result<()> { 118 fn commit(&self) -> io::Result<()> {
119 fs2::write(&self.path, &self.contents) 119 fs2::write(&self.path, &self.contents)
120 } 120 }
121} 121}
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index ef811e5bf..038898993 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -4,55 +4,14 @@ use std::{
4 cell::RefCell, 4 cell::RefCell,
5 env, 5 env,
6 ffi::OsString, 6 ffi::OsString,
7 io::Write, 7 io::{self, Write},
8 path::{Path, PathBuf}, 8 path::{Path, PathBuf},
9 process::{Command, Stdio}, 9 process::{Command, Stdio},
10}; 10};
11 11
12use anyhow::{bail, Context, Result}; 12use anyhow::{bail, Context, Result};
13 13
14pub mod fs2 { 14pub use fs_err as fs2;
15 use std::{fs, path::Path};
16
17 use anyhow::{Context, Result};
18
19 pub fn read_dir<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir> {
20 let path = path.as_ref();
21 fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display()))
22 }
23
24 pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
25 let path = path.as_ref();
26 fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))
27 }
28
29 pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
30 let path = path.as_ref();
31 fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display()))
32 }
33
34 pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
35 let from = from.as_ref();
36 let to = to.as_ref();
37 fs::copy(from, to)
38 .with_context(|| format!("Failed to copy {} to {}", from.display(), to.display()))
39 }
40
41 pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
42 let path = path.as_ref();
43 fs::remove_file(path).with_context(|| format!("Failed to remove file {}", path.display()))
44 }
45
46 pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
47 let path = path.as_ref();
48 fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
49 }
50
51 pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
52 let path = path.as_ref();
53 fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display()))
54 }
55}
56 15
57#[macro_export] 16#[macro_export]
58macro_rules! run { 17macro_rules! run {
@@ -98,7 +57,7 @@ impl Drop for Pushenv {
98 } 57 }
99} 58}
100 59
101pub fn rm_rf(path: impl AsRef<Path>) -> Result<()> { 60pub fn rm_rf(path: impl AsRef<Path>) -> io::Result<()> {
102 let path = path.as_ref(); 61 let path = path.as_ref();
103 if !path.exists() { 62 if !path.exists() {
104 return Ok(()); 63 return Ok(());