mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Check for both path separators on windows
This commit is contained in:
parent
a8ec77dc7e
commit
b3ebc9ab6a
@ -2000,8 +2000,18 @@ fn run_rustfmt(
|
|||||||
let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
|
let workspace = CargoTargetSpec::for_file(&snap, file_id)?;
|
||||||
let mut cmd = match workspace {
|
let mut cmd = match workspace {
|
||||||
Some(spec) => {
|
Some(spec) => {
|
||||||
let cmd = spec.workspace_root.join(cmd);
|
// approach: if the command name contains a path seperator, join it with the workspace root.
|
||||||
process::Command::new(cmd.as_os_str())
|
// however, if the path is absolute, joining will result in the absolute path being preserved.
|
||||||
|
// as a fallback, rely on $PATH-based discovery.
|
||||||
|
let cmd_path =
|
||||||
|
if cfg!(windows) && command.contains(&[std::path::MAIN_SEPARATOR, '/']) {
|
||||||
|
spec.workspace_root.join(cmd).into()
|
||||||
|
} else if command.contains(std::path::MAIN_SEPARATOR) {
|
||||||
|
spec.workspace_root.join(cmd).into()
|
||||||
|
} else {
|
||||||
|
cmd
|
||||||
|
};
|
||||||
|
process::Command::new(cmd_path)
|
||||||
}
|
}
|
||||||
None => process::Command::new(cmd),
|
None => process::Command::new(cmd),
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user