summaryrefslogtreecommitdiff
path: root/lib/bundler/spec_set.rb
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-06-05 22:47:59 -0700
committerCarl Lerche <carllerche@mac.com>2010-06-05 22:47:59 -0700
commit89f1db5f7002bd5e9434a95c6dc53c3cb796970e (patch)
tree5d4b093d998ecde1c475bd05e93f2d74ec209220 /lib/bundler/spec_set.rb
parent19ad4e1b9a1cfcc5a9ccfd806f7a7a0069d1e9d9 (diff)
downloadbundler-89f1db5f7002bd5e9434a95c6dc53c3cb796970e.tar.gz
Make SpecSet#for smart about platforms
Diffstat (limited to 'lib/bundler/spec_set.rb')
-rw-r--r--lib/bundler/spec_set.rb60
1 files changed, 28 insertions, 32 deletions
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb
index 13239ef04f..6d7c229ea8 100644
--- a/lib/bundler/spec_set.rb
+++ b/lib/bundler/spec_set.rb
@@ -16,54 +16,47 @@ module Bundler
@specs.length
end
- # TODO: Handle platform filtering
- def for(deps, skip = [], platform_filter = false)
- handled = {}
- deps = deps.map { |d| d.respond_to?(:name) ? d.name : d }
+ def for(dependencies, skip = [], check = false)
+ handled, deps, specs = {}, [], []
+
+ dependencies.each do |d|
+ d.platforms.each do |p|
+ deps << DepProxy.new(d, p)
+ end
+ end
until deps.empty?
dep = deps.shift
- next if handled[dep] || skip.include?(dep)
- specs = lookup[dep]
- next if specs.empty?
+ next if handled[dep] || skip.include?(dep.name)
- if platform_filter
- specs = specs.sort_by { |s| s.platform.to_s == 'ruby' ? "\0" : s.platform.to_s }.reverse
- specs = Array(specs.find { |s| Gem::Platform.match(s.platform) })
+ spec = lookup[dep.name].find do |s|
+ s.match_platform(dep.__platform)
end
- specs.each do |s|
- handled[s.name] ||= []
- handled[s.name] << s
- s.dependencies.each do |d|
+ handled[dep] = true
+
+ if spec
+ specs << spec
+
+ spec.dependencies.each do |d|
next if d.type == :development
- deps << d.name
+ deps << DepProxy.new(d, dep.__platform)
end
+ elsif check
+ return false
end
end
- SpecSet.new(handled.values.flatten)
+ check ? true : SpecSet.new(specs)
end
def valid_for?(deps)
- deps = deps.dup
- handled = {}
-
- until deps.empty?
- 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
+ self.for(deps, [], true)
end
def [](key)
key = key.name if key.respond_to?(:name)
- lookup[key].sort_by { |s| s.platform.to_s == 'ruby' ? "\0" : s.platform.to_s }
+ lookup[key].reverse
end
def to_a
@@ -75,7 +68,7 @@ module Bundler
end
def materialize(type, deps)
- materialized = self.for(deps, [], true).to_a
+ materialized = self.for(deps, []).to_a
materialized.map! do |s|
next s unless s.is_a?(LazySpecification)
s.__materialize__(s.source.send(type))
@@ -93,7 +86,10 @@ module Bundler
def lookup
@lookup ||= begin
lookup = Hash.new { |h,k| h[k] = [] }
- @specs.each do |s|
+ specs = @specs.sort_by do |s|
+ s.platform.to_s == 'ruby' ? "\0" : s.platform.to_s
+ end
+ specs.reverse_each do |s|
lookup[s.name] << s
end
lookup