Skip to content
Merged
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
32 changes: 32 additions & 0 deletions e2e/tasks/test_task_depends_post
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# ensures depends_post and depends can be used on separate tasks
cat <<EOF >mise.toml
[tasks.one]
run = "echo one"

[tasks.two]
depends = ["one"]
run = "echo two"

[tasks.three]
depends_post = ["two"]
run = "echo three"
EOF
assert "mise task deps" "one
three
two
├── three
└── one"
assert "mise run three"

# TODO: this does not work with how mise is designed currently. Tasks can only ever be run once per run session. This will require hefty refactoring if it is ever supported
# uses depends and depends_post on the same task
#cat <<EOF >mise.toml
#tasks."util:donothing" = ""
#[tasks.hi]
#depends = "util:donothing"
#run = "echo hi"
#depends_post = "util:donothing"
#EOF
#assert "mise run hi"
6 changes: 6 additions & 0 deletions src/task/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl Deps {
let mut graph = DiGraph::new();
let mut indexes = HashMap::new();
let mut stack = vec![];
let mut seen = HashSet::new();

let mut add_idx = |task: &Task, graph: &mut DiGraph<Task, ()>| {
*indexes
Expand All @@ -45,6 +46,10 @@ impl Deps {
.flatten_ok()
.collect::<eyre::Result<Vec<_>>>()?;
while let Some(a) = stack.pop() {
if seen.contains(&a) {
// prevent infinite loop
continue;
}
let a_idx = add_idx(&a, &mut graph);
let (pre, post) = a.resolve_depends(&all_tasks_to_run)?;
for b in pre {
Expand All @@ -57,6 +62,7 @@ impl Deps {
graph.update_edge(b_idx, a_idx, ());
stack.push(b.clone());
}
seen.insert(a);
}
let (tx, _) = channel::unbounded();
let sent = HashSet::new();
Expand Down
5 changes: 4 additions & 1 deletion src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ impl Task {
.filter_ok(|t| t.name != self.name)
.collect::<Result<Vec<_>>>()?;
for dep in depends.clone() {
depends.extend(dep.all_depends()?);
let mut extra = dep.all_depends()?;
extra.retain(|t| t.name != self.name); // prevent depending on ourself
depends.extend(extra);
}
let depends = depends.into_iter().unique().collect();
Ok(depends)
}

Expand Down
Loading