From 69502ec69ad6e6cabdf81b9ee7294b9ebb9db6c1 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 18 Mar 2018 16:15:05 -0400 Subject: [PATCH] Log the reasons things can't be instantiated --- ofborg/src/nix.rs | 68 ++++++++++++++++++++++++++------------- ofborg/src/tasks/build.rs | 19 ++++++++--- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index 32b7520..4f2d8cb 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -6,6 +6,8 @@ use std::io::SeekFrom; use std::path::Path; use std::process::{Command, Stdio}; use tempfile::tempfile; +use std::io::BufReader; +use std::io::BufRead; #[derive(Clone, Debug)] pub enum Operation { @@ -102,16 +104,35 @@ impl Nix { nixpkgs: &Path, file: &str, attrs: Vec, - ) -> (Vec, Vec) { - attrs + ) -> (Vec, Vec<(String,Vec)>) { + let attr_instantiations: Vec)>> = + attrs .into_iter() - .partition(|attr| { - self.safely_instantiate_attrs( - nixpkgs, - file, - vec![attr.clone()] - ).is_ok() - }) + .map(|attr| + match self.safely_instantiate_attrs( + nixpkgs, + file, + vec![attr.clone()] + ) { + Ok(_) => Ok(attr.clone()), + Err(f) => Err((attr.clone(), lines_from_file(f))) + } + ) + .collect(); + + let (ok, err): ( + Vec)>>, + Vec)>>) = attr_instantiations + .into_iter() + .partition(|x| x.is_ok()); + + let ok_ret: Vec = ok.into_iter().map(|x| x.unwrap()).collect(); + let err_ret: Vec<(String, Vec)> = err.into_iter().map(|x| x.unwrap_err()).collect(); + + return ( + ok_ret, + err_ret + ) } pub fn safely_instantiate_attrs( @@ -253,6 +274,15 @@ impl Nix { } } +fn lines_from_file(file: File) -> Vec { + BufReader::new(file) + .lines() + .into_iter() + .filter(|line| line.is_ok()) + .map(|line| line.unwrap()) + .collect() +} + #[cfg(test)] mod tests { fn nix() -> Nix { @@ -291,15 +321,6 @@ mod tests { Fail, } - fn lines_from_file(file: File) -> Vec { - BufReader::new(file) - .lines() - .into_iter() - .filter(|line| line.is_ok()) - .map(|line| line.unwrap()) - .collect() - } - fn assert_run(res: Result, expected: Expect, require: Vec<&str>) { let expectation_held: bool = match expected { Expect::Pass => res.is_ok(), @@ -378,8 +399,6 @@ mod tests { } use super::*; - use std::io::BufReader; - use std::io::BufRead; use std::path::PathBuf; use std::env; @@ -567,7 +586,7 @@ mod tests { fn partition_instantiable_attributes() { let nix = nix(); - let ret: (Vec, Vec) = nix.safely_partition_instantiable_attrs( + let ret: (Vec, Vec<(String, Vec)>) = nix.safely_partition_instantiable_attrs( individual_eval_path().as_path(), "default.nix", vec![ @@ -578,7 +597,12 @@ mod tests { ); assert_eq!(ret.0, vec!["passes-instantiation"]); - assert_eq!(ret.1, vec!["fails-instantiation", "missing-attr"]); + + assert_eq!(ret.1[0].0, "fails-instantiation"); + assert_eq!(ret.1[0].1[0], "trace: You just can\'t frooble the frozz on this particular system."); + + assert_eq!(ret.1[1].0, "missing-attr"); + assert_eq!(ret.1[1].1[0], "error: attribute ‘missing-attr’ in selection path ‘missing-attr’ not found"); } #[test] diff --git a/ofborg/src/tasks/build.rs b/ofborg/src/tasks/build.rs index d8784de..0d9a6c9 100644 --- a/ofborg/src/tasks/build.rs +++ b/ofborg/src/tasks/build.rs @@ -342,12 +342,22 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { job.attrs.clone(), ); + let cannot_build_attrs: Vec = cannot_build + .clone() + .into_iter() + .map(|(attr,_)| attr) + .collect(); + println!("Can build: '{}', Cannot build: '{}'", can_build.join(", "), - cannot_build.join(", ")); + cannot_build_attrs.join(", ")); + + + actions.log_started(can_build.clone(), cannot_build_attrs.clone()); + actions.log_instantiation_errors(cannot_build); if can_build.len() == 0 { - actions.build_not_attempted(cannot_build); + actions.build_not_attempted(cannot_build_attrs); return; } @@ -358,7 +368,6 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { ); println!("About to execute {:?}", cmd); - actions.log_started(can_build.clone(), cannot_build.clone()); let acmd = AsyncCmd::new(cmd); let mut spawned = acmd.spawn(); @@ -381,7 +390,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker { let last10lines: Vec = actions.log_snippet().into_iter().collect::>(); - actions.build_finished(success, last10lines.clone(), can_build, cannot_build); + actions.build_finished(success, last10lines.clone(), can_build, cannot_build_attrs); println!("Done!"); } } @@ -541,6 +550,8 @@ mod tests { println!("Total actions: {:?}", dummyreceiver.actions.len()); let mut actions = dummyreceiver.actions.into_iter(); + assert_contains_job(&mut actions, "\"line_number\":1,\"output\":\"Cannot nix-instantiate `not-real\' because:\""); + assert_contains_job(&mut actions, "\"line_number\":2,\"output\":\"error: attribute ‘not-real’ in selection path ‘not-real’ not found\"}"); assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // First one to the github poster assert_contains_job(&mut actions, "skipped_attrs\":[\"not-real"); // This one to the logs assert_eq!(actions.next(), Some(worker::Action::Ack));