Skip to content

Commit ab4ca48

Browse files
committed
Auto merge of #128611 - ChrisDenton:cygpath, r=<try>
run-make: Only use cygpath if the path looks unixy `cygpath -w` can mangle paths that are already Windows paths. Therefore only use it if the path looks like a Unix path. Additionally fallback to using the path as given if `cygpath` fails on the assumption that the path is already good or else will be an error when it's actually used. Tbh, I'm not entirely convinced that `cygpath` is necessary but if it is used then it shouldn't get in the way of using Windows paths. try-job: x86_64-msvc try-job: i686-msvc try-job: i686-mingw try-job: x86_64-mingw
2 parents 1f47624 + 1ae5da1 commit ab4ca48

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)