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/dist.rs | 4 ++-- xtask/src/not_bash.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index e1126602a..821ba041b 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use anyhow::Result; use crate::{ - not_bash::{fs2, pushd, pwd, rm_rf, run}, + not_bash::{fs2, pushd, rm_rf, run}, project_root, }; @@ -22,7 +22,7 @@ pub fn run_dist(nightly: bool) -> Result<()> { fn dist_client(nightly: bool) -> Result<()> { let _d = pushd("./editors/code"); - let package_json_path = pwd().join("package.json"); + let package_json_path = PathBuf::from("./package.json"); let original_package_json = fs2::read_to_string(&package_json_path)?; let _restore = Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; 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