diff --git a/ofborg/src/tagger.rs b/ofborg/src/tagger.rs index e2bdba3..0952f79 100644 --- a/ofborg/src/tagger.rs +++ b/ofborg/src/tagger.rs @@ -21,13 +21,13 @@ impl StdenvTagger { return t; } - pub fn changed(&mut self, systems: Vec) { + pub fn changed(&mut self, systems: Vec) { for system in systems { match system { - tasks::massrebuilder::System::X8664Darwin => { + tasks::eval::stdenvs::System::X8664Darwin => { self.selected.push(String::from("10.rebuild-darwin-stdenv")); } - tasks::massrebuilder::System::X8664Linux => { + tasks::eval::stdenvs::System::X8664Linux => { self.selected.push(String::from("10.rebuild-linux-stdenv")); } } diff --git a/ofborg/src/tasks/eval/mod.rs b/ofborg/src/tasks/eval/mod.rs new file mode 100644 index 0000000..35a344b --- /dev/null +++ b/ofborg/src/tasks/eval/mod.rs @@ -0,0 +1,2 @@ +pub mod stdenvs; +pub use self::stdenvs::Stdenvs; diff --git a/ofborg/src/tasks/eval/stdenvs.rs b/ofborg/src/tasks/eval/stdenvs.rs new file mode 100644 index 0000000..febe2fc --- /dev/null +++ b/ofborg/src/tasks/eval/stdenvs.rs @@ -0,0 +1,149 @@ + +use std::path::PathBuf; +use ofborg::nix; +use ofborg::files::file_to_str; + +enum StdenvFrom { + Before, + After, +} + +#[derive(Debug)] +pub enum System { + X8664Darwin, + X8664Linux, +} + +#[derive(Debug, PartialEq)] +pub struct Stdenvs { + nix: nix::Nix, + co: PathBuf, + + linux_stdenv_before: Option, + linux_stdenv_after: Option, + + darwin_stdenv_before: Option, + darwin_stdenv_after: Option, +} + +impl Stdenvs { + pub fn new(nix: nix::Nix, co: PathBuf) -> Stdenvs { + return Stdenvs { + nix: nix, + co: co, + + linux_stdenv_before: None, + linux_stdenv_after: None, + + darwin_stdenv_before: None, + darwin_stdenv_after: None, + }; + } + + pub fn identify_before(&mut self) { + self.identify(System::X8664Linux, StdenvFrom::Before); + self.identify(System::X8664Darwin, StdenvFrom::Before); + } + + pub fn identify_after(&mut self) { + self.identify(System::X8664Linux, StdenvFrom::After); + self.identify(System::X8664Darwin, StdenvFrom::After); + } + + pub fn are_same(&self) -> bool { + return self.changed().len() == 0; + } + + pub fn changed(&self) -> Vec { + let mut changed: Vec = vec![]; + + if self.linux_stdenv_before != self.linux_stdenv_after { + changed.push(System::X8664Linux); + } + + if self.darwin_stdenv_before != self.darwin_stdenv_after { + changed.push(System::X8664Darwin); + } + + + return changed; + } + + fn identify(&mut self, system: System, from: StdenvFrom) { + match (system, from) { + (System::X8664Linux, StdenvFrom::Before) => { + self.linux_stdenv_before = self.evalstdenv("x86_64-linux"); + } + (System::X8664Linux, StdenvFrom::After) => { + self.linux_stdenv_after = self.evalstdenv("x86_64-linux"); + } + + (System::X8664Darwin, StdenvFrom::Before) => { + self.darwin_stdenv_before = self.evalstdenv("x86_64-darwin"); + } + (System::X8664Darwin, StdenvFrom::After) => { + self.darwin_stdenv_after = self.evalstdenv("x86_64-darwin"); + } + } + } + + /// This is used to find out what the output path of the stdenv for the + /// given system. + fn evalstdenv(&self, system: &str) -> Option { + let result = self.nix.with_system(system.to_owned()).safely( + nix::Operation::QueryPackagesOutputs, + &self.co, + vec![ + String::from("-f"), + String::from("."), + String::from("-A"), + String::from("stdenv"), + ], + true, + ); + + println!("{:?}", result); + + return match result { + Ok(mut out) => Some(file_to_str(&mut out)), + Err(mut out) => { + println!("{:?}", file_to_str(&mut out)); + None + } + }; + } +} + +#[cfg(test)] +mod tests { + + use super::*; + use std::env; + use std::process::Command; + + #[test] + fn stdenv_checking() { + let output = Command::new("nix-instantiate") + .args(&["--eval", "-E", ""]) + .output() + .expect("nix-instantiate required"); + + let nixpkgs = String::from_utf8(output.stdout) + .expect("nixpkgs required"); + + let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); + let nix = nix::Nix::new(String::from("x86_64-linux"), remote, 1200, None); + let mut stdenv = + Stdenvs::new( + nix.clone(), + PathBuf::from(nixpkgs.trim_right()), + ); + stdenv.identify(System::X8664Linux, StdenvFrom::Before); + stdenv.identify(System::X8664Darwin, StdenvFrom::Before); + + stdenv.identify(System::X8664Linux, StdenvFrom::After); + stdenv.identify(System::X8664Darwin, StdenvFrom::After); + + assert!(stdenv.are_same()); + } +} diff --git a/ofborg/src/tasks/massrebuilder.rs b/ofborg/src/tasks/massrebuilder.rs index 8a88cae..c5df76b 100644 --- a/ofborg/src/tasks/massrebuilder.rs +++ b/ofborg/src/tasks/massrebuilder.rs @@ -3,6 +3,7 @@ extern crate amqp; extern crate env_logger; extern crate uuid; +use tasks::eval; use uuid::Uuid; use std::collections::HashMap; use std::path::Path; @@ -195,7 +196,7 @@ impl worker::SimpleWorker for MassRebuildWorker worker::SimpleWorker for MassRebuildWorker, - linux_stdenv_after: Option, - - darwin_stdenv_before: Option, - darwin_stdenv_after: Option, -} - -impl Stdenvs { - fn new(nix: nix::Nix, co: PathBuf) -> Stdenvs { - return Stdenvs { - nix: nix, - co: co, - - linux_stdenv_before: None, - linux_stdenv_after: None, - - darwin_stdenv_before: None, - darwin_stdenv_after: None, - }; - } - - fn identify_before(&mut self) { - self.identify(System::X8664Linux, StdenvFrom::Before); - self.identify(System::X8664Darwin, StdenvFrom::Before); - } - - fn identify_after(&mut self) { - self.identify(System::X8664Linux, StdenvFrom::After); - self.identify(System::X8664Darwin, StdenvFrom::After); - } - - fn are_same(&self) -> bool { - return self.changed().len() == 0; - } - - fn changed(&self) -> Vec { - let mut changed: Vec = vec![]; - - if self.linux_stdenv_before != self.linux_stdenv_after { - changed.push(System::X8664Linux); - } - - if self.darwin_stdenv_before != self.darwin_stdenv_after { - changed.push(System::X8664Darwin); - } - - - return changed; - } - - fn identify(&mut self, system: System, from: StdenvFrom) { - match (system, from) { - (System::X8664Linux, StdenvFrom::Before) => { - self.linux_stdenv_before = self.evalstdenv("x86_64-linux"); - } - (System::X8664Linux, StdenvFrom::After) => { - self.linux_stdenv_after = self.evalstdenv("x86_64-linux"); - } - - (System::X8664Darwin, StdenvFrom::Before) => { - self.darwin_stdenv_before = self.evalstdenv("x86_64-darwin"); - } - (System::X8664Darwin, StdenvFrom::After) => { - self.darwin_stdenv_after = self.evalstdenv("x86_64-darwin"); - } - } - } - - /// This is used to find out what the output path of the stdenv for the - /// given system. - fn evalstdenv(&self, system: &str) -> Option { - let result = self.nix.with_system(system.to_owned()).safely( - nix::Operation::QueryPackagesOutputs, - &self.co, - vec![ - String::from("-f"), - String::from("."), - String::from("-A"), - String::from("stdenv"), - ], - true, - ); - - println!("{:?}", result); - - return match result { - Ok(mut out) => Some(file_to_str(&mut out)), - Err(mut out) => { - println!("{:?}", file_to_str(&mut out)); - None - } - }; - } -} fn make_gist<'a>( gists: &hubcaps::gists::Gists<'a>, @@ -753,34 +645,6 @@ fn parse_commit_messages(messages: Vec) -> Vec { mod tests { use super::*; - use std::env; - use std::process::Command; - - #[test] - fn stdenv_checking() { - let output = Command::new("nix-instantiate") - .args(&["--eval", "-E", ""]) - .output() - .expect("nix-instantiate required"); - - let nixpkgs = String::from_utf8(output.stdout) - .expect("nixpkgs required"); - - let remote = env::var("NIX_REMOTE").unwrap_or("".to_owned()); - let nix = nix::Nix::new(String::from("x86_64-linux"), remote, 1200, None); - let mut stdenv = - Stdenvs::new( - nix.clone(), - PathBuf::from(nixpkgs.trim_right()), - ); - stdenv.identify(System::X8664Linux, StdenvFrom::Before); - stdenv.identify(System::X8664Darwin, StdenvFrom::Before); - - stdenv.identify(System::X8664Linux, StdenvFrom::After); - stdenv.identify(System::X8664Darwin, StdenvFrom::After); - - assert!(stdenv.are_same()); - } #[test] fn test_parse_commit_messages() { diff --git a/ofborg/src/tasks/mod.rs b/ofborg/src/tasks/mod.rs index 531e981..3b31963 100644 --- a/ofborg/src/tasks/mod.rs +++ b/ofborg/src/tasks/mod.rs @@ -1,4 +1,5 @@ +pub mod eval; pub mod build; pub mod massrebuilder; pub mod githubcommentfilter;