Merge pull request #234 from NixOS/move-mass-rebuilder

Move mass rebuilder
This commit is contained in:
Graham Christensen 2018-09-06 22:40:43 -04:00 committed by GitHub
commit 97495c3f11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 189 additions and 154 deletions

View file

@ -1,4 +1,5 @@
language: nix language: nix
nix: 2.1
matrix: matrix:
include: include:
- name: checkPhase - Nix 2 - name: checkPhase - Nix 2

View file

@ -1,7 +1,7 @@
{ {
"url": "https://github.com/nixos/nixpkgs-channels.git", "url": "https://github.com/nixos/nixpkgs-channels.git",
"rev": "2e855dc6b0cd88767a8a5df2faff9e66e1cd7f18", "rev": "4477cf04b6779a537cdb5f0bd3dd30e75aeb4a3b",
"date": "2018-04-11T10:16:39+08:00", "date": "2018-08-31T21:37:07-04:00",
"sha256": "08s6mfh5a05kd2qs3hmza50ng3pyhd3qha4nanwwk0s8fjzqnv4a", "sha256": "1i39wsfwkvj9yryj8di3jibpdg3b3j86ych7s9rb6z79k08yaaxc",
"fetchSubmodules": true "fetchSubmodules": true
} }

8
ofborg/src/files.rs Normal file
View file

@ -0,0 +1,8 @@
use std::io::Read;
use std::fs::File;
pub fn file_to_str(f: &mut File) -> String {
let mut buffer = Vec::new();
f.read_to_end(&mut buffer).expect("Reading eval output");
return String::from(String::from_utf8_lossy(&buffer));
}

View file

@ -36,6 +36,7 @@ pub mod config;
pub mod message; pub mod message;
pub mod tasks; pub mod tasks;
pub mod evalchecker; pub mod evalchecker;
pub mod files;
pub mod nix; pub mod nix;
pub mod stats; pub mod stats;
pub mod ghevent; pub mod ghevent;
@ -61,6 +62,7 @@ pub mod ofborg {
pub use message; pub use message;
pub use tasks; pub use tasks;
pub use evalchecker; pub use evalchecker;
pub use files;
pub use commitstatus; pub use commitstatus;
pub use ghevent; pub use ghevent;
pub use nix; pub use nix;

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

@ -393,7 +393,7 @@ mod tests {
message: MsgType::Msg(logmsg.clone()), message: MsgType::Msg(logmsg.clone()),
}; };
let p = TestScratch::new_dir("log-message-collector-path_for_log"); let p = TestScratch::new_dir("log-message-collector-logs_collector");
{ {
let mut worker = make_worker(p.path()); let mut worker = make_worker(p.path());

View file

@ -3,15 +3,15 @@ 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::fs::File;
use std::io::Read;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use ofborg::checkout; use ofborg::checkout;
use ofborg::message::{massrebuildjob, buildjob}; use ofborg::message::{massrebuildjob, buildjob};
use std::time::Instant; use std::time::Instant;
use ofborg::files::file_to_str;
use ofborg::nix; use ofborg::nix;
use ofborg::acl::ACL; use ofborg::acl::ACL;
use ofborg::stats; use ofborg::stats;
@ -196,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));
@ -561,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>,
@ -730,12 +621,6 @@ pub fn update_labels(issue: &hubcaps::issues::IssueRef, add: Vec<String>, remove
} }
} }
fn file_to_str(f: &mut File) -> String {
let mut buffer = Vec::new();
f.read_to_end(&mut buffer).expect("Reading eval output");
return String::from(String::from_utf8_lossy(&buffer));
}
fn parse_commit_messages(messages: Vec<String>) -> Vec<String> { fn parse_commit_messages(messages: Vec<String>) -> Vec<String> {
messages messages
.iter() .iter()
@ -760,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;

View file

@ -1,6 +1,17 @@
{ pkgs ? import ./nix {}, useNix1 ? false }: { pkgs ? import ./nix {}, useNix1 ? false }:
let let
# A random Nixpkgs revision *before* the default glibc
# was switched to version 2.27.x.
oldpkgsSrc = pkgs.fetchFromGitHub {
owner = "nixos";
repo = "nixpkgs";
rev = "0252e6ca31c98182e841df494e6c9c4fb022c676";
sha256 = "1sr5a11sb26rgs1hmlwv5bxynw2pl5w4h5ic0qv3p2ppcpmxwykz";
};
oldpkgs = import oldpkgsSrc {};
inherit (pkgs) stdenv; inherit (pkgs) stdenv;
phpEnv = stdenv.mkDerivation rec { phpEnv = stdenv.mkDerivation rec {
@ -23,6 +34,7 @@ let
rustEnv = stdenv.mkDerivation rec { rustEnv = stdenv.mkDerivation rec {
name = "gh-event-forwarder"; name = "gh-event-forwarder";
buildInputs = with pkgs; [ buildInputs = with pkgs; [
bash
nix-prefetch-git nix-prefetch-git
rust.rustc rust.rustc
rust.cargo rust.cargo
@ -43,7 +55,10 @@ let
HISTFILE = "${toString ./.}/.bash_hist"; HISTFILE = "${toString ./.}/.bash_hist";
RUSTFLAGS = "-D warnings"; RUSTFLAGS = "-D warnings";
LOCALE_ARCHIVE_2_21 = "${oldpkgs.glibcLocales}/lib/locale/locale-archive";
LOCALE_ARCHIVE_2_27 = "${pkgs.glibcLocales}/lib/locale/locale-archive";
RUST_BACKTRACE = "1";
RUST_LOG = "ofborg=debug";
passthru.phpEnv = phpEnv; passthru.phpEnv = phpEnv;
}; };