Skip to content

Commit 1ae5da1

Browse files
committed
run-make: Only use cygpath if the path looks unixy
1 parent 1f47624 commit 1ae5da1

File tree

1 file changed

+14
-11
lines changed
  • src/tools/run-make-support/src/external_deps

1 file changed

+14
-11
lines changed

src/tools/run-make-support/src/external_deps/cygpath.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::panic;
21
use std::path::Path;
32

43
use crate::command::Command;
5-
use crate::util::handle_failed_output;
64

75
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
86
/// available on the platform!
@@ -22,14 +20,19 @@ use crate::util::handle_failed_output;
2220
#[track_caller]
2321
#[must_use]
2422
pub fn get_windows_path<P: AsRef<Path>>(path: P) -> String {
25-
let caller = panic::Location::caller();
26-
let mut cygpath = Command::new("cygpath");
27-
cygpath.arg("-w");
28-
cygpath.arg(path.as_ref());
29-
let output = cygpath.run();
30-
if !output.status().success() {
31-
handle_failed_output(&cygpath, output, caller.line());
23+
// If the path looks unixy then use cygpath otherwise return it unchanged.
24+
// If cygpath fails then fallback to just using the path as given.
25+
if path.as_ref().starts_with("/") {
26+
let mut cygpath = Command::new("cygpath");
27+
cygpath.arg("-w");
28+
cygpath.arg(path.as_ref());
29+
let output = cygpath.run();
30+
if !output.status().success() {
31+
return path.as_ref().to_str().unwrap().into();
32+
}
33+
// cygpath -w can attach a newline
34+
output.stdout_utf8().trim().to_string()
35+
} else {
36+
path.as_ref().to_str().unwrap().into()
3237
}
33-
// cygpath -w can attach a newline
34-
output.stdout_utf8().trim().to_string()
3538
}

0 commit comments

Comments
 (0)