aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/not_bash.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-05 10:15:55 +0000
committerAleksey Kladov <[email protected]>2020-03-05 10:25:23 +0000
commitca62f568bec128d2eba2032337354e01ebef6858 (patch)
treedae4de49aa1269ade7c7f668a19d5df72899fc57 /xtask/src/not_bash.rs
parent166c07b28d0f5431bb599e067336c332d912e401 (diff)
Remove pwd
Diffstat (limited to 'xtask/src/not_bash.rs')
-rw-r--r--xtask/src/not_bash.rs20
1 files changed, 10 insertions, 10 deletions
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<PathBuf>) -> Pushd {
71 Pushd { _p: () } 71 Pushd { _p: () }
72} 72}
73 73
74pub fn pwd() -> PathBuf {
75 Env::with(|env| env.cwd())
76}
77
78impl Drop for Pushd { 74impl Drop for Pushd {
79 fn drop(&mut self) { 75 fn drop(&mut self) {
80 Env::with(|env| env.popd()) 76 Env::with(|env| env.popd())
@@ -101,6 +97,7 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
101fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { 97fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
102 let mut args = shelx(cmd); 98 let mut args = shelx(cmd);
103 let binary = args.remove(0); 99 let binary = args.remove(0);
100 let current_dir = Env::with(|it| it.cwd().to_path_buf());
104 101
105 if echo { 102 if echo {
106 println!("> {}", cmd) 103 println!("> {}", cmd)
@@ -108,7 +105,7 @@ fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
108 105
109 let output = Command::new(binary) 106 let output = Command::new(binary)
110 .args(args) 107 .args(args)
111 .current_dir(pwd()) 108 .current_dir(current_dir)
112 .stdin(Stdio::null()) 109 .stdin(Stdio::null())
113 .stderr(Stdio::inherit()) 110 .stderr(Stdio::inherit())
114 .output()?; 111 .output()?;
@@ -130,7 +127,6 @@ fn shelx(cmd: &str) -> Vec<String> {
130 cmd.split_whitespace().map(|it| it.to_string()).collect() 127 cmd.split_whitespace().map(|it| it.to_string()).collect()
131} 128}
132 129
133#[derive(Default)]
134struct Env { 130struct Env {
135 pushd_stack: Vec<PathBuf>, 131 pushd_stack: Vec<PathBuf>,
136} 132}
@@ -138,19 +134,23 @@ struct Env {
138impl Env { 134impl Env {
139 fn with<F: FnOnce(&mut Env) -> T, T>(f: F) -> T { 135 fn with<F: FnOnce(&mut Env) -> T, T>(f: F) -> T {
140 thread_local! { 136 thread_local! {
141 static ENV: RefCell<Env> = Default::default(); 137 static ENV: RefCell<Env> = RefCell::new(Env {
138 pushd_stack: vec![env::current_dir().unwrap()]
139 });
142 } 140 }
143 ENV.with(|it| f(&mut *it.borrow_mut())) 141 ENV.with(|it| f(&mut *it.borrow_mut()))
144 } 142 }
145 143
146 fn pushd(&mut self, dir: PathBuf) { 144 fn pushd(&mut self, dir: PathBuf) {
147 let dir = self.cwd().join(dir); 145 let dir = self.cwd().join(dir);
148 self.pushd_stack.push(dir) 146 self.pushd_stack.push(dir);
147 env::set_current_dir(self.cwd()).unwrap();
149 } 148 }
150 fn popd(&mut self) { 149 fn popd(&mut self) {
151 self.pushd_stack.pop().unwrap(); 150 self.pushd_stack.pop().unwrap();
151 env::set_current_dir(self.cwd()).unwrap();
152 } 152 }
153 fn cwd(&self) -> PathBuf { 153 fn cwd(&self) -> &Path {
154 self.pushd_stack.last().cloned().unwrap_or_else(|| env::current_dir().unwrap()) 154 self.pushd_stack.last().unwrap()
155 } 155 }
156} 156}