diff options
author | Carl Lerche <carllerche@mac.com> | 2010-06-04 14:18:23 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-06-04 14:18:23 -0700 |
commit | a9b3f285411bcd1b26511a773610007d027ce4bc (patch) | |
tree | 93189d3a7fecb16b77a09e4afa3efccb2db8a54f /lib/bundler | |
parent | 0ccfdd8e49a4641edad0dcde5d4111bad06c8e00 (diff) | |
download | bundler-a9b3f285411bcd1b26511a773610007d027ce4bc.tar.gz |
Refactor SpecSet#for
Diffstat (limited to 'lib/bundler')
-rw-r--r-- | lib/bundler/definition.rb | 3 | ||||
-rw-r--r-- | lib/bundler/lazy_specification.rb | 6 | ||||
-rw-r--r-- | lib/bundler/spec_set.rb | 47 |
3 files changed, 34 insertions, 22 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index a1a7f43f..b451c449 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -32,6 +32,7 @@ module Bundler def initialize(lockfile, dependencies, sources, unlock) @dependencies, @sources, @unlock = dependencies, sources, unlock + @specs = nil if lockfile && File.exists?(lockfile) locked = LockfileParser.new(File.read(lockfile)) @@ -193,7 +194,7 @@ module Bundler # Run a resolve against the locally available gems resolve = Resolver.resolve(dependencies, idx, source_requirements, @last_resolve, platforms) - [resolve, resolve.__materialize__(type)] + [resolve, resolve.materialize(type, dependencies)] end def resolve_local_specs diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index d348b648..b8800e5d 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -27,6 +27,12 @@ module Bundler @name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version)) end + def match_platform(p) + platform.nil? or p == platform or + (p != Gem::Platform::RUBY and p =~ platform) or + (p == Gem::Platform::RUBY and platform.to_generic == Gem::Platform::RUBY) + end + def to_lock if platform == Gem::Platform::RUBY or platform.nil? out = " #{name} (#{version})\n" diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 9d0a771e..d5eccfbb 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -18,22 +18,38 @@ module Bundler # TODO: Handle platform filtering def for(deps, skip = []) - specs = {} - deps.each do |dep| - name = dep.respond_to?(:name) ? dep.name : dep - current = lookup[name].first - append_subgraph(specs, current, skip) + handled = {} + deps = deps.map { |d| d.respond_to?(:name) ? d.name : d } + + until deps.empty? + dep = deps.shift + next if handled[dep] || skip.include?(dep) + specs = lookup[dep] + next if specs.empty? + specs.each do |s| + handled[s.name] = true + s.dependencies.each do |d| + next if d.type == :development + deps << d.name + end + end end - SpecSet.new(sorted.select { |s| specs[s.name] }) + SpecSet.new(sorted.select { |s| handled[s.name] }) end def valid_for?(deps) deps = deps.dup + handled = {} + until deps.empty? - specs = lookup[deps.shift.name] - return false unless specs.any? - specs.each { |s| deps.concat s.dependencies } + dep = deps.shift + unless dep.type == :development || handled[dep.name] + specs = lookup[dep.name] + return false unless specs.any? + handled[dep.name] = true + specs.each { |s| deps.concat s.dependencies } + end end true end @@ -48,7 +64,7 @@ module Bundler @specs.delete_if(&blk) end - def __materialize__(type) + def materialize(type, deps) materialized = @specs.map do |s| next s unless s.is_a?(LazySpecification) s.__materialize__(s.source.send(type)) @@ -58,17 +74,6 @@ module Bundler private - def append_subgraph(specs, current, skip) - return unless current - return if specs[current.name] || skip.include?(current.name) - specs[current.name] = true - current.dependencies.each do |dep| - next if dep.type == :development - s = lookup[dep.name].first - append_subgraph(specs, s, skip) - end - end - def sorted rake = @specs.find { |s| s.name == 'rake' } @sorted ||= ([rake] + tsort).compact.uniq |