Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead Option layer from run_piped #3634

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove dead Option layer from run_piped
  • Loading branch information
zhassan-aws committed Oct 22, 2024
commit f15992c1b0265893bd7a1fd558cc806fd26a0f01
93 changes: 45 additions & 48 deletions kani-driver/src/call_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,62 +277,59 @@ crate-type = ["lib"]
fn run_build(&self, cargo_cmd: Command) -> Result<Vec<RustcArtifact>> {
let support_color = std::io::stdout().is_terminal();
let mut artifacts = vec![];
if let Some(mut cargo_process) = self.run_piped(cargo_cmd)? {
let reader = BufReader::new(cargo_process.stdout.take().unwrap());
let mut error_count = 0;
for message in Message::parse_stream(reader) {
let message = message.unwrap();
match message {
Message::CompilerMessage(msg) => match msg.message.level {
DiagnosticLevel::FailureNote => {
print_msg(&msg.message, support_color)?;
}
DiagnosticLevel::Error => {
error_count += 1;
print_msg(&msg.message, support_color)?;
}
DiagnosticLevel::Ice => {
print_msg(&msg.message, support_color)?;
let _ = cargo_process.wait();
return Err(anyhow::Error::msg(msg.message).context(format!(
"Failed to compile `{}` due to an internal compiler error.",
msg.target.name
)));
}
_ => {
if !self.args.common_args.quiet {
print_msg(&msg.message, support_color)?;
}
}
},
Message::CompilerArtifact(rustc_artifact) => {
// Compares two targets, and falls back to a weaker
// comparison where we avoid dashes in their names.
artifacts.push(rustc_artifact)
let mut cargo_process = self.run_piped(cargo_cmd)?;
let reader = BufReader::new(cargo_process.stdout.take().unwrap());
let mut error_count = 0;
for message in Message::parse_stream(reader) {
let message = message.unwrap();
match message {
Message::CompilerMessage(msg) => match msg.message.level {
DiagnosticLevel::FailureNote => {
print_msg(&msg.message, support_color)?;
}
Message::BuildScriptExecuted(_) | Message::BuildFinished(_) => {
// do nothing
DiagnosticLevel::Error => {
error_count += 1;
print_msg(&msg.message, support_color)?;
}
Message::TextLine(msg) => {
if !self.args.common_args.quiet {
println!("{msg}");
}
DiagnosticLevel::Ice => {
print_msg(&msg.message, support_color)?;
let _ = cargo_process.wait();
return Err(anyhow::Error::msg(msg.message).context(format!(
"Failed to compile `{}` due to an internal compiler error.",
msg.target.name
)));
}

// Non-exhaustive enum.
_ => {
if !self.args.common_args.quiet {
println!("{message:?}");
print_msg(&msg.message, support_color)?;
}
}
},
Message::CompilerArtifact(rustc_artifact) => {
// Compares two targets, and falls back to a weaker
// comparison where we avoid dashes in their names.
artifacts.push(rustc_artifact)
}
Message::BuildScriptExecuted(_) | Message::BuildFinished(_) => {
// do nothing
}
Message::TextLine(msg) => {
if !self.args.common_args.quiet {
println!("{msg}");
}
}

// Non-exhaustive enum.
_ => {
if !self.args.common_args.quiet {
println!("{message:?}");
}
}
}
let status = cargo_process.wait()?;
if !status.success() {
bail!(
"Failed to execute cargo ({status}). Found {error_count} compilation errors."
);
}
}
let status = cargo_process.wait()?;
if !status.success() {
bail!("Failed to execute cargo ({status}). Found {error_count} compilation errors.");
}
Ok(artifacts)
}
Expand Down Expand Up @@ -383,7 +380,7 @@ crate-type = ["lib"]
cmd.arg(pkg);
// For some reason clippy cannot see that we are invoking wait() in the next line.
#[allow(clippy::zombie_processes)]
let mut process = self.run_piped(cmd)?.unwrap();
let mut process = self.run_piped(cmd)?;
let result = process.wait()?;
if !result.success() {
bail!("Failed to retrieve information for `{pkg}`");
Expand Down
4 changes: 2 additions & 2 deletions kani-driver/src/call_cbmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ impl KaniSession {
cmd.arg("--json-ui");

// Spawn the CBMC process and process its output below
let cbmc_process_opt = self.run_piped(cmd)?;
let cbmc_process = cbmc_process_opt.ok_or(anyhow::Error::msg("Failed to run cbmc"))?;
let cbmc_process =
self.run_piped(cmd).map_err(|_| anyhow::Error::msg("Failed to run cbmc"))?;
let output = process_cbmc_output(cbmc_process, |i| {
kani_cbmc_output_filter(
i,
Expand Down
6 changes: 3 additions & 3 deletions kani-driver/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl KaniSession {
}

/// Call [run_piped] with the verbosity configured by the user.
pub fn run_piped(&self, cmd: Command) -> Result<Option<Child>> {
pub fn run_piped(&self, cmd: Command) -> Result<Child> {
run_piped(&self.args.common_args, cmd)
}

Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn run_redirect(
///
/// NOTE: Unlike other `run_` functions, this function does not attempt to indicate
/// the process exit code, you need to remember to check this yourself.
pub fn run_piped(verbosity: &impl Verbosity, mut cmd: Command) -> Result<Option<Child>> {
pub fn run_piped(verbosity: &impl Verbosity, mut cmd: Command) -> Result<Child> {
if verbosity.verbose() {
println!("[Kani] Running: `{}`", render_command(&cmd).to_string_lossy());
}
Expand All @@ -237,7 +237,7 @@ pub fn run_piped(verbosity: &impl Verbosity, mut cmd: Command) -> Result<Option<
.spawn()
.context(format!("Failed to invoke {}", cmd.get_program().to_string_lossy()))?;

Ok(Some(process))
Ok(process)
}

/// Execute the provided function and measure the clock time it took for its execution.
Expand Down
Loading