run_make_support: rename cygpath_windows
to get_windows_path
and move under external_deps
as private
This commit is contained in:
parent
a443dc4ecd
commit
13a1751061
5 changed files with 45 additions and 42 deletions
|
@ -1,7 +1,10 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::command::Command;
|
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.
|
/// Construct a new platform-specific C compiler invocation.
|
||||||
///
|
///
|
||||||
|
@ -72,10 +75,10 @@ impl Cc {
|
||||||
|
|
||||||
if is_msvc() {
|
if is_msvc() {
|
||||||
path.set_extension("exe");
|
path.set_extension("exe");
|
||||||
let fe_path = cygpath_windows(&path);
|
let fe_path = get_windows_path(&path);
|
||||||
path.set_extension("");
|
path.set_extension("");
|
||||||
path.set_extension("obj");
|
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!("-Fe:{fe_path}"));
|
||||||
self.cmd.arg(format!("-Fo:{fo_path}"));
|
self.cmd.arg(format!("-Fo:{fo_path}"));
|
||||||
} else {
|
} else {
|
||||||
|
|
35
src/tools/run-make-support/src/external_deps/cygpath.rs
Normal file
35
src/tools/run-make-support/src/external_deps/cygpath.rs
Normal 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()
|
||||||
|
}
|
|
@ -1,10 +1,5 @@
|
||||||
//! This module contains external tool dependencies that we assume are available in the environment,
|
//! This module contains external tool dependencies that we assume are available in the environment,
|
||||||
//! such as `cc` or `python`.
|
//! 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 c_build;
|
||||||
pub mod cc;
|
pub mod cc;
|
||||||
|
@ -14,3 +9,6 @@ pub mod llvm;
|
||||||
pub mod python;
|
pub mod python;
|
||||||
pub mod rustc;
|
pub mod rustc;
|
||||||
pub mod rustdoc;
|
pub mod rustdoc;
|
||||||
|
|
||||||
|
// Library-internal external dependency.
|
||||||
|
mod cygpath;
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub use artifact_names::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Path-related helpers.
|
/// 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.
|
/// Helpers for common fs operations.
|
||||||
pub use fs_helpers::{copy_dir_all, create_symlink, read_dir};
|
pub use fs_helpers::{copy_dir_all, create_symlink, read_dir};
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
//! Collection of path-related helpers.
|
//! Collection of path-related helpers.
|
||||||
|
|
||||||
use std::panic;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::command::Command;
|
|
||||||
use crate::env::env_var;
|
use crate::env::env_var;
|
||||||
use crate::util::handle_failed_output;
|
|
||||||
|
|
||||||
/// Return the current working directory.
|
/// Return the current working directory.
|
||||||
///
|
///
|
||||||
|
@ -34,33 +31,3 @@ pub fn path<P: AsRef<Path>>(p: P) -> PathBuf {
|
||||||
pub fn source_root() -> PathBuf {
|
pub fn source_root() -> PathBuf {
|
||||||
env_var("SOURCE_ROOT").into()
|
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()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue