Skip to content
Snippets Groups Projects
Commit 2b34b319 authored by Ron Williams's avatar Ron Williams Committed by Jeremy Soller
Browse files

Allow package spec "binary" or "recipe" to override REPO_BINARY=0 or REPO_BINARY=1

parent d61b30de
No related branches found
No related tags found
1 merge request!25Allow package spec "binary" or "recipe" to override REPO_BINARY=0 or REPO_BINARY=1
......@@ -3,9 +3,9 @@ extern crate redox_installer;
extern crate serde;
extern crate toml;
use std::{env, fs, io, process};
use std::io::{Read, Write};
use std::path::Path;
use std::{env, fs, io, process};
use arg_parser::ArgParser;
......@@ -18,34 +18,29 @@ fn main() {
let mut parser = ArgParser::new(4)
.add_opt("b", "cookbook")
.add_opt("c", "config")
.add_flag(&["p", "cooking"])
.add_flag(&["r", "repo-binary"])
.add_flag(&["l", "list-packages"])
.add_flag(&["live"]);
parser.parse(env::args());
// Allow filesystem config to specify recipe or package, enabling mixed recipe/binary build
let cooking = parser.found("cooking");
// Use pre-built binaries for packages as the default.
// If not set on the command line or the filesystem config, then build packages from source.
let repo_binary = parser.found("repo-binary");
let mut config_data = String::new();
let mut config = if let Some(path) = parser.get_opt("config") {
match fs::File::open(&path) {
Ok(mut config_file) => {
match config_file.read_to_string(&mut config_data) {
Ok(_) => {
match toml::from_str(&config_data) {
Ok(config) => {
config
},
Err(err) => {
writeln!(stderr, "installer: {}: failed to decode: {}", path, err).unwrap();
process::exit(1);
}
}
},
Ok(mut config_file) => match config_file.read_to_string(&mut config_data) {
Ok(_) => match toml::from_str(&config_data) {
Ok(config) => config,
Err(err) => {
writeln!(stderr, "installer: {}: failed to read: {}", path, err).unwrap();
writeln!(stderr, "installer: {}: failed to decode: {}", path, err).unwrap();
process::exit(1);
}
},
Err(err) => {
writeln!(stderr, "installer: {}: failed to read: {}", path, err).unwrap();
process::exit(1);
}
},
Err(err) => {
......@@ -65,30 +60,33 @@ fn main() {
});
// Add command line flags to config, command line takes priority
if cooking {
config.general.cooking = Some(true);
if repo_binary {
config.general.repo_binary = Some(true);
}
if parser.found("list-packages") {
// List the packages that should be fetched or built by the cookbook
for (packagename, package) in &config.packages {
if config.general.cooking == Some(true) {
// Only print the names of packages that are relevant to the cookbook
match package {
PackageConfig::Build(rule) if rule == "recipe" => {
println!("{}", packagename);
}
PackageConfig::Build(rule) if rule == "recipe_no_fetch" => {
match package {
PackageConfig::Build(rule) if rule == "recipe" => {
println!("{}", packagename);
}
PackageConfig::Build(rule) if rule == "binary" => {
// skip this package
}
_ => {
if config.general.repo_binary == Some(true) {
// default action is to not build this package, skip it
} else {
// default action is to build
println!("{}", packagename);
}
_ => {}
}
} else {
println!("{}", packagename);
}
}
} else {
let cookbook = if let Some(path) = parser.get_opt("cookbook") {
if ! Path::new(&path).is_dir() {
if !Path::new(&path).is_dir() {
writeln!(stderr, "installer: {}: cookbook not found", path).unwrap();
process::exit(1);
}
......@@ -103,31 +101,50 @@ fn main() {
..Default::default()
});
Some(path)
},
}
Err(err) => {
// if there are no recipes coming from the cookbook, this is not a fatal error
if config.packages.clone().into_iter().any(| (_packagename, package) |
match package {
if config
.packages
.clone()
.into_iter()
.any(|(_packagename, package)| match package {
PackageConfig::Empty => false,
PackageConfig::Spec { version: None, git: None, path: None, } => false,
PackageConfig::Spec {
version: None,
git: None,
path: None,
} => false,
_ => true,
})
{
writeln!(stderr, "installer: {}: failed to read cookbook key: {}", key_path.display(), err).unwrap();
writeln!(
stderr,
"installer: {}: failed to read cookbook key: {}",
key_path.display(),
err
)
.unwrap();
process::exit(1);
} else {
writeln!(stderr, "installer: {}: (non-fatal) missing cookbook key: {}", key_path.display(), err).unwrap();
writeln!(
stderr,
"installer: {}: (non-fatal) missing cookbook key: {}",
key_path.display(),
err
)
.unwrap();
None
}
}
}
} else {
None
};
if let Some(path) = parser.args.get(0) {
if let Err(err) = redox_installer::install(config, path, cookbook, parser.found("live")) {
if let Err(err) = redox_installer::install(config, path, cookbook, parser.found("live"))
{
writeln!(stderr, "installer: failed to install: {}", err).unwrap();
process::exit(1);
}
......
#[derive(Clone, Debug, Default, Deserialize)]
pub struct GeneralConfig {
pub prompt: bool,
// Allow filesystem config to select recipe or package
#[serde(skip)]
pub cooking: Option<bool>,
// Allow config to specify cookbook recipe or binary package as default
pub repo_binary: Option<bool>,
}
......@@ -104,9 +104,10 @@ fn install_packages<S: AsRef<str>>(config: &Config, dest: &str, cookbook: Option
let pkgar_path = format!("{}/{}/repo/{}/{}.pkgar",
env::current_dir().unwrap().to_string_lossy(),
cookbook.as_ref(), target, packagename);
let from_remote = match (config.general.cooking, package) {
let from_remote = match (config.general.repo_binary, package) {
(Some(true), PackageConfig::Empty) => true,
(Some(true), PackageConfig::Spec { version: None, git: None, path: None }) => true,
(_, PackageConfig::Build(rule)) if rule == "binary" => true,
_ => false
};
if from_remote {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment