about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/run-make-support/src/external_deps/mod.rs5
-rw-r--r--src/tools/run-make-support/src/lib.rs38
-rw-r--r--src/tools/run-make-support/src/path_helpers.rs66
3 files changed, 75 insertions, 34 deletions
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 f4f03aa7efb..bcd7dce0f96 100644
--- a/src/tools/run-make-support/src/external_deps/mod.rs
+++ b/src/tools/run-make-support/src/external_deps/mod.rs
@@ -1,5 +1,10 @@
 //! 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 cc;
 pub mod clang;
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index 5ca15b88530..5ec466af6ce 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -12,6 +12,7 @@ pub mod diff;
 pub mod env_checked;
 pub mod external_deps;
 pub mod fs_wrapper;
+pub mod path_helpers;
 pub mod run;
 pub mod targets;
 
@@ -67,18 +68,10 @@ pub use artifact_names::{
     bin_name, dynamic_lib_extension, dynamic_lib_name, rust_lib_name, static_lib_name,
 };
 
-use command::{Command, CompletedProcess};
-
-/// Returns the path for a local test file.
-pub fn path<P: AsRef<Path>>(p: P) -> PathBuf {
-    cwd().join(p.as_ref())
-}
+/// Path-related helpers.
+pub use path_helpers::{cwd, cygpath_windows, path, source_root};
 
-/// Path to the root rust-lang/rust source checkout.
-#[must_use]
-pub fn source_root() -> PathBuf {
-    env_var("SOURCE_ROOT").into()
-}
+use command::{Command, CompletedProcess};
 
 /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
 #[cfg(target_family = "windows")]
@@ -108,12 +101,6 @@ pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
     ));
 }
 
-/// Return the current working directory.
-#[must_use]
-pub fn cwd() -> PathBuf {
-    std::env::current_dir().unwrap()
-}
-
 // FIXME(Oneirical): This will no longer be required after compiletest receives the ability
 // to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
 /// Ensure that the path P is read-only while the test runs, and restore original permissions
@@ -227,23 +214,6 @@ pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str)
     count
 }
 
-/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
-/// available on the platform!
-#[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()
-}
-
 pub(crate) fn handle_failed_output(
     cmd: &Command,
     output: CompletedProcess,
diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs
new file mode 100644
index 00000000000..59e0cec0be4
--- /dev/null
+++ b/src/tools/run-make-support/src/path_helpers.rs
@@ -0,0 +1,66 @@
+//! Collection of path-related helpers.
+
+use std::panic;
+use std::path::{Path, PathBuf};
+
+use crate::command::Command;
+use crate::env_checked::env_var;
+use crate::handle_failed_output;
+
+/// Return the current working directory.
+///
+/// This forwards to [`std::env::current_dir`], please see its docs regarding platform-specific
+/// behavior.
+#[must_use]
+pub fn cwd() -> PathBuf {
+    std::env::current_dir().unwrap()
+}
+
+/// Construct a `PathBuf` relative to the current working directory by joining `cwd()` with the
+/// relative path. This is mostly a convenience helper so the test writer does not need to write
+/// `PathBuf::from(path_like_string)`.
+///
+/// # Example
+///
+/// ```rust
+/// let p = path("support_file.txt");
+/// ```
+pub fn path<P: AsRef<Path>>(p: P) -> PathBuf {
+    cwd().join(p.as_ref())
+}
+
+/// Path to the root `rust-lang/rust` source checkout.
+#[must_use]
+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()
+}