Skip to content

Commit

Permalink
run-make: Only use cygpath if the path looks unixy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Aug 3, 2024
1 parent 1f47624 commit 1ae5da1
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 1ae5da1

Please sign in to comment.