summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/definition.rb24
-rw-r--r--lib/bundler/dependency.rb9
-rw-r--r--lib/bundler/dsl.rb3
-rw-r--r--lib/bundler/lazy_specification.rb8
-rw-r--r--lib/bundler/resolver.rb30
-rw-r--r--lib/bundler/resolver/spec_group.rb31
6 files changed, 75 insertions, 30 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index d6fbb0b5b7..3e5186039a 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -82,7 +82,11 @@ module Bundler
@lockfile_contents = Bundler.read_file(lockfile)
@locked_gems = LockfileParser.new(@lockfile_contents)
@locked_platforms = @locked_gems.platforms
- @platforms = @locked_platforms.dup
+ if Bundler.settings[:force_ruby_platform]
+ @platforms = [Gem::Platform::RUBY]
+ else
+ @platforms = @locked_platforms.dup
+ end
@locked_bundler_version = @locked_gems.bundler_version
@locked_ruby_version = @locked_gems.ruby_version
@@ -228,12 +232,13 @@ module Bundler
end
def current_dependencies
- dependencies.select(&:should_include?)
+ dependencies.select do |d|
+ d.should_include? && !d.gem_platforms(@platforms).empty?
+ end
end
def specs_for(groups)
- deps = dependencies.select {|d| (d.groups & groups).any? }
- deps.delete_if {|d| !d.should_include? }
+ deps = dependencies_for(groups)
specs.for(expand_dependencies(deps))
end
@@ -706,9 +711,6 @@ module Bundler
elsif dep.source
dep.source = sources.get(dep.source)
end
- if dep.source.is_a?(Source::Gemspec)
- dep.platforms.concat(@platforms.map {|p| Dependency::REVERSE_PLATFORM_MAP[p] }.flatten(1)).uniq!
- end
end
changes = false
@@ -907,10 +909,16 @@ module Bundler
deps
end
+ def dependencies_for(groups)
+ current_dependencies.reject do |d|
+ (d.groups & groups).empty?
+ end
+ end
+
def requested_dependencies
groups = requested_groups
groups.map!(&:to_sym)
- dependencies.reject {|d| !d.should_include? || (d.groups & groups).empty? }
+ dependencies_for(groups)
end
def source_requirements
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index 6c2642163e..26e5f3d1a5 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -74,15 +74,6 @@ module Bundler
:x64_mingw_26 => Gem::Platform::X64_MINGW,
}.freeze
- REVERSE_PLATFORM_MAP = {}.tap do |reverse_platform_map|
- PLATFORM_MAP.each do |key, value|
- reverse_platform_map[value] ||= []
- reverse_platform_map[value] << key
- end
-
- reverse_platform_map.each {|_, platforms| platforms.freeze }
- end.freeze
-
def initialize(name, version, options = {}, &blk)
type = options["type"] || :runtime
super(name, version, type)
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 99a369281a..bb92a28381 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -75,8 +75,7 @@ module Bundler
@gemspecs << spec
- gem_platforms = Bundler::Dependency::REVERSE_PLATFORM_MAP[Bundler::GemHelpers.generic_local_platform]
- gem spec.name, :name => spec.name, :path => path, :glob => glob, :platforms => gem_platforms
+ gem spec.name, :name => spec.name, :path => path, :glob => glob
group(development_group) do
spec.development_dependencies.each do |dep|
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index 32c8bb9557..7a6f5614ef 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -46,6 +46,14 @@ module Bundler
identifier == other.identifier
end
+ def eql?(other)
+ identifier.eql?(other.identifier)
+ end
+
+ def hash
+ identifier.hash
+ end
+
def satisfies?(dependency)
@name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version))
end
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index c7caf01c7d..2374ed3e5a 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -146,7 +146,26 @@ module Bundler
@gem_version_promoter.sort_versions(dependency, spec_groups)
end
end
- search.select {|sg| sg.for?(platform) }.each {|sg| sg.activate_platform!(platform) }
+ selected_sgs = []
+ search.each do |sg|
+ next unless sg.for?(platform)
+ # Add a spec group for "non platform specific spec" as the fallback
+ # spec group.
+ sg_ruby = sg.copy_for(Gem::Platform::RUBY)
+ selected_sgs << sg_ruby if sg_ruby
+ sg_all_platforms = nil
+ all_platforms = @platforms + [platform]
+ sorted_all_platforms = self.class.sort_platforms(all_platforms)
+ sorted_all_platforms.reverse_each do |other_platform|
+ if sg_all_platforms.nil?
+ sg_all_platforms = sg.copy_for(other_platform)
+ else
+ sg_all_platforms.activate_platform!(other_platform)
+ end
+ end
+ selected_sgs << sg_all_platforms
+ end
+ selected_sgs
end
def index_for(dependency)
@@ -183,9 +202,7 @@ module Bundler
end
def requirement_satisfied_by?(requirement, activated, spec)
- return false unless requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec)
- spec.activate_platform!(requirement.__platform) if !@platforms || @platforms.include?(requirement.__platform)
- true
+ requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec)
end
def relevant_sources_for_vertex(vertex)
@@ -223,8 +240,9 @@ module Bundler
end
def self.platform_sort_key(platform)
- return ["", "", ""] if Gem::Platform::RUBY == platform
- platform.to_a.map {|part| part || "" }
+ # Prefer specific platform to not specific platform
+ return ["99-LAST", "", "", ""] if Gem::Platform::RUBY == platform
+ ["00", *platform.to_a.map {|part| part || "" }]
end
private
diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb
index e5772eed81..d5d12f7a2d 100644
--- a/lib/bundler/resolver/spec_group.rb
+++ b/lib/bundler/resolver/spec_group.rb
@@ -9,6 +9,7 @@ module Bundler
attr_accessor :ignores_bundler_dependencies
def initialize(all_specs)
+ @all_specs = all_specs
raise ArgumentError, "cannot initialize with an empty value" unless exemplary_spec = all_specs.first
@name = exemplary_spec.name
@version = exemplary_spec.version
@@ -28,7 +29,7 @@ module Bundler
lazy_spec = LazySpecification.new(name, version, s.platform, source)
lazy_spec.dependencies.replace s.dependencies
lazy_spec
- end.compact
+ end.compact.uniq
end
def activate_platform!(platform)
@@ -37,13 +38,25 @@ module Bundler
@activated_platforms << platform
end
+ def copy_for(platform)
+ copied_sg = self.class.new(@all_specs)
+ copied_sg.ignores_bundler_dependencies = @ignores_bundler_dependencies
+ return nil unless copied_sg.for?(platform)
+ copied_sg.activate_platform!(platform)
+ copied_sg
+ end
+
+ def spec_for(platform)
+ @specs[platform]
+ end
+
def for?(platform)
- spec = @specs[platform]
- !spec.nil?
+ !spec_for(platform).nil?
end
def to_s
- @to_s ||= "#{name} (#{version})"
+ activated_platforms_string = sorted_activated_platforms.join(", ")
+ "#{name} (#{version}) (#{activated_platforms_string})"
end
def dependencies_for_activated_platforms
@@ -58,6 +71,7 @@ module Bundler
return unless other.is_a?(SpecGroup)
name == other.name &&
version == other.version &&
+ sorted_activated_platforms == other.sorted_activated_platforms &&
source == other.source
end
@@ -65,11 +79,18 @@ module Bundler
return unless other.is_a?(SpecGroup)
name.eql?(other.name) &&
version.eql?(other.version) &&
+ sorted_activated_platforms.eql?(other.sorted_activated_platforms) &&
source.eql?(other.source)
end
def hash
- to_s.hash ^ source.hash
+ name.hash ^ version.hash ^ sorted_activated_platforms.hash ^ source.hash
+ end
+
+ protected
+
+ def sorted_activated_platforms
+ @activated_platforms.sort_by(&:to_s)
end
private