diff options
author | Homu <homu@barosl.com> | 2015-10-18 01:09:01 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2015-10-18 01:09:01 +0900 |
commit | 59fd7949c48a9720b47252dbc7e85e514cf9c0b2 (patch) | |
tree | 3fdfde52c97cc3b07126f7e992ebadf52cb568b7 | |
parent | 1bb7e41bd002294564c6e7de29cd9667df51c1ee (diff) | |
parent | e16706bf1388e1a2b5965896567e1e2f98c8a538 (diff) | |
download | bundler-59fd7949c48a9720b47252dbc7e85e514cf9c0b2.tar.gz |
Auto merge of #4026 - bundler:seg-resolve-ruby-version, r=indirect
[Resolver] Resolve for a given ruby version
Take the definition's ruby version into account when resolving, to try and avoid conflicts with incompatible `required_ruby_version`s. This will mostly help once the compact index is in use.
-rw-r--r-- | lib/bundler/definition.rb | 3 | ||||
-rw-r--r-- | lib/bundler/index.rb | 1 | ||||
-rw-r--r-- | lib/bundler/resolver.rb | 21 | ||||
-rw-r--r-- | lib/bundler/source/path.rb | 2 | ||||
-rw-r--r-- | spec/resolver/basic_spec.rb | 29 | ||||
-rw-r--r-- | spec/support/builders.rb | 4 | ||||
-rw-r--r-- | spec/update/path_spec.rb | 2 |
7 files changed, 52 insertions, 10 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index d1849e48..1de65df6 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -196,7 +196,8 @@ module Bundler last_resolve else # Run a resolve against the locally available gems - last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve) + requested_ruby_version = ruby_version.version if ruby_version + last_resolve.merge Resolver.resolve(expanded_dependencies, index, source_requirements, last_resolve, requested_ruby_version) end end end diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index f71849a8..1fa90e71 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -79,6 +79,7 @@ module Bundler when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query) when String then specs_by_name(query) when Gem::Dependency then search_by_dependency(query, base) + when DepProxy then search_by_dependency(query.dep, base) else raise "You can't search for a #{query.inspect}." end diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 5c7a65d8..527962d1 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -108,7 +108,7 @@ module Bundler def activate_platform(platform) unless @activated.include?(platform) - if for?(platform) + if for?(platform, nil) @activated << platform return __dependencies[platform] || [] end @@ -128,8 +128,14 @@ module Bundler @source ||= first.source end - def for?(platform) - @specs[platform] + def for?(platform, required_ruby_version) + if spec = @specs[platform] + if required_ruby_version && spec_required_ruby_version = spec.required_ruby_version + spec_required_ruby_version.satisfied_by?(required_ruby_version) + else + true + end + end end def to_s @@ -173,14 +179,14 @@ module Bundler # ==== Returns # <GemBundle>,nil:: If the list of dependencies can be resolved, a # collection of gemspecs is returned. Otherwise, nil is returned. - def self.resolve(requirements, index, source_requirements = {}, base = []) + def self.resolve(requirements, index, source_requirements = {}, base = [], ruby_version = nil) base = SpecSet.new(base) unless base.is_a?(SpecSet) - resolver = new(index, source_requirements, base) + resolver = new(index, source_requirements, base, ruby_version) result = resolver.start(requirements) SpecSet.new(result) end - def initialize(index, source_requirements, base) + def initialize(index, source_requirements, base, ruby_version) @index = index @source_requirements = source_requirements @base = base @@ -188,6 +194,7 @@ module Bundler @search_for = {} @base_dg = Molinillo::DependencyGraph.new @base.each {|ls| @base_dg.add_vertex(ls.name, Dependency.new(ls.name, ls.version), true) } + @ruby_version = ruby_version ? Gem::Version.create(ruby_version) : nil end def start(requirements) @@ -267,7 +274,7 @@ module Bundler [] end end - search.select {|sg| sg.for?(platform) }.each {|sg| sg.activate_platform(platform) } + search.select {|sg| sg.for?(platform, @ruby_version) }.each {|sg| sg.activate_platform(platform) } end def name_for(dependency) diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index d47fe0de..29241204 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -49,7 +49,7 @@ module Bundler end def to_s - "source at #{@path}" + "source at `#{@path}`" end def hash diff --git a/spec/resolver/basic_spec.rb b/spec/resolver/basic_spec.rb index 998bce60..416f94d4 100644 --- a/spec/resolver/basic_spec.rb +++ b/spec/resolver/basic_spec.rb @@ -74,4 +74,33 @@ describe "Resolving" do dep "foo", ">= 3.0.0" should_resolve_and_include %w(foo-3.0.5) end + + it "takes into account required_ruby_version" do + @index = build_index do + gem "foo", "1.0.0" do + dep "bar", ">= 0" + end + + gem "foo", "2.0.0" do |s| + dep "bar", ">= 0" + s.required_ruby_version = "~> 2.0.0" + end + + gem "bar", "1.0.0" + + gem "bar", "2.0.0" do |s| + s.required_ruby_version = "~> 2.0.0" + end + end + dep "foo" + + deps = [] + @deps.each do |d| + deps << Bundler::DepProxy.new(d, "ruby") + end + + got = Bundler::Resolver.resolve(deps, @index, {}, [], "1.8.7") + got = got.map(&:full_name).sort + expect(got).to eq(%w(foo-1.0.0 bar-1.0.0).sort) + end end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index fe9b2ba4..c4c4181f 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -439,6 +439,10 @@ module Spec @spec.add_runtime_dependency(name, requirements) end + def required_ruby_version=(*reqs) + @spec.required_ruby_version = *reqs + end + alias_method :dep, :runtime end diff --git a/spec/update/path_spec.rb b/spec/update/path_spec.rb index ff09cd7f..79d8caa9 100644 --- a/spec/update/path_spec.rb +++ b/spec/update/path_spec.rb @@ -12,7 +12,7 @@ describe "path sources" do build_lib "activesupport", "3.0", :path => lib_path("rails/activesupport") bundle "update --source activesupport" - expect(out).to include("Using activesupport 3.0 (was 2.3.5) from source at #{lib_path("rails/activesupport")}") + expect(out).to include("Using activesupport 3.0 (was 2.3.5) from source at `#{lib_path("rails/activesupport")}`") end end end |