run_make_support: rename cygpath_windows to get_windows_path and move under external_deps as private

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-07-17 11:23:29 +00:00
parent a443dc4ecd
commit 13a1751061
5 changed files with 45 additions and 42 deletions

View File

@ -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 {

View File

@ -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<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()
}

View File

@ -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;

View File

@ -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};

View File

@ -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: AsRef<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<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()
}