mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Better exe probing
This commit is contained in:
parent
b1a4e810a4
commit
f89722f357
1 changed files with 11 additions and 10 deletions
|
@ -46,22 +46,23 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf {
|
||||||
path.push(".cargo");
|
path.push(".cargo");
|
||||||
path.push("bin");
|
path.push("bin");
|
||||||
path.push(executable_name);
|
path.push(executable_name);
|
||||||
if path.is_file() {
|
if let Some(path) = probe(path) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
executable_name.into()
|
executable_name.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_in_path(exec: &str) -> bool {
|
fn lookup_in_path(exec: &str) -> bool {
|
||||||
let paths = env::var_os("PATH").unwrap_or_default();
|
let paths = env::var_os("PATH").unwrap_or_default();
|
||||||
let mut candidates = env::split_paths(&paths).flat_map(|path| {
|
env::split_paths(&paths).map(|path| path.join(exec)).find_map(probe).is_some()
|
||||||
let candidate = path.join(&exec);
|
}
|
||||||
let with_exe = match env::consts::EXE_EXTENSION {
|
|
||||||
"" => None,
|
fn probe(path: PathBuf) -> Option<PathBuf> {
|
||||||
it => Some(candidate.with_extension(it)),
|
let with_extension = match env::consts::EXE_EXTENSION {
|
||||||
};
|
"" => None,
|
||||||
iter::once(candidate).chain(with_exe)
|
it => Some(path.with_extension(it)),
|
||||||
});
|
};
|
||||||
candidates.any(|it| it.is_file())
|
iter::once(path).chain(with_extension).find(|it| it.is_file())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue