aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/dist.rs4
-rw-r--r--xtask/src/not_bash.rs20
2 files changed, 12 insertions, 12 deletions
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;
3use anyhow::Result; 3use anyhow::Result;
4 4
5use crate::{ 5use crate::{
6 not_bash::{fs2, pushd, pwd, rm_rf, run}, 6 not_bash::{fs2, pushd, rm_rf, run},
7 project_root, 7 project_root,
8}; 8};
9 9
@@ -22,7 +22,7 @@ pub fn run_dist(nightly: bool) -> Result<()> {
22fn dist_client(nightly: bool) -> Result<()> { 22fn dist_client(nightly: bool) -> Result<()> {
23 let _d = pushd("./editors/code"); 23 let _d = pushd("./editors/code");
24 24
25 let package_json_path = pwd().join("package.json"); 25 let package_json_path = PathBuf::from("./package.json");
26 let original_package_json = fs2::read_to_string(&package_json_path)?; 26 let original_package_json = fs2::read_to_string(&package_json_path)?;
27 let _restore = 27 let _restore =
28 Restore { path: package_json_path.clone(), contents: original_package_json.clone() }; 28 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<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}