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 bbf60c8 + e861f93 commit bbd0e9f
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/tools/run-make-support/src/external_deps/cygpath.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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 @@ -21,15 +17,7 @@ use crate::util::handle_failed_output;
/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*.
#[track_caller]
#[must_use]
// FIXME: If try job succeeds, remove this function entirely.
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());
}
// cygpath -w can attach a newline
output.stdout_utf8().trim().to_string()
path.as_ref().to_str().unwrap().into()
}

0 comments on commit bbd0e9f

Please sign in to comment.