Skip to content

Commit ee75928

Browse files
bors[bot]matklad
andauthored
Merge #3471
3471: Remove pwd r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 31fd10b + ca62f56 commit ee75928

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

xtask/src/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33
use anyhow::Result;
44

55
use crate::{
6-
not_bash::{fs2, pushd, pwd, rm_rf, run},
6+
not_bash::{fs2, pushd, rm_rf, run},
77
project_root,
88
};
99

@@ -22,7 +22,7 @@ pub fn run_dist(nightly: bool) -> Result<()> {
2222
fn dist_client(nightly: bool) -> Result<()> {
2323
let _d = pushd("./editors/code");
2424

25-
let package_json_path = pwd().join("package.json");
25+
let package_json_path = PathBuf::from("./package.json");
2626
let original_package_json = fs2::read_to_string(&package_json_path)?;
2727
let _restore =
2828
Restore { path: package_json_path.clone(), contents: original_package_json.clone() };

xtask/src/not_bash.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ pub fn pushd(path: impl Into<PathBuf>) -> Pushd {
7171
Pushd { _p: () }
7272
}
7373

74-
pub fn pwd() -> PathBuf {
75-
Env::with(|env| env.cwd())
76-
}
77-
7874
impl Drop for Pushd {
7975
fn drop(&mut self) {
8076
Env::with(|env| env.popd())
@@ -101,14 +97,15 @@ pub fn run_process(cmd: String, echo: bool) -> Result<String> {
10197
fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
10298
let mut args = shelx(cmd);
10399
let binary = args.remove(0);
100+
let current_dir = Env::with(|it| it.cwd().to_path_buf());
104101

105102
if echo {
106103
println!("> {}", cmd)
107104
}
108105

109106
let output = Command::new(binary)
110107
.args(args)
111-
.current_dir(pwd())
108+
.current_dir(current_dir)
112109
.stdin(Stdio::null())
113110
.stderr(Stdio::inherit())
114111
.output()?;
@@ -130,27 +127,30 @@ fn shelx(cmd: &str) -> Vec<String> {
130127
cmd.split_whitespace().map(|it| it.to_string()).collect()
131128
}
132129

133-
#[derive(Default)]
134130
struct Env {
135131
pushd_stack: Vec<PathBuf>,
136132
}
137133

138134
impl Env {
139135
fn with<F: FnOnce(&mut Env) -> T, T>(f: F) -> T {
140136
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+
});
142140
}
143141
ENV.with(|it| f(&mut *it.borrow_mut()))
144142
}
145143

146144
fn pushd(&mut self, dir: PathBuf) {
147145
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();
149148
}
150149
fn popd(&mut self) {
151150
self.pushd_stack.pop().unwrap();
151+
env::set_current_dir(self.cwd()).unwrap();
152152
}
153-
fn cwd(&self) -> PathBuf {
154-
self.pushd_stack.last().cloned().unwrap_or_else(|| env::current_dir().unwrap())
153+
fn cwd(&self) -> &Path {
154+
self.pushd_stack.last().unwrap()
155155
}
156156
}

0 commit comments

Comments
 (0)