diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-27 01:05:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-27 01:05:02 +0100 |
commit | 9a4d02faf9c47f401b8756c3f7fcab2198f5f9cd (patch) | |
tree | 690249f8406f074866604ffa98045e5f476e83d5 | |
parent | b1a4e810a4909c36eabf6f4b746a021c2074c2c3 (diff) | |
parent | f89722f3571bcdcd7f5e9b6d22d4d8d82dffc332 (diff) |
Merge #5088
5088: Better exe probing r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_toolchain/src/lib.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_toolchain/src/lib.rs b/crates/ra_toolchain/src/lib.rs index 9532fb255..9916e52c4 100644 --- a/crates/ra_toolchain/src/lib.rs +++ b/crates/ra_toolchain/src/lib.rs | |||
@@ -46,22 +46,23 @@ fn get_path_for_executable(executable_name: &'static str) -> PathBuf { | |||
46 | path.push(".cargo"); | 46 | path.push(".cargo"); |
47 | path.push("bin"); | 47 | path.push("bin"); |
48 | path.push(executable_name); | 48 | path.push(executable_name); |
49 | if path.is_file() { | 49 | if let Some(path) = probe(path) { |
50 | return path; | 50 | return path; |
51 | } | 51 | } |
52 | } | 52 | } |
53 | |||
53 | executable_name.into() | 54 | executable_name.into() |
54 | } | 55 | } |
55 | 56 | ||
56 | fn lookup_in_path(exec: &str) -> bool { | 57 | fn lookup_in_path(exec: &str) -> bool { |
57 | let paths = env::var_os("PATH").unwrap_or_default(); | 58 | let paths = env::var_os("PATH").unwrap_or_default(); |
58 | let mut candidates = env::split_paths(&paths).flat_map(|path| { | 59 | env::split_paths(&paths).map(|path| path.join(exec)).find_map(probe).is_some() |
59 | let candidate = path.join(&exec); | 60 | } |
60 | let with_exe = match env::consts::EXE_EXTENSION { | 61 | |
61 | "" => None, | 62 | fn probe(path: PathBuf) -> Option<PathBuf> { |
62 | it => Some(candidate.with_extension(it)), | 63 | let with_extension = match env::consts::EXE_EXTENSION { |
63 | }; | 64 | "" => None, |
64 | iter::once(candidate).chain(with_exe) | 65 | it => Some(path.with_extension(it)), |
65 | }); | 66 | }; |
66 | candidates.any(|it| it.is_file()) | 67 | iter::once(path).chain(with_extension).find(|it| it.is_file()) |
67 | } | 68 | } |