From 7a0fa5a559b036a1e6c1f231a6b188c6d61e1f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sat, 29 Jun 2024 22:07:59 +0200 Subject: [PATCH] Handle execution of dry run commands --- src/bootstrap/src/core/build_steps/perf.rs | 1 - src/bootstrap/src/core/build_steps/test.rs | 8 +++++++- src/bootstrap/src/core/metadata.rs | 3 +-- src/bootstrap/src/lib.rs | 5 ++--- src/bootstrap/src/utils/exec.rs | 14 +++++++++++++- 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 20ab1836e0068..f41b5fe10f1d9 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 b063d0aaf4f16..998e45848a1c3 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 da269959e7b43..49d17107125aa 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 { .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 7f096b8fc3bf7..510eaeb33ff01 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -964,12 +964,11 @@ impl Build { /// Execute a command and return its output. /// This method should be used for all command executions in bootstrap. fn run>(&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 = match command.output_mode { diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 78a3b917e459a..98d194e64d3ab 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 for BootstrapCommand { impl From 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, + } } }