From ca62f568bec128d2eba2032337354e01ebef6858 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 5 Mar 2020 11:15:55 +0100 Subject: Remove pwd --- xtask/src/not_bash.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'xtask/src/not_bash.rs') diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs index 1697b7fcd..2d45e5dff 100644 --- a/xtask/src/not_bash.rs +++ b/xtask/src/not_bash.rs @@ -71,10 +71,6 @@ pub fn pushd(path: impl Into) -> Pushd { Pushd { _p: () } } -pub fn pwd() -> PathBuf { - Env::with(|env| env.cwd()) -} - impl Drop for Pushd { fn drop(&mut self) { Env::with(|env| env.popd()) @@ -101,6 +97,7 @@ pub fn run_process(cmd: String, echo: bool) -> Result { fn run_process_inner(cmd: &str, echo: bool) -> Result { let mut args = shelx(cmd); let binary = args.remove(0); + let current_dir = Env::with(|it| it.cwd().to_path_buf()); if echo { println!("> {}", cmd) @@ -108,7 +105,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result { let output = Command::new(binary) .args(args) - .current_dir(pwd()) + .current_dir(current_dir) .stdin(Stdio::null()) .stderr(Stdio::inherit()) .output()?; @@ -130,7 +127,6 @@ fn shelx(cmd: &str) -> Vec { cmd.split_whitespace().map(|it| it.to_string()).collect() } -#[derive(Default)] struct Env { pushd_stack: Vec, } @@ -138,19 +134,23 @@ struct Env { impl Env { fn with T, T>(f: F) -> T { thread_local! { - static ENV: RefCell = Default::default(); + static ENV: RefCell = RefCell::new(Env { + pushd_stack: vec![env::current_dir().unwrap()] + }); } ENV.with(|it| f(&mut *it.borrow_mut())) } fn pushd(&mut self, dir: PathBuf) { let dir = self.cwd().join(dir); - self.pushd_stack.push(dir) + self.pushd_stack.push(dir); + env::set_current_dir(self.cwd()).unwrap(); } fn popd(&mut self) { self.pushd_stack.pop().unwrap(); + env::set_current_dir(self.cwd()).unwrap(); } - fn cwd(&self) -> PathBuf { - self.pushd_stack.last().cloned().unwrap_or_else(|| env::current_dir().unwrap()) + fn cwd(&self) -> &Path { + self.pushd_stack.last().unwrap() } } -- cgit v1.2.3