diff --git a/Cargo.lock b/Cargo.lock index aa56527..db1370f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,117 +24,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef417f821ef79296ed89405aea025a756f5ab48b5f7a47db6698f3f3da4f1bc5" [[package]] -name = "diml" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1dfab373d3ddb0edf9436ab9526f74228cc34daf40879231ab899f13d2e766" - -[[package]] -name = "equivalent" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" - -[[package]] -name = "fixedbitset" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5905ec755cc8386d7928353e4d356d2be3e89e81e5ca01fe630a1ca4d08dc175" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash", -] - -[[package]] -name = "indexmap" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" -dependencies = [ - "equivalent", - "hashbrown", -] - -[[package]] -name = "petgraph" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" -dependencies = [ - "fixedbitset", - "hashbrown", - "indexmap", - "serde", -] - -[[package]] -name = "proc-macro2" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "serde" -version = "1.0.229" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" -dependencies = [ - "serde_core", -] - -[[package]] -name = "serde_core" -version = "1.0.229" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.229" +name = "dagis" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "3fd9ff595b2ca4e5be81234b17cc53efb051562923f4ef1087dfb38201f89ad1" [[package]] -name = "syn" -version = "3.0.10" +name = "diml" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "ec1dfab373d3ddb0edf9436ab9526f74228cc34daf40879231ab899f13d2e766" [[package]] name = "task-commander" @@ -143,13 +42,6 @@ dependencies = [ "antex", "clars", "cli-assert", + "dagis", "diml", - "indexmap", - "petgraph", ] - -[[package]] -name = "unicode-ident" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" diff --git a/Cargo.toml b/Cargo.toml index 3265894..e78630c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,8 @@ include = [ [dependencies] antex = "0.2.6" clars = "0.5.0" +dagis = "0.1.0" diml = "0.2.1" -petgraph = "0.8.3" -# indexmap lowered because of petgraph - remove when petgraph upgrades -indexmap = "=2.6.0" [dev-dependencies] cli-assert = "0.1.13" diff --git a/src/tasks.rs b/src/tasks.rs index dfa60ee..fe3c797 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -4,9 +4,7 @@ use super::errors::{ }; use crate::command::execute; use antex::{ColorMode, StyledText, Text}; -use petgraph::Graph; -use petgraph::algo::toposort; -use petgraph::graph::NodeIndex; +use dagis::TypedDiGraph; use std::collections::{BTreeMap, HashMap}; use std::process::ExitStatus; @@ -296,36 +294,30 @@ impl Tasks { /// Sorts tasks topologically, detect non-existing subtasks and dependency cycles. fn sort_tasks_topologically(tasks: &Self) -> Result> { - let mut graph = Graph::::new(); - let mut name_by_index: HashMap = HashMap::new(); - let mut index_by_name: HashMap = HashMap::new(); + let mut graph = TypedDiGraph::::default(); + let mut vertex_by_name: HashMap = HashMap::new(); // Add all nodes to the graph. for (name, _) in tasks { - let node_index = graph.add_node(name.to_owned()); - name_by_index.insert(node_index, name.to_owned()); - index_by_name.insert(name.to_owned(), node_index); + let node_index = graph.vertex(name.to_owned()); + vertex_by_name.insert(name.to_owned(), node_index); } // Add directed edges to the graph, from child node to parent node. for (name, task) in tasks { - let parent_index = index_by_name.get(name).copied().unwrap(); + let parent_vertex = vertex_by_name.get(name).copied().unwrap(); for action in &task.actions { if let Action::Task(name) = action { - let Some(child_index) = index_by_name.get(name).copied() else { + let Some(child_vertex) = vertex_by_name.get(name).copied() else { return Err(err_task_not_found(name.to_owned())); }; - graph.add_edge(child_index, parent_index, ()); + graph.edge(child_vertex, parent_vertex); } } } // Sort topologically, detect cycles. - match toposort(&graph, None) { - Ok(indexes) => Ok(indexes - .iter() - .map(|index| name_by_index.get(index).cloned().unwrap()) - .collect()), - Err(cycle) => Err(err_dependency_cycle( - name_by_index.get(&cycle.node_id()).cloned().unwrap(), - )), + if graph.acyclic() { + Ok(graph.sort()) + } else { + Err(err_dependency_cycle(graph.cycle()[0].clone())) } } diff --git a/tests/dependency_cycle/mod.rs b/tests/dependency_cycle/mod.rs index d5ff02f..71f6773 100644 --- a/tests/dependency_cycle/mod.rs +++ b/tests/dependency_cycle/mod.rs @@ -5,6 +5,6 @@ fn _0001() { .failure() .code(1) .stdout("") - .stderr("error: dependency cycle for task: uncle\n") + .stderr("error: dependency cycle for task: child\n") .execute(); }