Permalink
Browse files

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

  • Loading branch information...
1 parent 3a383f8 commit 529d792205b2cf66cad7179f32baee391b46e545 Carl Lerche committed Mar 10, 2010
Showing with 102 additions and 14 deletions.
  1. +1 −0 lib/bundler.rb
  2. +1 −3 lib/bundler/installer.rb
  3. +1 −9 lib/bundler/resolver.rb
  4. +34 −0 lib/bundler/spec_set.rb
  5. +11 −1 spec/install/gems_spec.rb
  6. +54 −1 spec/support/builders.rb
View
@@ -17,6 +17,7 @@ module Bundler
autoload :Runtime, 'bundler/runtime'
autoload :Settings, 'bundler/settings'
autoload :SharedHelpers, 'bundler/shared_helpers'
+ autoload :SpecSet, 'bundler/spec_set'
autoload :Source, 'bundler/source'
autoload :Specification, 'bundler/specification'
autoload :UI, 'bundler/ui'
View
@@ -26,9 +26,7 @@ def run(options)
next
end
- # unless spec.source.is_a?(Source::SystemGems)
- Bundler.ui.info "Installing #{spec.name} (#{spec.version}) from #{spec.source} "
- # end
+ Bundler.ui.info "Installing #{spec.name} (#{spec.version}) from #{spec.source} "
spec.source.install(spec)
View
@@ -52,15 +52,7 @@ def self.resolve(requirements, index, source_requirements = {})
raise VersionConflict, "No compatible versions could be found for required dependencies:\n #{output}"
nil
end
- if result
- # Dependency ordering was busted anyway. This will be revisted in 0.10
- ordered = []
- ordered << result['rake']
- ordered.concat result.values
- ordered.compact!
- ordered.uniq!
- ordered
- end
+ SpecSet.new(result.values)
end
def initialize(index, source_requirements)
View
@@ -0,0 +1,34 @@
+require 'tsort'
+
+module Bundler
+ class SpecSet
+ include TSort, Enumerable
+
+ def initialize(specs)
+ @specs = specs.sort_by { |s| s.name }
+ @lookup = Hash.new do |h,k|
+ h[k] = specs.find { |s| s.name == k }
+ end
+ @sorted = ([@lookup['rake']] + tsort).compact.uniq
+ end
+
+ def each
+ @sorted.each { |s| yield s }
+ end
+
+ def length
+ @specs.length
+ end
+
+ def tsort_each_node
+ @specs.each { |s| yield s }
+ end
+
+ def tsort_each_child(s)
+ s.dependencies.sort_by { |d| d.name }.each do |d|
+ next if d.type == :development
+ yield @lookup[d.name]
+ end
+ end
+ end
+end
View
@@ -394,7 +394,7 @@
end
end
- describe "native dependencies" do
+ describe "install time dependencies" do
it "installs gems with implicit rake dependencies" do
install_gemfile <<-G
source "file://#{gem_repo1}"
@@ -411,6 +411,16 @@
R
out.should == "YES\nYES"
end
+
+ it "works with crazy rubygem plugin stuff" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "net_c"
+ gem "net_e"
+ G
+
+ should_be_installed "net_a 1.0", "net_b 1.0", "net_c 1.0", "net_d 1.0", "net_e 1.0"
+ end
end
describe "with groups" do
View
@@ -134,6 +134,59 @@ def build_repo1
s.write "lib/bundler/omg.rb", ""
s.write "lib/rubygems_plugin.rb", "require 'bundler/omg' ; puts 'FAIL'"
end
+
+ # Test comlicated gem dependencies for install
+ build_gem "net_a" do |s|
+ s.add_dependency "net_b"
+ s.add_dependency "net_build_extensions"
+ s.write "lib/rubygems_plugin.rb", <<-R
+ require 'net_b'
+ require 'net_a'
+ R
+ end
+
+ build_gem "net_b" do |s|
+ s.write "lib/rubygems_plugin.rb", <<-G
+ require 'net_b'
+ G
+ end
+
+ build_gem "net_build_extensions" do |s|
+ s.add_dependency "rake"
+ s.extensions << "Rakefile"
+ s.write "Rakefile", <<-RUBY
+ task :default do
+ path = File.expand_path("../lib", __FILE__)
+ FileUtils.mkdir_p(path)
+ File.open("\#{path}/net_build_extensions.rb", "w") do |f|
+ f.puts "NET_BUILD_EXTENSIONS = 'YES'"
+ end
+ end
+ RUBY
+ end
+
+ build_gem "net_c" do |s|
+ s.add_dependency "net_a"
+ s.add_dependency "net_d"
+ s.write "lib/rubygems_plugin.rb", <<-G
+ require 'net_a'
+ require 'net_d'
+ require 'net_c'
+ G
+ end
+
+ build_gem "net_d" do |s|
+ s.write "lib/rubygems_plugin.rb", <<-G
+ require 'net_d'
+ G
+ end
+
+ build_gem "net_e" do |s|
+ s.add_dependency "net_d"
+ s.write "lib/rubygems_plugin.rb", <<-G
+ require 'net_d'
+ G
+ end
end
end
@@ -275,7 +328,7 @@ def method_missing(*args, &blk)
@spec.send(*args, &blk)
end
- def write(file, source)
+ def write(file, source = "")
@files[file] = source
end

0 comments on commit 529d792

Please sign in to comment.