From cc89c1a88dc99c14769993f825d75ff2f31280c0 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Fri, 1 May 2020 21:16:03 +0200 Subject: [PATCH] move exit status handling to nix module --- ofborg/src/nix.rs | 24 ++++++++++++++++++++++-- ofborg/src/tasks/build.rs | 18 +----------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index e0bb21a..df0bada 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -1,8 +1,7 @@ use crate::asynccmd::{AsyncCmd, SpawnedAsyncCmd}; +use crate::message::buildresult::BuildStatus; use crate::ofborg::partition_result; -use tempfile::tempfile; - use std::collections::HashMap; use std::env; use std::ffi::OsStr; @@ -12,6 +11,8 @@ use std::io::{BufRead, BufReader, Seek, SeekFrom}; use std::path::Path; use std::process::{Command, Stdio}; +use tempfile::tempfile; + #[derive(Clone, Copy, Debug, PartialEq)] pub enum File { DefaultNixpkgs, @@ -358,6 +359,25 @@ pub fn is_user_setting_warning(line: &str) -> bool { && line.ends_with("because it is a restricted setting and you are not a trusted user") } +pub fn wait_for_build_status(spawned: SpawnedAsyncCmd) -> BuildStatus { + match spawned.wait() { + Ok(s) => match s.code() { + Some(0) => BuildStatus::Success, + Some(100) => BuildStatus::Failure, // nix permanent failure + Some(101) => BuildStatus::TimedOut, // nix build timedout + Some(i) => BuildStatus::UnexpectedError { + err: format!("command failed with exit code {}", i), + }, + None => BuildStatus::UnexpectedError { + err: "unexpected build failure".into(), + }, + }, + e => BuildStatus::UnexpectedError { + err: format!("failed on interior command {:?}", e), + }, + } +} + #[cfg(test)] mod tests { fn nix() -> Nix { diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index 4f0721c..cce1925 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -361,23 +361,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { actions.log_line(&line); } - // TODO: this belongs in the nix module. - let status = match spawned.wait() { - Ok(s) => match s.code() { - Some(0) => BuildStatus::Success, - Some(100) => BuildStatus::Failure, // nix permanent failure - Some(101) => BuildStatus::TimedOut, // nix build timedout - Some(i) => BuildStatus::UnexpectedError { - err: format!("command failed with exit code {}", i), - }, - None => BuildStatus::UnexpectedError { - err: "unexpected build failure".into(), - }, - }, - e => BuildStatus::UnexpectedError { - err: format!("failed on interior command {:?}", e), - }, - }; + let status = nix::wait_for_build_status(spawned); info!("ok built ({:?}), building", status); info!("Lines:");