Remove stdenv hash finding from massrebuilder

This commit is contained in:
Graham Christensen 2018-09-03 16:00:43 -04:00
parent ffb7ab30e6
commit e91a865708
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
5 changed files with 157 additions and 141 deletions

View file

@ -21,13 +21,13 @@ impl StdenvTagger {
return t; return t;
} }
pub fn changed(&mut self, systems: Vec<tasks::massrebuilder::System>) { pub fn changed(&mut self, systems: Vec<tasks::eval::stdenvs::System>) {
for system in systems { for system in systems {
match system { match system {
tasks::massrebuilder::System::X8664Darwin => { tasks::eval::stdenvs::System::X8664Darwin => {
self.selected.push(String::from("10.rebuild-darwin-stdenv")); 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")); self.selected.push(String::from("10.rebuild-linux-stdenv"));
} }
} }

View file

@ -0,0 +1,2 @@
pub mod stdenvs;
pub use self::stdenvs::Stdenvs;

View file

@ -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<String>,
linux_stdenv_after: Option<String>,
darwin_stdenv_before: Option<String>,
darwin_stdenv_after: Option<String>,
}
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<System> {
let mut changed: Vec<System> = 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<String> {
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", "<nixpkgs>"])
.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());
}
}

View file

@ -3,6 +3,7 @@ extern crate amqp;
extern crate env_logger; extern crate env_logger;
extern crate uuid; extern crate uuid;
use tasks::eval;
use uuid::Uuid; use uuid::Uuid;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
@ -195,7 +196,7 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for MassRebuildWorker<E
); );
let mut stdenvs = Stdenvs::new(self.nix.clone(), PathBuf::from(&refpath)); let mut stdenvs = eval::Stdenvs::new(self.nix.clone(), PathBuf::from(&refpath));
stdenvs.identify_before(); stdenvs.identify_before();
let mut rebuildsniff = OutPathDiff::new(self.nix.clone(), PathBuf::from(&refpath)); let mut rebuildsniff = OutPathDiff::new(self.nix.clone(), PathBuf::from(&refpath));
@ -560,116 +561,7 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for MassRebuildWorker<E
} }
} }
enum StdenvFrom {
Before,
After,
}
#[derive(Debug)]
pub enum System {
X8664Darwin,
X8664Linux,
}
#[derive(Debug, PartialEq)]
struct Stdenvs {
nix: nix::Nix,
co: PathBuf,
linux_stdenv_before: Option<String>,
linux_stdenv_after: Option<String>,
darwin_stdenv_before: Option<String>,
darwin_stdenv_after: Option<String>,
}
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<System> {
let mut changed: Vec<System> = 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<String> {
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>( fn make_gist<'a>(
gists: &hubcaps::gists::Gists<'a>, gists: &hubcaps::gists::Gists<'a>,
@ -753,34 +645,6 @@ fn parse_commit_messages(messages: Vec<String>) -> Vec<String> {
mod tests { mod tests {
use super::*; use super::*;
use std::env;
use std::process::Command;
#[test]
fn stdenv_checking() {
let output = Command::new("nix-instantiate")
.args(&["--eval", "-E", "<nixpkgs>"])
.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] #[test]
fn test_parse_commit_messages() { fn test_parse_commit_messages() {

View file

@ -1,4 +1,5 @@
pub mod eval;
pub mod build; pub mod build;
pub mod massrebuilder; pub mod massrebuilder;
pub mod githubcommentfilter; pub mod githubcommentfilter;