Verified Commit 5c93eccd authored by Morten Linderud's avatar Morten Linderud 🏄
Browse files

lib: Implement 'only' that creates a dependency chain from stdin

When building closed loops of packages you sometime don't want the
entire chain to be resolved to just figure out the order of 5 packages.
This implement `--only` which resolves the chain and ensures only the
packages from stdin are included in the output chain.

This is useful for rebuild lists or when building tight loops of

    $ arch-rebuild-order -o cmake meson jsoncpp
    meson jsoncpp cmake
    $ arch-rebuild-order -o jsoncpp meson cmake
    meson jsoncpp cmake

Signed-off-by: Morten Linderud's avatarMorten Linderud <>
parent 70b24de6
Pipeline #13990 failed with stages
in 1 minute and 28 seconds
......@@ -22,4 +22,8 @@ pub struct Args {
/// Write a dotfile into the given file
#[structopt(short, long)]
pub dotfile: Option<String>,
/// Only use the pkgnames provided as input
#[structopt(short, long)]
pub only: bool,
......@@ -79,6 +79,7 @@ pub fn run(
dbpath: Option<String>,
repos: Vec<String>,
dotfile: Option<String>,
only: bool,
) -> Result<String> {
let pacman = match dbpath {
Some(path) => alpm::Alpm::new(ROOT_DIR, &path),
......@@ -165,15 +166,14 @@ pub fn run(
// shows it as last package
let mut output = String::new();
for elem in rebuild_order_packages.iter() {
output.push(' ');
// We only retain the packages we want to when using `--only`
// This logic is hard to parse because retain is an inverse filter,
// thus we use the negated form of: only && !pkgnames.contains(&pkg.to_string()
rebuild_order_packages.retain(|pkg| !only || pkgnames.contains(&pkg.to_string()));
if let Some(filename) = dotfile {
write_dotfile(filename, graph)?;
Ok(rebuild_order_packages.join(" "))
......@@ -4,7 +4,13 @@ use arch_rebuild_order::args::Args;
fn main() {
let args = Args::from_args();
match arch_rebuild_order::run(args.pkgnames, args.dbpath, args.repos, args.dotfile) {
match arch_rebuild_order::run(
) {
Ok(output) => {
println!("{}", output);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment