about summary refs log tree commit diff
path: root/src/bootstrap/lib.rs
diff options
context:
space:
mode:
authorjyn <github@jyn.dev>2023-07-13 02:12:57 -0500
committerjyn <github@jyn.dev>2023-07-15 12:27:53 -0500
commit63d7992353b7250e150a377d1ca499e869de55f7 (patch)
treecb05c1c223aed096c0b7f19e626c6e33e7a53aa8 /src/bootstrap/lib.rs
parent4d6e4260b2de66a356a2536320f339467dff0d2b (diff)
downloadrust-63d7992353b7250e150a377d1ca499e869de55f7.tar.gz
rust-63d7992353b7250e150a377d1ca499e869de55f7.zip
Deduplicate `Builder::try_run` and mark `Config::try_run` as deprecated
This does three things:
1. Remove `forward!(Build, fn try_run())`. Having `try_run` behave differently as a free function than an associated function is confusing, and `Builder::try_run` is a very desirable name.
2. Move `test::try_run` and `run::try_run` to `Builder::try_run`. These functions are different than `Config::try_run` - they delay the failure and print it out at the end of the build.
3. Mark `Config::try_run` as deprecated to encourage people to use `Builder::try_run` instead.
Diffstat (limited to 'src/bootstrap/lib.rs')
-rw-r--r--src/bootstrap/lib.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 32b66973567..7c53d1a92f7 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -333,7 +333,6 @@ forward! {
     create(path: &Path, s: &str),
     remove(f: &Path),
     tempdir() -> PathBuf,
-    try_run(cmd: &mut Command) -> Result<(), ()>,
     llvm_link_shared() -> bool,
     download_rustc() -> bool,
     initial_rustfmt() -> Option<PathBuf>,
@@ -617,7 +616,9 @@ impl Build {
         }
 
         // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error).
+        #[allow(deprecated)] // diff-index reports the modifications through the exit status
         let has_local_modifications = self
+            .config
             .try_run(
                 Command::new("git")
                     .args(&["diff-index", "--quiet", "HEAD"])
@@ -979,6 +980,21 @@ impl Build {
         try_run_suppressed(cmd)
     }
 
+    /// Runs a command, printing out contextual info if it fails, and delaying errors until the build finishes.
+    pub(crate) fn try_run(&self, cmd: &mut Command) -> bool {
+        if !self.fail_fast {
+            #[allow(deprecated)] // can't use Build::try_run, that's us
+            if self.config.try_run(cmd).is_err() {
+                let mut failures = self.delayed_failures.borrow_mut();
+                failures.push(format!("{:?}", cmd));
+                return false;
+            }
+        } else {
+            self.run(cmd);
+        }
+        true
+    }
+
     pub fn is_verbose_than(&self, level: usize) -> bool {
         self.verbosity > level
     }