|
4 | 4 | require "json" |
5 | 5 | require "tsort" |
6 | 6 | require "utils" |
| 7 | +require "utils/topological_hash" |
7 | 8 | require "utils/output" |
8 | 9 | require "bundle/package_type" |
9 | 10 | require "trust" |
@@ -426,24 +427,27 @@ def sort!(formulae) |
426 | 427 | raise "formulae_by_full_name is nil" if @formulae_by_full_name.nil? |
427 | 428 | raise "formulae_by_name is nil" if @formulae_by_name.nil? |
428 | 429 |
|
429 | | - @formulae = topo.tsort |
430 | | - .map { |name| @formulae_by_full_name[name] || @formulae_by_name[name] } |
431 | | - .uniq { |f| f[:full_name] } |
432 | | - rescue TSort::Cyclic => e |
433 | | - e.message =~ /\["([^"]*)".*"([^"]*)"\]/ |
434 | | - cycle_first = Regexp.last_match(1) |
435 | | - cycle_last = Regexp.last_match(2) |
436 | | - odie e.message if !cycle_first || !cycle_last |
437 | | - |
438 | | - odie <<~EOS |
439 | | - Formulae dependency graph sorting failed (likely due to a circular dependency): |
440 | | - #{cycle_first}: #{topo[cycle_first] if topo} |
441 | | - #{cycle_last}: #{topo[cycle_last] if topo} |
442 | | - Please run the following commands and try again: |
443 | | - brew update |
444 | | - brew uninstall --ignore-dependencies --force #{cycle_first} #{cycle_last} |
445 | | - brew install #{cycle_first} #{cycle_last} |
446 | | - EOS |
| 430 | + # Stale keg-tab dependency data can form a cycle the live graph does not |
| 431 | + # have (Homebrew/homebrew-bundle#1513), so warn and continue rather than |
| 432 | + # aborting the whole bundle. |
| 433 | + sorted = topo.tsort_with_cycles do |cycles| |
| 434 | + cyclic = cycles.flatten |
| 435 | + .filter_map { |name| @formulae_by_full_name[name] || @formulae_by_name[name] } |
| 436 | + .uniq { |f| f[:full_name] } |
| 437 | + .map { |f| f[:full_name] } |
| 438 | + opoo <<~EOS |
| 439 | + Formulae dependency graph sorting found a circular dependency: |
| 440 | + #{cyclic.join(", ")} |
| 441 | + This is usually caused by stale dependency data in installed keg tabs. |
| 442 | + If it persists, run the following commands and try again: |
| 443 | + brew update |
| 444 | + brew uninstall --ignore-dependencies --force #{cyclic.join(" ")} |
| 445 | + brew install #{cyclic.join(" ")} |
| 446 | + EOS |
| 447 | + end |
| 448 | + |
| 449 | + @formulae = sorted.filter_map { |name| @formulae_by_full_name[name] || @formulae_by_name[name] } |
| 450 | + .uniq { |f| f[:full_name] } |
447 | 451 | end |
448 | 452 | end |
449 | 453 |
|
@@ -773,6 +777,7 @@ def upgrade_formula!(verbose:, force:) |
773 | 777 | class Topo < Hash |
774 | 778 | extend T::Generic |
775 | 779 | include TSort |
| 780 | + include Utils::CycleTolerantTSort |
776 | 781 |
|
777 | 782 | K = type_member { { fixed: String } } |
778 | 783 | V = type_member { { fixed: T::Array[String] } } |
|
0 commit comments