Merge branch 'package-lister' into 'master'

Add list_packages binary

See merge request redox-os/installer!36
This commit is contained in:
Jeremy Soller
2024-08-17 23:58:19 +00:00
2 changed files with 78 additions and 0 deletions
+4
View File
@@ -15,6 +15,10 @@ path = "src/bin/installer.rs"
name = "redox_installer_tui"
path = "src/bin/installer_tui.rs"
[[bin]]
name = "list_packages"
path = "src/bin/list_packages.rs"
[lib]
name = "redox_installer"
path = "src/lib.rs"
+74
View File
@@ -0,0 +1,74 @@
/// List packages for compilation, skip binary packages to be downloaded
extern crate arg_parser;
extern crate redox_installer;
extern crate serde;
extern crate toml;
use std::io::Write;
use std::path::Path;
use std::{env, io, process};
use arg_parser::ArgParser;
use redox_installer::{Config, PackageConfig};
fn main() {
let stderr = io::stderr();
let mut stderr = stderr.lock();
let mut parser = ArgParser::new(4)
.add_opt("c", "config")
.add_flag(&["r", "repo-binary"]);
parser.parse(env::args());
// 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 = if let Some(path) = parser.get_opt("config") {
match Config::from_file(Path::new(&path)) {
Ok(config) => config,
Err(err) => {
writeln!(stderr, "installer: {err}").unwrap();
process::exit(1);
}
}
} else {
redox_installer::Config::default()
};
// Get toml of merged config
let merged_toml = toml::to_string_pretty(&config).unwrap();
// Add filesystem.toml to config
config.files.push(redox_installer::FileConfig {
path: "filesystem.toml".to_string(),
data: merged_toml,
..Default::default()
});
// Add command line flags to config, command line takes priority
if repo_binary {
config.general.repo_binary = Some(true);
}
// List the packages that should be fetched or built by the cookbook
for (packagename, package) in &config.packages {
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);
}
}
}
}
}