diff --git a/src/tools/run-make-support/src/external_deps/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs index 677790b0aa9..840bfa0d2b4 100644 --- a/src/tools/run-make-support/src/external_deps/cc.rs +++ b/src/tools/run-make-support/src/external_deps/cc.rs @@ -1,7 +1,10 @@ use std::path::Path; use crate::command::Command; -use crate::{cygpath_windows, env_var, is_msvc, is_windows, uname}; +use crate::{env_var, is_msvc, is_windows, uname}; + +// FIXME(jieyouxu): can we get rid of the `cygpath` external dependency? +use super::cygpath::get_windows_path; /// Construct a new platform-specific C compiler invocation. /// @@ -72,10 +75,10 @@ pub fn out_exe(&mut self, name: &str) -> &mut Self { if is_msvc() { path.set_extension("exe"); - let fe_path = cygpath_windows(&path); + let fe_path = get_windows_path(&path); path.set_extension(""); path.set_extension("obj"); - let fo_path = cygpath_windows(path); + let fo_path = get_windows_path(path); self.cmd.arg(format!("-Fe:{fe_path}")); self.cmd.arg(format!("-Fo:{fo_path}")); } else { diff --git a/src/tools/run-make-support/src/external_deps/cygpath.rs b/src/tools/run-make-support/src/external_deps/cygpath.rs new file mode 100644 index 00000000000..07d8e840a63 --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/cygpath.rs @@ -0,0 +1,35 @@ +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! +/// +/// # FIXME +/// +/// FIXME(jieyouxu): we should consider not depending on `cygpath`. +/// +/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style +/// > pathnames and vice versa. +/// > +/// > [irrelevant entries omitted...] +/// > +/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)` +/// > +/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*. +#[track_caller] +#[must_use] +pub fn get_windows_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() +} diff --git a/src/tools/run-make-support/src/external_deps/mod.rs b/src/tools/run-make-support/src/external_deps/mod.rs index 13020b51563..a2dc426f3f2 100644 --- a/src/tools/run-make-support/src/external_deps/mod.rs +++ b/src/tools/run-make-support/src/external_deps/mod.rs @@ -1,10 +1,5 @@ //! This module contains external tool dependencies that we assume are available in the environment, //! such as `cc` or `python`. -//! -//! # Notes -//! -//! - This is not the *only* place where external dependencies are assumed or referenced. For -//! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows]. pub mod c_build; pub mod cc; @@ -14,3 +9,6 @@ pub mod python; pub mod rustc; pub mod rustdoc; + +// Library-internal external dependency. +mod cygpath; diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 38070f79edc..5416a6920a5 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -62,7 +62,7 @@ }; /// Path-related helpers. -pub use path_helpers::{cwd, cygpath_windows, path, source_root}; +pub use path_helpers::{cwd, path, source_root}; /// Helpers for common fs operations. pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index f46368b53f8..b29d8727d2b 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -1,11 +1,8 @@ //! Collection of path-related helpers. -use std::panic; use std::path::{Path, PathBuf}; -use crate::command::Command; use crate::env::env_var; -use crate::util::handle_failed_output; /// Return the current working directory. /// @@ -34,33 +31,3 @@ pub fn path>(p: P) -> PathBuf { pub fn source_root() -> PathBuf { env_var("SOURCE_ROOT").into() } - -/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is -/// available on the platform! -/// -/// # FIXME -/// -/// FIXME(jieyouxu): we should consider not depending on `cygpath`. -/// -/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style -/// > pathnames and vice versa. -/// > -/// > [irrelevant entries omitted...] -/// > -/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)` -/// > -/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*. -#[track_caller] -#[must_use] -pub fn cygpath_windows>(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() -}