From eb024410c5ea68984cd1e2278ed903a05dfe1ea5 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Wed, 18 Sep 2024 12:21:55 +0100 Subject: [PATCH] WIP Auto resolve cyclic USE conflicts by trying the first suggestion Signed-off-by: James Le Cuirot --- lib/_emerge/depgraph.py | 22 ++++++++++++++++----- lib/_emerge/resolver/circular_dependency.py | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/_emerge/depgraph.py b/lib/_emerge/depgraph.py index 2acd8f2e13..5bb486377a 100644 --- a/lib/_emerge/depgraph.py +++ b/lib/_emerge/depgraph.py @@ -9909,8 +9909,6 @@ def find_smallest_cycle(mergeable_nodes, local_priority_range): continue if not selected_nodes: - self._dynamic_config._circular_deps_for_display = mygraph - unsolved_cycle = False if self._dynamic_config._allow_backtracking: backtrack_infos = self._dynamic_config._backtrack_infos @@ -9935,11 +9933,25 @@ def find_smallest_cycle(mergeable_nodes, local_priority_range): ) if unsolved_cycle or not self._dynamic_config._allow_backtracking: + self._dynamic_config._circular_deps_for_display = mygraph self._dynamic_config._skip_restart = True + raise self._unknown_internal_error() else: - self._dynamic_config._need_restart = True - - raise self._unknown_internal_error() + handler = circular_dependency_handler(self, mygraph) + if handler.solutions: + pkg = list(handler.solutions.keys())[0] + parent, solution = list(handler.solutions[pkg])[0] + solution = list(solution)[0] + enabled = list(parent.use.enabled) + if solution[1]: + enabled.append(solution[0]) + else: + enabled.remove(solution[0]) + selected_nodes = [parent.with_use(enabled), pkg, parent] + else: + self._dynamic_config._circular_deps_for_display = mygraph + self._dynamic_config._need_restart = True + raise self._unknown_internal_error() # At this point, we've succeeded in selecting one or more nodes, so # reset state variables for leaf node selection. diff --git a/lib/_emerge/resolver/circular_dependency.py b/lib/_emerge/resolver/circular_dependency.py index 6c21423083..09b1afebfb 100644 --- a/lib/_emerge/resolver/circular_dependency.py +++ b/lib/_emerge/resolver/circular_dependency.py @@ -293,7 +293,7 @@ def _find_suggestions(self): " (This change might require USE changes on parent packages.)" ) suggestions.append(msg) - final_solutions.setdefault(pkg, set()).add(solution) + final_solutions.setdefault(pkg, set()).add((parent, solution)) return final_solutions, suggestions