outpath diff scratch commit

This commit is contained in:
Graham Christensen 2019-04-13 08:09:19 -04:00
parent 8bd49f5dcd
commit 09e20e5845
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 55 additions and 20 deletions

View file

@ -261,6 +261,33 @@ impl Nix {
}
}
pub fn run_stderr_stdout(&self, mut cmd: Command) -> (bool, fs::File, fs::File) {
let stdout_file = tempfile().expect("Fetching a stdout tempfile");
let mut stdout_reader = stdout_file
.try_clone()
.expect("Cloning stdout to the reader");
let stderr_file = tempfile().expect("Fetching a stderr tempfile");
let mut stderr_reader = stderr_file
.try_clone()
.expect("Cloning stderr to the reader");
let status = cmd
.stdout(Stdio::from(stdout_file))
.stderr(Stdio::from(stderr_file))
.status()
.expect("Running a program ...");
stdout_reader
.seek(SeekFrom::Start(0))
.expect("Seeking dout to Start(0)");
stderr_reader
.seek(SeekFrom::Start(0))
.expect("Seeking stderr to Start(0)");
(status.success(), stdout_reader, stderr_reader)
}
pub fn safe_command(
&self,
op: &Operation,

View file

@ -1,19 +1,23 @@
extern crate amqp;
extern crate env_logger;
use crate::nixstats::EvaluationStats;
use ofborg::nix;
use serde_json;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::path::PathBuf;
pub struct OutPathDiff {
calculator: OutPaths,
pub original: Option<PackageOutPaths>,
pub current: Option<PackageOutPaths>,
pub original: Option<(PackageOutPaths, EvaluationStats)>,
pub current: Option<(PackageOutPaths, EvaluationStats)>,
}
impl OutPathDiff {
@ -59,8 +63,8 @@ impl OutPathDiff {
}
pub fn package_diff(&self) -> Option<(Vec<PackageArch>, Vec<PackageArch>)> {
if let Some(ref cur) = self.current {
if let Some(ref orig) = self.original {
if let Some((ref cur, _)) = self.current {
if let Some((ref orig, _)) = self.original {
let orig_set: HashSet<&PackageArch> = orig.keys().collect();
let cur_set: HashSet<&PackageArch> = cur.keys().collect();
@ -84,8 +88,8 @@ impl OutPathDiff {
pub fn calculate_rebuild(&self) -> Option<Vec<PackageArch>> {
let mut rebuild: Vec<PackageArch> = vec![];
if let Some(ref cur) = self.current {
if let Some(ref orig) = self.original {
if let Some((ref cur, _)) = self.current {
if let Some((ref orig, _)) = self.original {
for key in cur.keys() {
trace!("Checking out {:?}", key);
if cur.get(key) != orig.get(key) {
@ -103,7 +107,7 @@ impl OutPathDiff {
None
}
fn run(&mut self) -> Result<PackageOutPaths, File> {
fn run(&mut self) -> Result<(PackageOutPaths, EvaluationStats), File> {
self.calculator.find()
}
}
@ -134,18 +138,21 @@ impl OutPaths {
}
}
pub fn find(&self) -> Result<PackageOutPaths, File> {
self.run()
}
fn run(&self) -> Result<PackageOutPaths, File> {
pub fn find(&self) -> Result<(PackageOutPaths, EvaluationStats), File> {
self.place_nix();
let ret = self.execute();
let (status, stdout, mut stderr) = self.execute();
self.remove_nix();
match ret {
Ok(file) => Ok(parse_lines(&mut BufReader::new(file))),
Err(e) => Err(e),
if status {
Err(stderr)
} else if let Ok(stats) = serde_json::from_reader(&mut stderr) {
let outpaths = parse_lines(&mut BufReader::new(stdout));
Ok((outpaths, stats))
} else {
stderr
.seek(SeekFrom::Start(0))
.expect("Seeking to Start(0)");
Err(stderr)
}
}
@ -166,14 +173,14 @@ impl OutPaths {
dest
}
fn execute(&self) -> Result<File, File> {
fn execute(&self) -> (bool, File, File) {
let check_meta: String = if self.check_meta {
String::from("true")
} else {
String::from("false")
};
self.nix.safely(
self.nix.run_stderr_stdout(self.nix.safe_command(
&nix::Operation::QueryPackagesOutputs,
&self.path,
vec![
@ -183,8 +190,8 @@ impl OutPaths {
String::from("checkMeta"),
check_meta,
],
true,
)
&[],
))
}
}

View file

@ -270,6 +270,7 @@ impl<'a> NixpkgsStrategy<'a> {
match checker.find() {
Ok(pkgs) => {
let mut try_build: Vec<String> = pkgs
.0
.keys()
.map(|pkgarch| pkgarch.package.clone())
.filter(|pkg| possibly_touched_packages.contains(&pkg))