File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -125,9 +125,7 @@ module Pgpm
125
125
os.with_scope do
126
126
arch.with_scope do
127
127
selected_pgdist.with_scope do
128
- pkgs = pkgs.flat_map do |pkg|
129
- [pkg, *pkg.all_requirements]
130
- end.reject(&:contrib?)
128
+ pkgs = pkgs.flat_map(&:topologically_ordered_with_dependencies).uniq.reject(&:contrib?)
131
129
132
130
b = pkgs.reduce(nil) do |c, p|
133
131
if p.broken?
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require "tsort"
4
+
3
5
module Pgpm
4
6
class Package
5
7
module Dependencies
@@ -40,6 +42,33 @@ def all_requirements
40
42
requires.flat_map { |r| [r, *r.all_requirements] }.uniq
41
43
end
42
44
45
+ def topologically_ordered_with_dependencies
46
+ TopologicalPackageSorter.new([self, *all_requirements]).sorted_packages
47
+ end
48
+
49
+ class TopologicalPackageSorter
50
+ include TSort
51
+
52
+ def initialize(packages)
53
+ @packages = packages.each_with_object({}) do |pkg, hash|
54
+ hash[pkg.name] = pkg
55
+ end
56
+ end
57
+
58
+ def tsort_each_node(&block)
59
+ @packages.each_key(&block)
60
+ end
61
+
62
+ def tsort_each_child(node, &block)
63
+ package = @packages[node]
64
+ package.requires.each { |req| block.call(req) if @packages.key?(req) }
65
+ end
66
+
67
+ def sorted_packages
68
+ tsort.map { |name| @packages[name] }.reverse
69
+ end
70
+ end
71
+
43
72
def c_files_present?
44
73
Dir.glob("*.c", base: source).any?
45
74
end
You can’t perform that action at this time.
0 commit comments