Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serial-buildorder argument to the build-tree #419

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,24 @@ pub fn cli() -> Command {
.required(false)
.long("dot")
.help("Output the dependency DAG in the Graphviz DOT format")
.conflicts_with("serial-buildorder")
)
.arg(Arg::new("serial-buildorder")
.action(ArgAction::SetTrue)
.required(false)
.long("serial-buildorder")
.help("Output the dependencies in a serial build order (flattened tree)")
.long_help(indoc::indoc!(r#"
A serial build order ensures that dependencies are built one at a time
in a specific sequence. This approach follows a reversed topological ordering,
where dependencies (or children) are listed and built first. Each dependency
must be fully built before the next one begins, ensuring all components are
available when needed.

Keep in mind that the actual build order remains parallel, this serialized
output is mainly useful for debugging purposes.
"#))
.conflicts_with("dot")
)
)

Expand Down
15 changes: 15 additions & 0 deletions src/commands/tree_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub async fn tree_of(matches: &ArgMatches, repo: Repository, config: &Configurat

let dot = matches.get_flag("dot");

let serial_buildorder = matches.get_flag("serial-buildorder");

repo.packages()
.filter(|p| pname.as_ref().map(|n| p.name() == n).unwrap_or(true))
.filter(|p| {
Expand Down Expand Up @@ -92,6 +94,19 @@ pub async fn tree_of(matches: &ArgMatches, repo: Repository, config: &Configurat
);

println!("{:?}", dot);
Ok(())
} else if serial_buildorder {
let petgraph: DiGraph<Package, DependencyType> = (*dag.dag()).clone().into();

let topo_sorted = petgraph::algo::toposort(&petgraph, None)
ammernico marked this conversation as resolved.
Show resolved Hide resolved
.map_err(|_| Error::msg("Cyclic dependency found!"))?;
ammernico marked this conversation as resolved.
Show resolved Hide resolved

for node in topo_sorted.iter().rev() {
let package = petgraph.node_weight(*node).unwrap();
println!("{}", package.clone().display_name_version());
}
println!();

Ok(())
} else {
let stdout = std::io::stdout();
Expand Down