From bb94edcb157e323a6f439f97f45cb73fae2df393 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Sun, 9 Apr 2017 10:11:49 -0700 Subject: [PATCH] Support building directly from cookbook with --cookbook= --- src/bin/installer.rs | 15 ++++++++++++++- src/install.rs | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/bin/installer.rs b/src/bin/installer.rs index 525312e4f6..129fe476ba 100644 --- a/src/bin/installer.rs +++ b/src/bin/installer.rs @@ -7,13 +7,26 @@ extern crate toml; use std::{env, process}; use std::fs::File; use std::io::{self, Read, Write}; +use std::path::Path; fn main() { let stderr = io::stderr(); let mut stderr = stderr.lock(); let mut configs = vec![]; + let mut cookbook = None; for arg in env::args().skip(1) { + if arg.starts_with("--cookbook=") { + let path = arg.splitn(2, "--cookbook=").nth(1).unwrap().to_string(); + if !Path::new(&path).is_dir() { + writeln!(stderr, "installer: {}: cookbook not found", arg).unwrap(); + process::exit(1); + + } + cookbook = Some(path); + continue; + } + match File::open(&arg) { Ok(mut config_file) => { let mut config_data = String::new(); @@ -59,7 +72,7 @@ fn main() { } for config in configs { - if let Err(err) = redox_installer::install(config) { + if let Err(err) = redox_installer::install(config, cookbook.as_ref().map(String::as_ref)) { writeln!(stderr, "installer: failed to install: {}", err).unwrap(); process::exit(1); } diff --git a/src/install.rs b/src/install.rs index 6e311c3ec3..30c8c5d8b7 100644 --- a/src/install.rs +++ b/src/install.rs @@ -9,8 +9,9 @@ use self::termion::input::TermRead; use self::pkgutils::Repo; use std::{env, fs}; -use std::io::{self, Write}; +use std::io::{self, stderr, Write}; use std::str::FromStr; +use std::process::{self, Command}; use config::Config; @@ -63,18 +64,40 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result } } -fn install_packages(config: &Config, dest: &str) { +fn install_packages(config: &Config, dest: &str, cookbook: Option<&str>) { let mut repo = Repo::new(TARGET); repo.add_remote(REMOTE); repo.set_dest(dest); - for (packagename, _package) in &config.packages { - println!("Installing package {}", packagename); - repo.install(&packagename).unwrap(); + if let Some(cookbook) = cookbook { + let status = Command::new("./update-packages.sh") + .current_dir(cookbook) + .args(config.packages.keys()) + .spawn() + .unwrap() + .wait() + .unwrap(); + + if !status.success() { + write!(stderr(), "./update-package.sh failed.").unwrap(); + process::exit(1); + } + + for (packagename, _package) in &config.packages { + let path = format!("{}/{}/repo/{}/{}.tar", + env::current_dir().unwrap().to_string_lossy(), + cookbook, TARGET, packagename); + repo.install_file(&path).unwrap(); + } + } else { + for (packagename, _package) in &config.packages { + println!("Installing package {}", packagename); + repo.install(&packagename).unwrap(); + } } } -pub fn install(config: Config) -> Result<(), String> { +pub fn install(config: Config, cookbook: Option<&str>) -> Result<(), String> { println!("Install {:#?}", config); let mut context = liner::Context::new(); @@ -126,7 +149,7 @@ pub fn install(config: Config) -> Result<(), String> { dir!(""); - install_packages(&config, sysroot.to_str().unwrap()); + install_packages(&config, sysroot.to_str().unwrap(), cookbook); for file in config.files { file!(file.path.trim_matches('/'), file.data.as_bytes());