aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/not_bash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r--xtask/src/not_bash.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index 40f706d9f..1697b7fcd 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -19,6 +19,11 @@ pub mod fs2 {
19 fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display())) 19 fs::read_dir(path).with_context(|| format!("Failed to read {}", path.display()))
20 } 20 }
21 21
22 pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
23 let path = path.as_ref();
24 fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))
25 }
26
22 pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> { 27 pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
23 let path = path.as_ref(); 28 let path = path.as_ref();
24 fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display())) 29 fs::write(path, contents).with_context(|| format!("Failed to write {}", path.display()))
@@ -40,6 +45,11 @@ pub mod fs2 {
40 let path = path.as_ref(); 45 let path = path.as_ref();
41 fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display())) 46 fs::remove_dir_all(path).with_context(|| format!("Failed to remove dir {}", path.display()))
42 } 47 }
48
49 pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
50 let path = path.as_ref();
51 fs::create_dir_all(path).with_context(|| format!("Failed to create dir {}", path.display()))
52 }
43} 53}
44 54
45macro_rules! _run { 55macro_rules! _run {
@@ -61,6 +71,10 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd {
61 Pushd { _p: () } 71 Pushd { _p: () }
62} 72}
63 73
74pub fn pwd() -> PathBuf {
75 Env::with(|env| env.cwd())
76}
77
64impl Drop for Pushd { 78impl Drop for Pushd {
65 fn drop(&mut self) { 79 fn drop(&mut self) {
66 Env::with(|env| env.popd()) 80 Env::with(|env| env.popd())
@@ -85,7 +99,6 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
85} 99}
86 100
87fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { 101fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
88 let cwd = Env::with(|env| env.cwd());
89 let mut args = shelx(cmd); 102 let mut args = shelx(cmd);
90 let binary = args.remove(0); 103 let binary = args.remove(0);
91 104
@@ -95,7 +108,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
95 108
96 let output = Command::new(binary) 109 let output = Command::new(binary)
97 .args(args) 110 .args(args)
98 .current_dir(cwd) 111 .current_dir(pwd())
99 .stdin(Stdio::null()) 112 .stdin(Stdio::null())
100 .stderr(Stdio::inherit()) 113 .stderr(Stdio::inherit())
101 .output()?; 114 .output()?;