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( pub fn safe_command(
&self, &self,
op: &Operation, op: &Operation,

View file

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

View file

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