Support checking meta, half way

This commit is contained in:
Graham Christensen 2017-12-05 17:42:19 -05:00
parent b1378bab5b
commit 38d9bb3392
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 94 additions and 12 deletions

View file

@ -11,8 +11,7 @@ use ofborg::nix;
use std::io::Write;
pub struct OutPathDiff {
path: PathBuf,
nix: nix::Nix,
calculator: OutPaths,
pub original: Option<HashMap<String, String>>,
pub current: Option<HashMap<String, String>>,
}
@ -20,8 +19,7 @@ pub struct OutPathDiff {
impl OutPathDiff {
pub fn new(nix: nix::Nix, path: PathBuf) -> OutPathDiff {
OutPathDiff {
nix: nix,
path: path,
calculator: OutPaths::new(nix, path, false),
original: None,
current: None,
}
@ -106,6 +104,30 @@ impl OutPathDiff {
return None;
}
fn run(&mut self) -> Result<File, File> {
self.calculator.find()
}
}
pub struct OutPaths {
path: PathBuf,
nix: nix::Nix,
check_meta: bool,
}
impl OutPaths {
pub fn new(nix: nix::Nix, path: PathBuf, check_meta: bool) -> OutPaths {
OutPaths {
nix: nix,
path: path,
check_meta: check_meta,
}
}
pub fn find(&self) -> Result<File, File> {
self.run()
}
fn run(&self) -> Result<File, File> {
self.place_nix();
let ret = self.execute();
@ -115,31 +137,40 @@ impl OutPathDiff {
fn place_nix(&self) {
let mut file = File::create(self.nix_path()).expect("Failed to create nix out path check");
file.write_all(include_str!("rebuild-amount.nix").as_bytes()).expect("");
file.write_all(include_str!("outpaths.nix").as_bytes()).expect("Failed to place outpaths.nix");
}
fn remove_nix(&self) {
fs::remove_file(self.nix_path()).expect(":)");
fs::remove_file(self.nix_path()).expect("Failed to delete outpaths.nix");
}
fn nix_path(&self) -> PathBuf {
let mut dest = self.path.clone();
dest.push(".gc-of-borg-out-list.nix");
dest.push(".gc-of-borg-outpaths.nix");
dest
}
fn execute(&self) -> Result<File, File>{
fn execute(&self) -> Result<File, File> {
let check_meta: String;
if self.check_meta {
check_meta = String::from("true");
} else {
check_meta = String::from("false");
}
self.nix.safely(
"nix-env",
&self.path,
vec![
String::from("-f"),
String::from(".gc-of-borg-out-list.nix"),
String::from(".gc-of-borg-outpaths.nix"),
String::from("-qaP"),
String::from("--no-name"),
String::from("--out-path"),
String::from("--show-trace"),
String::from("--arg"), String::from("checkMeta"), check_meta,
],
true
)

View file

@ -1,8 +1,19 @@
{ checkMeta ? false }:
let
lib = import ./lib;
hydraJobs = import ./pkgs/top-level/release.nix
# Compromise: accuracy vs. resources needed for evaluation.
{ supportedSystems = [ "x86_64-linux" "x86_64-darwin" ]; };
{
supportedSystems = [ "x86_64-linux" "x86_64-darwin" ];
nixpkgsArgs = {
config = {
allowBroken = true;
allowUnfree = true;
inHydra = true;
checkMeta = checkMeta;
};
};
};
recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
# hydraJobs leaves recurseForDerivations as empty attrmaps;

View file

@ -14,7 +14,7 @@ use ofborg::nix::Nix;
use ofborg::worker;
use ofborg::tagger::{StdenvTagger,RebuildTagger};
use ofborg::outpathdiff::OutPathDiff;
use ofborg::outpathdiff::{OutPaths, OutPathDiff};
use ofborg::evalchecker::EvalChecker;
use ofborg::commitstatus::CommitStatus;
use amqp::protocol::basic::{Deliver,BasicProperties};
@ -262,7 +262,7 @@ impl worker::SimpleWorker for MassRebuildWorker {
),
];
let eval_results: bool = eval_checks.into_iter()
let mut eval_results: bool = eval_checks.into_iter()
.map(|check|
{
let mut status = CommitStatus::new(
@ -306,6 +306,46 @@ impl worker::SimpleWorker for MassRebuildWorker {
)
.all(|status| status == Ok(()));
if eval_results {
let mut status = CommitStatus::new(
repo.statuses(),
job.pr.head_sha.clone(),
String::from("Meta Field Checks"),
String::from("config.nix: checkMeta = true"),
None
);
status.set(hubcaps::statuses::State::Pending);
let state: hubcaps::statuses::State;
let gist_url: Option<String>;
let checker = OutPaths::new(
self.nix.clone(),
PathBuf::from(&refpath),
true
);
match checker.find() {
Ok(_) => {
state = hubcaps::statuses::State::Success;
gist_url = None;
}
Err(mut out) => {
eval_results = false;
state = hubcaps::statuses::State::Failure;
gist_url = make_gist(
&gists,
String::from("Meta Check"),
Some(format!("{:?}", state)),
file_to_str(&mut out),
);
}
}
status.set_url(gist_url);
status.set(state.clone());
}
if eval_results {
overall_status.set_with_description(
"Calculating Changed Outputs",