diff --git a/ofborg/src/nixenv.rs b/ofborg/src/nixenv.rs index 0a05f90..91455c2 100644 --- a/ofborg/src/nixenv.rs +++ b/ofborg/src/nixenv.rs @@ -7,6 +7,7 @@ use serde_json; use std::fs; use std::fs::File; use std::io::BufReader; +use std::io::Read; use std::io::Seek; use std::io::SeekFrom; use std::io::Write; @@ -93,3 +94,24 @@ impl From for Error { Error::Io(e) } } + +impl Error { + pub fn display(self) -> String { + match self { + Error::Io(e) => format!("Failed during the setup of executing nix-env: {:?}", e), + Error::Fd(mut fd) => { + let mut buffer = Vec::new(); + let read_result = fd.read_to_end(&mut buffer); + let bufstr = String::from_utf8_lossy(&buffer); + + match read_result { + Ok(_) => format!("nix-env failed:\n{}", bufstr), + Err(e) => format!( + "nix-env failed and loading the error result caused a new error {:?}\n\n{}", + e, bufstr + ), + } + } + } + } +} diff --git a/ofborg/src/outpathdiff.rs b/ofborg/src/outpathdiff.rs index 95334a3..5bde638 100644 --- a/ofborg/src/outpathdiff.rs +++ b/ofborg/src/outpathdiff.rs @@ -1,6 +1,5 @@ -extern crate amqp; -extern crate env_logger; - +use crate::nixenv::Error as NixEnvError; +use crate::nixenv::HydraNixEnv; use crate::nixstats::EvaluationStats; use ofborg::nix; use serde_json; @@ -15,7 +14,7 @@ use std::io::Write; use std::path::PathBuf; pub struct OutPathDiff { - calculator: OutPaths, + calculator: HydraNixEnv, pub original: Option<(PackageOutPaths, EvaluationStats)>, pub current: Option<(PackageOutPaths, EvaluationStats)>, } @@ -23,43 +22,25 @@ pub struct OutPathDiff { impl OutPathDiff { pub fn new(nix: nix::Nix, path: PathBuf) -> OutPathDiff { OutPathDiff { - calculator: OutPaths::new(nix, path, false), + calculator: HydraNixEnv::new(nix, path, false), original: None, current: None, } } - pub fn find_before(&mut self) -> Result { - let x = self.run(); - match x { - Ok(f) => { - self.original = Some(f); - Ok(true) - } - Err(e) => { - info!("Failed to find Before list"); - Err(e) - } - } + pub fn find_before(&mut self) -> Result<(), NixEnvError> { + self.original = Some(self.run()?); + Ok(()) } - pub fn find_after(&mut self) -> Result { + pub fn find_after(&mut self) -> Result<(), NixEnvError> { if self.original.is_none() { debug!("Before is None, not bothering with After"); - return Ok(false); + return Ok(()); } - let x = self.run(); - match x { - Ok(f) => { - self.current = Some(f); - Ok(true) - } - Err(e) => { - info!("Failed to find After list"); - Err(e) - } - } + self.current = Some(self.run()?); + Ok(()) } pub fn package_diff(&self) -> Option<(Vec, Vec)> { @@ -107,8 +88,8 @@ impl OutPathDiff { None } - fn run(&mut self) -> Result<(PackageOutPaths, EvaluationStats), File> { - self.calculator.find() + fn run(&mut self) -> Result<(PackageOutPaths, EvaluationStats), NixEnvError> { + self.calculator.execute() } } diff --git a/ofborg/src/tasks/eval/nixpkgs.rs b/ofborg/src/tasks/eval/nixpkgs.rs index 6afb934..d61fa1f 100644 --- a/ofborg/src/tasks/eval/nixpkgs.rs +++ b/ofborg/src/tasks/eval/nixpkgs.rs @@ -125,7 +125,7 @@ impl<'a> NixpkgsStrategy<'a> { fn check_outpaths_before(&mut self, dir: &Path) -> StepResult<()> { let mut rebuildsniff = OutPathDiff::new(self.nix.clone(), dir.to_path_buf()); - if let Err(mut output) = rebuildsniff.find_before() { + if let Err(err) = rebuildsniff.find_before() { /* self.events .notify(Event::TargetBranchFailsEvaluation(target_branch.clone())); @@ -134,7 +134,7 @@ impl<'a> NixpkgsStrategy<'a> { Err(Error::FailWithGist( String::from("The branch this PR will merge in to does not evaluate, and so this PR cannot be checked."), String::from("Output path comparison"), - file_to_str(&mut output), + err.display(), )) } else { self.outpath_diff = Some(rebuildsniff); @@ -144,11 +144,11 @@ impl<'a> NixpkgsStrategy<'a> { fn check_outpaths_after(&mut self) -> StepResult<()> { if let Some(ref mut rebuildsniff) = self.outpath_diff { - if let Err(mut output) = rebuildsniff.find_after() { + if let Err(mut err) = rebuildsniff.find_after() { Err(Error::FailWithGist( String::from("This PR breaks listing of package outputs after merging."), String::from("Output path comparison"), - file_to_str(&mut output), + err.display(), )) } else { Ok(())