From 23304d8eae477a1b7b061e9f6e0f0acc1190ddc5 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 10 Dec 2017 16:38:03 -0500 Subject: [PATCH] Add simple-build, which builds gnu hello as if it were a PR --- ofborg/src/bin/simple-build.rs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ofborg/src/bin/simple-build.rs diff --git a/ofborg/src/bin/simple-build.rs b/ofborg/src/bin/simple-build.rs new file mode 100644 index 0000000..ea5b358 --- /dev/null +++ b/ofborg/src/bin/simple-build.rs @@ -0,0 +1,39 @@ +extern crate ofborg; +extern crate amqp; +extern crate env_logger; + +#[macro_use] +extern crate log; + +use std::env; + +use std::path::Path; +use std::fs::File; +use std::io::Read; +use ofborg::config; + + +fn main() { + let cfg = config::load(env::args().nth(1).unwrap().as_ref()); + + if let Err(_) = env::var("RUST_LOG") { + env::set_var("RUST_LOG", "info"); + env_logger::init().unwrap(); + info!("Defaulting RUST_LOG environment variable to info"); + } else { + env_logger::init().unwrap(); + } + + let nix = cfg.nix(); + + match nix.safely_build_attrs(&Path::new("./"), "./default.nix", vec![String::from("hello"),]) { + Ok(mut out) => { print!("{}", file_to_str(&mut out)); } + Err(mut out) => { print!("{}", file_to_str(&mut out)) } + } +} + +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)); +}