Skip to content
This repository
Browse code

Use tsort to order specifications. It makes teh crazy work.

  • Loading branch information...
commit 529d792205b2cf66cad7179f32baee391b46e545 1 parent 3a383f8
authored March 09, 2010
1  lib/bundler.rb
@@ -17,6 +17,7 @@ module Bundler
17 17
   autoload :Runtime,             'bundler/runtime'
18 18
   autoload :Settings,            'bundler/settings'
19 19
   autoload :SharedHelpers,       'bundler/shared_helpers'
  20
+  autoload :SpecSet,             'bundler/spec_set'
20 21
   autoload :Source,              'bundler/source'
21 22
   autoload :Specification,       'bundler/specification'
22 23
   autoload :UI,                  'bundler/ui'
4  lib/bundler/installer.rb
@@ -26,9 +26,7 @@ def run(options)
26 26
           next
27 27
         end
28 28
 
29  
-        # unless spec.source.is_a?(Source::SystemGems)
30  
-          Bundler.ui.info "Installing #{spec.name} (#{spec.version}) from #{spec.source} "
31  
-        # end
  29
+        Bundler.ui.info "Installing #{spec.name} (#{spec.version}) from #{spec.source} "
32 30
 
33 31
         spec.source.install(spec)
34 32
 
10  lib/bundler/resolver.rb
@@ -52,15 +52,7 @@ def self.resolve(requirements, index, source_requirements = {})
52 52
         raise VersionConflict, "No compatible versions could be found for required dependencies:\n  #{output}"
53 53
         nil
54 54
       end
55  
-      if result
56  
-        # Dependency ordering was busted anyway. This will be revisted in 0.10
57  
-        ordered = []
58  
-        ordered << result['rake']
59  
-        ordered.concat result.values
60  
-        ordered.compact!
61  
-        ordered.uniq!
62  
-        ordered
63  
-      end
  55
+      SpecSet.new(result.values)
64 56
     end
65 57
 
66 58
     def initialize(index, source_requirements)
34  lib/bundler/spec_set.rb
... ...
@@ -0,0 +1,34 @@
  1
+require 'tsort'
  2
+
  3
+module Bundler
  4
+  class SpecSet
  5
+    include TSort, Enumerable
  6
+
  7
+    def initialize(specs)
  8
+      @specs  = specs.sort_by { |s| s.name }
  9
+      @lookup = Hash.new do |h,k|
  10
+        h[k] = specs.find { |s| s.name == k }
  11
+      end
  12
+      @sorted = ([@lookup['rake']] + tsort).compact.uniq
  13
+    end
  14
+
  15
+    def each
  16
+      @sorted.each { |s| yield s }
  17
+    end
  18
+
  19
+    def length
  20
+      @specs.length
  21
+    end
  22
+
  23
+    def tsort_each_node
  24
+      @specs.each { |s| yield s }
  25
+    end
  26
+
  27
+    def tsort_each_child(s)
  28
+      s.dependencies.sort_by { |d| d.name }.each do |d|
  29
+        next if d.type == :development
  30
+        yield @lookup[d.name]
  31
+      end
  32
+    end
  33
+  end
  34
+end
12  spec/install/gems_spec.rb
@@ -394,7 +394,7 @@
394 394
     end
395 395
   end
396 396
 
397  
-  describe "native dependencies" do
  397
+  describe "install time dependencies" do
398 398
     it "installs gems with implicit rake dependencies" do
399 399
       install_gemfile <<-G
400 400
         source "file://#{gem_repo1}"
@@ -411,6 +411,16 @@
411 411
       R
412 412
       out.should == "YES\nYES"
413 413
     end
  414
+
  415
+    it "works with crazy rubygem plugin stuff" do
  416
+      install_gemfile <<-G
  417
+        source "file://#{gem_repo1}"
  418
+        gem "net_c"
  419
+        gem "net_e"
  420
+      G
  421
+
  422
+      should_be_installed "net_a 1.0", "net_b 1.0", "net_c 1.0", "net_d 1.0", "net_e 1.0"
  423
+    end
414 424
   end
415 425
 
416 426
   describe "with groups" do
55  spec/support/builders.rb
@@ -134,6 +134,59 @@ def build_repo1
134 134
           s.write "lib/bundler/omg.rb", ""
135 135
           s.write "lib/rubygems_plugin.rb", "require 'bundler/omg' ; puts 'FAIL'"
136 136
         end
  137
+
  138
+        # Test comlicated gem dependencies for install
  139
+        build_gem "net_a" do |s|
  140
+          s.add_dependency "net_b"
  141
+          s.add_dependency "net_build_extensions"
  142
+          s.write "lib/rubygems_plugin.rb", <<-R
  143
+            require 'net_b'
  144
+            require 'net_a'
  145
+          R
  146
+        end
  147
+
  148
+        build_gem "net_b" do |s|
  149
+          s.write "lib/rubygems_plugin.rb", <<-G
  150
+            require 'net_b'
  151
+          G
  152
+        end
  153
+
  154
+        build_gem "net_build_extensions" do |s|
  155
+          s.add_dependency "rake"
  156
+          s.extensions << "Rakefile"
  157
+          s.write "Rakefile", <<-RUBY
  158
+            task :default do
  159
+              path = File.expand_path("../lib", __FILE__)
  160
+              FileUtils.mkdir_p(path)
  161
+              File.open("\#{path}/net_build_extensions.rb", "w") do |f|
  162
+                f.puts "NET_BUILD_EXTENSIONS = 'YES'"
  163
+              end
  164
+            end
  165
+          RUBY
  166
+        end
  167
+
  168
+        build_gem "net_c" do |s|
  169
+          s.add_dependency "net_a"
  170
+          s.add_dependency "net_d"
  171
+          s.write "lib/rubygems_plugin.rb", <<-G
  172
+            require 'net_a'
  173
+            require 'net_d'
  174
+            require 'net_c'
  175
+          G
  176
+        end
  177
+
  178
+        build_gem "net_d" do |s|
  179
+          s.write "lib/rubygems_plugin.rb", <<-G
  180
+            require 'net_d'
  181
+          G
  182
+        end
  183
+
  184
+        build_gem "net_e" do |s|
  185
+          s.add_dependency "net_d"
  186
+          s.write "lib/rubygems_plugin.rb", <<-G
  187
+            require 'net_d'
  188
+          G
  189
+        end
137 190
       end
138 191
     end
139 192
 
@@ -275,7 +328,7 @@ def method_missing(*args, &blk)
275 328
         @spec.send(*args, &blk)
276 329
       end
277 330
 
278  
-      def write(file, source)
  331
+      def write(file, source = "")
279 332
         @files[file] = source
280 333
       end
281 334
 

0 notes on commit 529d792

Please sign in to comment.
Something went wrong with that request. Please try again.