diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-05 10:29:59 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-05 10:29:59 +0000 |
commit | ee75928855ba0b969376de9a13232895df24066b (patch) | |
tree | ebf6c4374e224174ad13134809e2d800e13272ac /xtask | |
parent | 31fd10b2a5fe11476e7f4a21b0f0955ea934e3a6 (diff) | |
parent | ca62f568bec128d2eba2032337354e01ebef6858 (diff) |
Merge #3471
3471: Remove pwd r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/dist.rs | 4 | ||||
-rw-r--r-- | xtask/src/not_bash.rs | 20 |
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; | |||
3 | use anyhow::Result; | 3 | use anyhow::Result; |
4 | 4 | ||
5 | use crate::{ | 5 | use 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<()> { | |||
22 | fn dist_client(nightly: bool) -> Result<()> { | 22 | fn 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 | ||
74 | pub fn pwd() -> PathBuf { | ||
75 | Env::with(|env| env.cwd()) | ||
76 | } | ||
77 | |||
78 | impl Drop for Pushd { | 74 | impl 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> { | |||
101 | fn run_process_inner(cmd: &str, echo: bool) -> Result<String> { | 97 | fn 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)] | ||
134 | struct Env { | 130 | struct Env { |
135 | pushd_stack: Vec<PathBuf>, | 131 | pushd_stack: Vec<PathBuf>, |
136 | } | 132 | } |
@@ -138,19 +134,23 @@ struct Env { | |||
138 | impl Env { | 134 | impl 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 | } |