From ad54d088d525f7e458756010d515758a15534584 Mon Sep 17 00:00:00 2001 From: Ron Williams Date: Fri, 16 Aug 2024 23:26:25 -0700 Subject: [PATCH] Add list_packages binary --- Cargo.toml | 4 +++ src/bin/list_packages.rs | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/bin/list_packages.rs diff --git a/Cargo.toml b/Cargo.toml index 20e92a41d6..101af50957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/bin/list_packages.rs b/src/bin/list_packages.rs new file mode 100644 index 0000000000..f5f6245d88 --- /dev/null +++ b/src/bin/list_packages.rs @@ -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); + } + } + } + } +}