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

fix: the graph calculation with post_depends. #4539

Open
wants to merge 3 commits into
base: main
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
35 changes: 35 additions & 0 deletions e2e/tasks/test_task_depends_post_inf_loop
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# ensures depends_post on multiple tasks works.
cat <<EOF >mise.toml
[tasks.one]
run = "echo one"
depends_post=[
'two',
'three'
]

[tasks.two]
run = "echo two"

[tasks.three]
run = "echo three"
EOF

assert "mise task deps" "one
two
└── one
three
└── one"
assert "mise run one"

# 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"
10 changes: 9 additions & 1 deletion src/cli/tasks/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ impl TasksDeps {
///
fn print_deps_tree(&self, tasks: Vec<Task>) -> Result<()> {
let deps = Deps::new(tasks.clone())?;
let all_tasks_to_run = tasks
.iter()
.flat_map(|t| {
let (_, postdeps) = t.resolve_depends(&tasks).unwrap();
postdeps
})
.chain(tasks.clone())
.collect_vec();
// filter out nodes that are not selected
let start_indexes = deps.graph.node_indices().filter(|&idx| {
let task = &deps.graph[idx];
tasks.iter().any(|t| t.name == task.name)
all_tasks_to_run.iter().any(|t| t.name == task.name)
});
// iterate over selected graph nodes and print tree
for idx in start_indexes {
Expand Down
7 changes: 4 additions & 3 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ impl Task {
.flatten_ok()
.filter_ok(|t| tasks_to_run.contains(t))
.collect_vec();
let depends_post = tasks_to_run
let depends_post = self
.depends_post
.iter()
.flat_map(|t| t.depends_post.iter().map(|td| match_tasks(&tasks, td)))
.map(|td| match_tasks(&tasks, td))
.flatten_ok()
.filter_ok(|t| t.name != self.name)
.collect::<Result<Vec<_>>>()?;
.collect::<Result<_>>()?;
let depends = depends
.into_iter()
.chain(wait_for)
Expand Down
Loading