From 02c7465b2c465c4e8902943972ed5acaf9e411d0 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Oct 2023 10:47:45 -0700 Subject: [PATCH 1/3] Fix cycle. --- ...n_test__errors_for_cycle_in_task_deps.snap | 3 +- crates/core/dep-graph/src/dep_graph.rs | 51 +++++++++++-------- crates/core/dep-graph/tests/dep_graph_test.rs | 3 +- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/crates/cli/tests/snapshots/run_test__errors_for_cycle_in_task_deps.snap b/crates/cli/tests/snapshots/run_test__errors_for_cycle_in_task_deps.snap index 04e40ba23ff..bbac63af8b6 100644 --- a/crates/cli/tests/snapshots/run_test__errors_for_cycle_in_task_deps.snap +++ b/crates/cli/tests/snapshots/run_test__errors_for_cycle_in_task_deps.snap @@ -2,8 +2,7 @@ source: crates/cli/tests/run_test.rs expression: assert.output() --- -Error: × A dependency cycle has been detected for RunTarget(depsA:taskCycle) → - │ RunTarget(depsB:taskCycle) → RunTarget(depsC:taskCycle). +Error: × A dependency cycle has been detected for RunTarget(depsC:taskCycle). diff --git a/crates/core/dep-graph/src/dep_graph.rs b/crates/core/dep-graph/src/dep_graph.rs index bc48cec9b28..2d55a71c113 100644 --- a/crates/core/dep-graph/src/dep_graph.rs +++ b/crates/core/dep-graph/src/dep_graph.rs @@ -180,27 +180,36 @@ impl DepGraph { #[track_caller] fn detect_cycle(&self) -> miette::Result<()> { - use petgraph::algo::kosaraju_scc; - - let scc = kosaraju_scc(&self.graph); - - // Remove the sync workspace node - let scc = scc - .into_iter() - .filter(|list| !(list.len() == 1 && list[0].index() == 0)) - .collect::>>(); - - // The cycle is always the last sequence in the list - let Some(cycle) = scc.last() else { - return Err(DepGraphError::CycleDetected("(unknown)".into()).into()); - }; - - let path = cycle - .iter() - .filter_map(|i| self.get_node_from_index(i).map(|n| n.label())) - .collect::>() - .join(" → "); + // use petgraph::algo::kosaraju_scc; + + // let scc = kosaraju_scc(&self.graph); + + // // Remove the sync workspace node + // let scc = scc + // .into_iter() + // .filter(|list| !(list.len() == 1 && list[0].index() == 0)) + // .collect::>>(); + + // // The cycle is always the last sequence in the list + // let Some(cycle) = scc.last() else { + // return Err(DepGraphError::CycleDetected("(unknown)".into()).into()); + // }; + + // let path = cycle + // .iter() + // .filter_map(|i| self.get_node_from_index(i).map(|n| n.label())) + // .collect::>() + // .join(" → "); + + // Err(DepGraphError::CycleDetected(path).into()) + + if let Err(error) = toposort(&self.graph, None) { + return Err(DepGraphError::CycleDetected( + self.get_node_from_index(&error.node_id()).unwrap().label(), + ) + .into()); + } - Err(DepGraphError::CycleDetected(path).into()) + Ok(()) } } diff --git a/crates/core/dep-graph/tests/dep_graph_test.rs b/crates/core/dep-graph/tests/dep_graph_test.rs index 0c51710324a..33115869642 100644 --- a/crates/core/dep-graph/tests/dep_graph_test.rs +++ b/crates/core/dep-graph/tests/dep_graph_test.rs @@ -127,7 +127,8 @@ fn sort_batches(batches: BatchedTopoSort) -> BatchedTopoSort { } #[tokio::test] -#[should_panic(expected = "A dependency cycle has been detected for RunTarget(cycle:a)")] +// #[should_panic(expected = "A dependency cycle has been detected for RunTarget(cycle:a)")] +#[should_panic(expected = "A dependency cycle has been detected for RunTarget(cycle:c)")] async fn detects_cycles() { let (_workspace, projects, _sandbox) = create_tasks_project_graph().await; From 13b49023cfc6806f3d34ff251974f33eef785f4f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Oct 2023 10:48:25 -0700 Subject: [PATCH 2/3] Update changelog. --- packages/cli/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index d4bddb63710..6ef5638268d 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -10,6 +10,12 @@ - More accurately monitors signals (ctrl+c) and shutdowns. - Tasks can now be configured with a timeout. +## Unreleased + +#### 🐞 Fixes + +- Temporarily fixed the "A dependency cycle has been detected for (unknown)" issue. + ## 1.14.4 #### 🐞 Fixes From 7a55098ff2b9612c918028419477608cb38f17a5 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 5 Oct 2023 10:50:32 -0700 Subject: [PATCH 3/3] Add patch. --- .yarn/versions/8aeb4131.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .yarn/versions/8aeb4131.yml diff --git a/.yarn/versions/8aeb4131.yml b/.yarn/versions/8aeb4131.yml new file mode 100644 index 00000000000..1f2a5d9c201 --- /dev/null +++ b/.yarn/versions/8aeb4131.yml @@ -0,0 +1,9 @@ +releases: + "@moonrepo/cli": patch + "@moonrepo/core-linux-arm64-gnu": patch + "@moonrepo/core-linux-arm64-musl": patch + "@moonrepo/core-linux-x64-gnu": patch + "@moonrepo/core-linux-x64-musl": patch + "@moonrepo/core-macos-arm64": patch + "@moonrepo/core-macos-x64": patch + "@moonrepo/core-windows-x64-msvc": patch