mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Remove pwd
This commit is contained in:
parent
166c07b28d
commit
ca62f568be
2 changed files with 12 additions and 12 deletions
|
@ -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() };
|
||||
|
|
|
@ -71,10 +71,6 @@ pub fn pushd(path: impl Into<PathBuf>) -> 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<String> {
|
|||
fn run_process_inner(cmd: &str, echo: bool) -> Result<String> {
|
||||
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<String> {
|
|||
|
||||
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<String> {
|
|||
cmd.split_whitespace().map(|it| it.to_string()).collect()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Env {
|
||||
pushd_stack: Vec<PathBuf>,
|
||||
}
|
||||
|
@ -138,19 +134,23 @@ struct Env {
|
|||
impl Env {
|
||||
fn with<F: FnOnce(&mut Env) -> T, T>(f: F) -> T {
|
||||
thread_local! {
|
||||
static ENV: RefCell<Env> = Default::default();
|
||||
static ENV: RefCell<Env> = 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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue