rebuild sniff: use NixEnv abstraction

This commit is contained in:
Graham Christensen 2019-04-13 13:32:33 -04:00
parent c754739505
commit ad15fd1e4b
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 39 additions and 36 deletions

View file

@ -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<std::io::Error> 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
),
}
}
}
}
}

View file

@ -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<bool, File> {
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<bool, File> {
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<PackageArch>, Vec<PackageArch>)> {
@ -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()
}
}

View file

@ -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(())