summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/definition.rb51
-rw-r--r--lib/bundler/dsl.rb26
-rw-r--r--lib/bundler/index.rb10
-rw-r--r--lib/bundler/lazy_specification.rb10
-rw-r--r--lib/bundler/lockfile_parser.rb6
-rw-r--r--lib/bundler/source/gemspec.rb4
-rw-r--r--lib/bundler/source/path.rb4
7 files changed, 78 insertions, 33 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 10e8e517f9..36bb9f2ef8 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -7,7 +7,15 @@ module Bundler
class Definition
include GemHelpers
- attr_reader :dependencies, :platforms, :ruby_version, :locked_deps, :gem_version_promoter, :requires
+ attr_reader(
+ :dependencies,
+ :gem_version_promoter,
+ :locked_deps,
+ :locked_gems,
+ :platforms,
+ :requires,
+ :ruby_version
+ )
# Given a gemfile and lockfile creates a Bundler definition
#
@@ -60,15 +68,15 @@ module Bundler
if lockfile && File.exist?(lockfile)
@lockfile_contents = Bundler.read_file(lockfile)
- locked = LockfileParser.new(@lockfile_contents)
- @platforms = locked.platforms
- @locked_bundler_version = locked.bundler_version
- @locked_ruby_version = locked.ruby_version
+ @locked_gems = LockfileParser.new(@lockfile_contents)
+ @platforms = @locked_gems.platforms
+ @locked_bundler_version = @locked_gems.bundler_version
+ @locked_ruby_version = @locked_gems.ruby_version
if unlock != true
- @locked_deps = locked.dependencies
- @locked_specs = SpecSet.new(locked.specs)
- @locked_sources = locked.sources
+ @locked_deps = @locked_gems.dependencies
+ @locked_specs = SpecSet.new(@locked_gems.specs)
+ @locked_sources = @locked_gems.sources
else
@unlock = {}
@locked_deps = []
@@ -78,6 +86,7 @@ module Bundler
else
@unlock = {}
@platforms = []
+ @locked_gems = nil
@locked_deps = []
@locked_specs = SpecSet.new([])
@locked_sources = []
@@ -512,14 +521,14 @@ module Bundler
# Check if the specs of the given source changed
# according to the locked source.
def specs_changed?(source)
- locked = @locked_sources.find(source)
+ locked = @locked_sources.find {|s| s == source }
- !locked || dependencies_for_source_changed?(source) || specs_for_source_changed?(source)
+ !locked || dependencies_for_source_changed?(source, locked) || specs_for_source_changed?(source)
end
- def dependencies_for_source_changed?(source)
+ def dependencies_for_source_changed?(source, locked_source = source)
deps_for_source = @dependencies.select {|s| s.source == source }
- locked_deps_for_source = @locked_deps.select {|s| s.source == source }
+ locked_deps_for_source = @locked_deps.select {|s| s.source == locked_source }
Set.new(deps_for_source) != Set.new(locked_deps_for_source)
end
@@ -557,9 +566,22 @@ module Bundler
end
end
+ def converge_path_source_to_gemspec_source(source)
+ return source unless source.instance_of?(Source::Path)
+ gemspec_source = sources.path_sources.find {|s| s.is_a?(Source::Gemspec) && s.as_path_source == source }
+ gemspec_source || source
+ end
+
def converge_sources
changes = false
+ @locked_sources.map! do |source|
+ converge_path_source_to_gemspec_source(source)
+ end
+ @locked_specs.each do |spec|
+ spec.source &&= converge_path_source_to_gemspec_source(spec.source)
+ end
+
# Get the Rubygems sources from the Gemfile.lock
locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) }
# Get the Rubygems remotes from the Gemfile
@@ -604,6 +626,9 @@ 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
Set.new(@dependencies) != Set.new(@locked_deps)
end
@@ -655,7 +680,7 @@ module Bundler
# then we unlock it.
# Path sources have special logic
- if s.source.instance_of?(Source::Path)
+ if s.source.instance_of?(Source::Path) || s.source.instance_of?(Source::Gemspec)
other = s.source.specs[s].first
# If the spec is no longer in the path source, unlock it. This
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 5577f40c26..b064c80d4c 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -50,22 +50,22 @@ module Bundler
end
def gemspec(opts = nil)
- path = opts && opts[:path] || "."
- glob = opts && opts[:glob]
- name = opts && opts[:name] || "{,*}"
- development_group = opts && opts[:development_group] || :development
+ opts ||= {}
+ path = opts[:path] || "."
+ glob = opts[:glob]
+ name = opts[:name]
+ development_group = opts[:development_group] || :development
expanded_path = gemfile_root.join(path)
- gemspecs = Dir[File.join(expanded_path, "#{name}.gemspec")]
+ gemspecs = Dir[File.join(expanded_path, "{,*}.gemspec")].map {|g| Bundler.load_gemspec(g) }.compact
+ gemspecs.reject! {|s| s.name != name } if name
+ Index.sort_specs(gemspecs)
+ specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
- case gemspecs.size
+ case specs_by_name_and_version.size
when 1
- spec = Bundler.load_gemspec(gemspecs.first)
-
- unless spec
- raise InvalidOption, "There was an error loading the gemspec at " \
- "#{file}. Make sure you can build the gem, then try again"
- end
+ specs = specs_by_name_and_version.values.first
+ spec = specs.find {|s| s.match_platform(Gem::Platform.local) } || specs.first
@gemspecs << spec
@@ -74,7 +74,7 @@ module Bundler
group(development_group) do
spec.development_dependencies.each do |dep|
- gem dep.name, *(dep.requirement.as_list + [:type => :development, :platforms => gem_platforms])
+ gem dep.name, *(dep.requirement.as_list + [:type => :development])
end
end
when 0
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index f0ee411df8..4529c57279 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -67,12 +67,20 @@ module Bundler
end
end
- results.sort_by do |s|
+ sort_specs(results)
+ end
+
+ def self.sort_specs(specs)
+ specs.sort_by do |s|
platform_string = s.platform.to_s
[s.version, platform_string == RUBY ? NULL : platform_string]
end
end
+ def sort_specs(specs)
+ self.class.sort_specs(specs)
+ end
+
def local_search(query, base = nil)
case query
when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query)
diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb
index ccaa791cc8..36ff5c59ed 100644
--- a/lib/bundler/lazy_specification.rb
+++ b/lib/bundler/lazy_specification.rb
@@ -5,6 +5,8 @@ require "bundler/match_platform"
module Bundler
class LazySpecification
+ Identifier = Struct.new(:name, :version, :source, :platform, :dependencies)
+
include MatchPlatform
attr_reader :name, :version, :dependencies, :platform
@@ -61,11 +63,15 @@ module Bundler
end
def to_s
- @__to_s ||= "#{name} (#{version})"
+ @__to_s ||= if platform == Gem::Platform::RUBY || platform.nil?
+ "#{name} (#{version})"
+ else
+ "#{name} (#{version}-#{platform})"
+ end
end
def identifier
- @__identifier ||= [name, version, source, platform, dependencies].hash
+ @__identifier ||= Identifier.new(name, version, source, platform, dependencies)
end
private
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index d5b2844079..90da4ac608 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -207,8 +207,10 @@ module Bundler
def parse_spec(line)
if line =~ NAME_VERSION_4
name = $1
- version = Gem::Version.new($2)
- platform = $3 ? Gem::Platform.new($3) : Gem::Platform::RUBY
+ version = $2
+ platform = $3
+ version = Gem::Version.new(version)
+ platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
@current_spec = LazySpecification.new(name, version, platform)
@current_spec.source = @current_source
diff --git a/lib/bundler/source/gemspec.rb b/lib/bundler/source/gemspec.rb
index 37e9a43945..05e613277f 100644
--- a/lib/bundler/source/gemspec.rb
+++ b/lib/bundler/source/gemspec.rb
@@ -8,6 +8,10 @@ module Bundler
super
@gemspec = options["gemspec"]
end
+
+ def as_path_source
+ Path.new(options)
+ end
end
end
end
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 3c4d914fb3..69bb0c1af2 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -11,7 +11,7 @@ module Bundler
DEFAULT_GLOB = "{,*,*/*}.gemspec".freeze
def initialize(options)
- @options = options
+ @options = options.dup
@glob = options["glob"] || DEFAULT_GLOB
@allow_cached = false
@@ -60,7 +60,7 @@ module Bundler
end
def eql?(other)
- return unless other.class == Path || other.class == Gemspec
+ return unless other.class == self.class
expanded_path == expand(other.path) &&
version == other.version
end