Skip to content

Commit

Permalink
Handle execution of dry run commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jun 29, 2024
1 parent c5c34ec commit 67d6eb1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/src/core/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
5 changes: 2 additions & 3 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 {
Expand Down
14 changes: 13 additions & 1 deletion src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand All @@ -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,
}
}
}

Expand Down

0 comments on commit 67d6eb1

Please sign in to comment.