Skip to content

Commit 42f347a

Browse files
committed
Correctly resolve executables in paths on windows
1 parent c473479 commit 42f347a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cargo/util/paths.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs::{self, File, OpenOptions};
44
use std::io;
55
use std::io::prelude::*;
66
use std::path::{Component, Path, PathBuf};
7+
use std::iter;
78

89
use filetime::FileTime;
910

@@ -88,8 +89,16 @@ pub fn without_prefix<'a>(long_path: &'a Path, prefix: &'a Path) -> Option<&'a P
8889
pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
8990
if exec.components().count() == 1 {
9091
let paths = env::var_os("PATH").ok_or(format_err!("no PATH"))?;
91-
for path in env::split_paths(&paths) {
92+
let candidates = env::split_paths(&paths).flat_map(|path| {
9293
let candidate = PathBuf::from(path).join(&exec);
94+
let with_exe = if env::consts::EXE_EXTENSION == "" {
95+
None
96+
} else {
97+
Some(candidate.with_extension(env::consts::EXE_EXTENSION))
98+
};
99+
iter::once(candidate).chain(with_exe)
100+
});
101+
for candidate in candidates {
93102
if candidate.is_file() {
94103
// PATH may have a component like "." in it, so we still need to
95104
// canonicalize.

0 commit comments

Comments
 (0)