Skip to content

Commit 080bab6

Browse files
author
Kalle Fagerberg
committed
Pipe emulator output instead of buffering it
1 parent 781d034 commit 080bab6

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/commands/emulator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::args::EmulatorArgs;
2-
use crate::langs::check_output;
2+
use crate::langs::check_exit_status;
33
use anyhow::{Context, Result, bail};
44
use flate2::read::GzDecoder;
55
use std::fs::File;
@@ -20,8 +20,8 @@ pub fn cmd_emulator(vfs: &Path, args: &EmulatorArgs) -> Result<()> {
2020
download_emulator(&bin_path).context("download emulator")?;
2121
}
2222
println!("⌛ running...");
23-
let output = Command::new(bin_path).args(&args.args).output()?;
24-
check_output(&output).context("run emulator")?;
23+
let exit_status = Command::new(bin_path).args(&args.args).status()?;
24+
check_exit_status(exit_status).context("run emulator")?;
2525
Ok(())
2626
}
2727

src/langs.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::env::temp_dir;
77
use std::fs::File;
88
use std::io::Write;
99
use std::path::{Path, PathBuf};
10-
use std::process::{Command, Output};
10+
use std::process::{Command, ExitStatus, Output};
1111

1212
pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> {
1313
// Don't build the binary if it will be copied directly in "files".
@@ -511,8 +511,12 @@ pub fn path_to_utf8(path: &Path) -> anyhow::Result<&str> {
511511
pub fn check_output(output: &Output) -> anyhow::Result<()> {
512512
std::io::stdout().write_all(&output.stdout)?;
513513
std::io::stderr().write_all(&output.stderr)?;
514-
if !output.status.success() {
515-
let code = output.status.code().unwrap_or(1);
514+
check_exit_status(output.status)
515+
}
516+
517+
pub fn check_exit_status(output: ExitStatus) -> anyhow::Result<()> {
518+
if !output.success() {
519+
let code = output.code().unwrap_or(1);
516520
bail!("subprocess exited with status code {code}");
517521
}
518522
Ok(())

0 commit comments

Comments
 (0)