about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <jakub.beranek@vsb.cz>2024-06-29 22:07:59 +0200
committerJakub Beránek <jakub.beranek@vsb.cz>2024-07-03 21:13:55 +0200
commit70b6e044523b0a2bc89b748a389c04277b5b9da1 (patch)
treeda53281659fa55c81e324aac34ddc4f02c1c0d3e
parent60c20bfe0c6e34d36d9a40d835ce6946a10f0238 (diff)
downloadrust-70b6e044523b0a2bc89b748a389c04277b5b9da1.tar.gz
rust-70b6e044523b0a2bc89b748a389c04277b5b9da1.zip
Handle execution of dry run commands
-rw-r--r--src/bootstrap/src/core/build_steps/perf.rs1
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs8
-rw-r--r--src/bootstrap/src/core/metadata.rs3
-rw-r--r--src/bootstrap/src/lib.rs5
-rw-r--r--src/bootstrap/src/utils/exec.rs14
5 files changed, 23 insertions, 8 deletions
diff --git a/src/bootstrap/src/core/build_steps/perf.rs b/src/bootstrap/src/core/build_steps/perf.rs
index 20ab1836e00..f41b5fe10f1 100644
--- a/src/bootstrap/src/core/build_steps/perf.rs
+++ b/src/bootstrap/src/core/build_steps/perf.rs
@@ -2,7 +2,6 @@ use crate::core::build_steps::compile::{Std, Sysroot};
 use crate::core::build_steps::tool::{RustcPerf, Tool};
 use crate::core::builder::Builder;
 use crate::core::config::DebuginfoLevel;
-use crate::utils::exec::BootstrapCommand;
 
 /// Performs profiling using `rustc-perf` on a built version of the compiler.
 pub fn perf(builder: &Builder<'_>) {
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index b063d0aaf4f..998e45848a1 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -1805,7 +1805,13 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
 
         let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
         let lldb_version = builder
-            .run(BootstrapCommand::new(&lldb_exe).capture().allow_failure().arg("--version"))
+            .run(
+                BootstrapCommand::new(&lldb_exe)
+                    .capture()
+                    .allow_failure()
+                    .run_always()
+                    .arg("--version"),
+            )
             .stdout_if_ok();
         if let Some(ref vers) = lldb_version {
             cmd.arg("--lldb-version").arg(vers);
diff --git a/src/bootstrap/src/core/metadata.rs b/src/bootstrap/src/core/metadata.rs
index da269959e7b..49d17107125 100644
--- a/src/bootstrap/src/core/metadata.rs
+++ b/src/bootstrap/src/core/metadata.rs
@@ -81,8 +81,7 @@ fn workspace_members(build: &Build) -> Vec<Package> {
             .arg("--no-deps")
             .arg("--manifest-path")
             .arg(build.src.join(manifest_path));
-        // FIXME: fix stderr
-        let metadata_output = build.run(cargo.capture()).stdout();
+        let metadata_output = build.run(cargo.capture_stdout().run_always()).stdout();
         let Output { packages, .. } = t!(serde_json::from_str(&metadata_output));
         packages
     };
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index 309fec474a1..ce139a0bc59 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -936,12 +936,11 @@ impl Build {
     /// Execute a command and return its output.
     /// This method should be used for all command executions in bootstrap.
     fn run<C: AsMut<BootstrapCommand>>(&self, mut command: C) -> CommandOutput {
-        if self.config.dry_run() {
+        let command = command.as_mut();
+        if self.config.dry_run() && !command.run_always {
             return CommandOutput::default();
         }
 
-        let command = command.as_mut();
-
         self.verbose(|| println!("running: {command:?}"));
 
         let output: io::Result<Output> = match command.output_mode {
diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs
index 78a3b917e45..98d194e64d3 100644
--- a/src/bootstrap/src/utils/exec.rs
+++ b/src/bootstrap/src/utils/exec.rs
@@ -47,6 +47,8 @@ pub struct BootstrapCommand {
     pub command: Command,
     pub failure_behavior: BehaviorOnFailure,
     pub output_mode: OutputMode,
+    // Run the command even during dry run
+    pub run_always: bool,
 }
 
 impl BootstrapCommand {
@@ -107,6 +109,11 @@ impl BootstrapCommand {
         Self { failure_behavior: BehaviorOnFailure::Ignore, ..self }
     }
 
+    pub fn run_always(&mut self) -> &mut Self {
+        self.run_always = true;
+        self
+    }
+
     /// Capture the output of the command, do not print it.
     pub fn capture(self) -> Self {
         Self { output_mode: OutputMode::CaptureAll, ..self }
@@ -128,7 +135,12 @@ impl AsMut<BootstrapCommand> for BootstrapCommand {
 
 impl From<Command> for BootstrapCommand {
     fn from(command: Command) -> Self {
-        Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: OutputMode::Print }
+        Self {
+            command,
+            failure_behavior: BehaviorOnFailure::Exit,
+            output_mode: OutputMode::Print,
+            run_always: false,
+        }
     }
 }