Skip to content

Commit

Permalink
Auto merge of #128611 - ChrisDenton:cygpath, r=<try>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 3, 2024
2 parents 1f47624 + 1ae5da1 commit ab4ca48
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/tools/run-make-support/src/external_deps/cygpath.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::panic;
use std::path::Path;

use crate::command::Command;
use crate::util::handle_failed_output;

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

0 comments on commit ab4ca48

Please sign in to comment.