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
125125 os . with_scope do
126126 arch . with_scope do
127127 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? )
131129
132130 b = pkgs . reduce ( nil ) do |c , p |
133131 if p . broken?
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3+ require "tsort"
4+
35module Pgpm
46 class Package
57 module Dependencies
@@ -40,6 +42,33 @@ def all_requirements
4042 requires . flat_map { |r | [ r , *r . all_requirements ] } . uniq
4143 end
4244
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+
4372 def c_files_present?
4473 Dir . glob ( "*.c" , base : source ) . any?
4574 end
You can’t perform that action at this time.
0 commit comments