Support building directly from cookbook with --cookbook=
This commit is contained in:
+14
-1
@@ -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);
|
||||
}
|
||||
|
||||
+30
-7
@@ -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<String, String>
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user