Skip to content

Commit 13a1751

Browse files
committed
run_make_support: rename cygpath_windows to get_windows_path and move under external_deps as private
1 parent a443dc4 commit 13a1751

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

src/tools/run-make-support/src/external_deps/cc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::path::Path;
22

33
use crate::command::Command;
4-
use crate::{cygpath_windows, env_var, is_msvc, is_windows, uname};
4+
use crate::{env_var, is_msvc, is_windows, uname};
5+
6+
// FIXME(jieyouxu): can we get rid of the `cygpath` external dependency?
7+
use super::cygpath::get_windows_path;
58

69
/// Construct a new platform-specific C compiler invocation.
710
///
@@ -72,10 +75,10 @@ impl Cc {
7275

7376
if is_msvc() {
7477
path.set_extension("exe");
75-
let fe_path = cygpath_windows(&path);
78+
let fe_path = get_windows_path(&path);
7679
path.set_extension("");
7780
path.set_extension("obj");
78-
let fo_path = cygpath_windows(path);
81+
let fo_path = get_windows_path(path);
7982
self.cmd.arg(format!("-Fe:{fe_path}"));
8083
self.cmd.arg(format!("-Fo:{fo_path}"));
8184
} else {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::panic;
2+
use std::path::Path;
3+
4+
use crate::command::Command;
5+
use crate::util::handle_failed_output;
6+
7+
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
8+
/// available on the platform!
9+
///
10+
/// # FIXME
11+
///
12+
/// FIXME(jieyouxu): we should consider not depending on `cygpath`.
13+
///
14+
/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style
15+
/// > pathnames and vice versa.
16+
/// >
17+
/// > [irrelevant entries omitted...]
18+
/// >
19+
/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)`
20+
/// >
21+
/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*.
22+
#[track_caller]
23+
#[must_use]
24+
pub fn get_windows_path<P: AsRef<Path>>(path: P) -> String {
25+
let caller = panic::Location::caller();
26+
let mut cygpath = Command::new("cygpath");
27+
cygpath.arg("-w");
28+
cygpath.arg(path.as_ref());
29+
let output = cygpath.run();
30+
if !output.status().success() {
31+
handle_failed_output(&cygpath, output, caller.line());
32+
}
33+
// cygpath -w can attach a newline
34+
output.stdout_utf8().trim().to_string()
35+
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//! This module contains external tool dependencies that we assume are available in the environment,
22
//! such as `cc` or `python`.
3-
//!
4-
//! # Notes
5-
//!
6-
//! - This is not the *only* place where external dependencies are assumed or referenced. For
7-
//! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows].
83
94
pub mod c_build;
105
pub mod cc;
@@ -14,3 +9,6 @@ pub mod llvm;
149
pub mod python;
1510
pub mod rustc;
1611
pub mod rustdoc;
12+
13+
// Library-internal external dependency.
14+
mod cygpath;

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use artifact_names::{
6262
};
6363

6464
/// Path-related helpers.
65-
pub use path_helpers::{cwd, cygpath_windows, path, source_root};
65+
pub use path_helpers::{cwd, path, source_root};
6666

6767
/// Helpers for common fs operations.
6868
pub use fs_helpers::{copy_dir_all, create_symlink, read_dir};
Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
//! Collection of path-related helpers.
22
3-
use std::panic;
43
use std::path::{Path, PathBuf};
54

6-
use crate::command::Command;
75
use crate::env::env_var;
8-
use crate::util::handle_failed_output;
96

107
/// Return the current working directory.
118
///
@@ -34,33 +31,3 @@ pub fn path<P: AsRef<Path>>(p: P) -> PathBuf {
3431
pub fn source_root() -> PathBuf {
3532
env_var("SOURCE_ROOT").into()
3633
}
37-
38-
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
39-
/// available on the platform!
40-
///
41-
/// # FIXME
42-
///
43-
/// FIXME(jieyouxu): we should consider not depending on `cygpath`.
44-
///
45-
/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style
46-
/// > pathnames and vice versa.
47-
/// >
48-
/// > [irrelevant entries omitted...]
49-
/// >
50-
/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)`
51-
/// >
52-
/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*.
53-
#[track_caller]
54-
#[must_use]
55-
pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
56-
let caller = panic::Location::caller();
57-
let mut cygpath = Command::new("cygpath");
58-
cygpath.arg("-w");
59-
cygpath.arg(path.as_ref());
60-
let output = cygpath.run();
61-
if !output.status().success() {
62-
handle_failed_output(&cygpath, output, caller.line());
63-
}
64-
// cygpath -w can attach a newline
65-
output.stdout_utf8().trim().to_string()
66-
}

0 commit comments

Comments
 (0)