From 2f22a8405c9ce290ed5464312cb100eeef3ad3b9 Mon Sep 17 00:00:00 2001 From: Homu Date: Wed, 28 Sep 2016 05:54:38 +0900 Subject: [PATCH] Auto merge of #5008 - bundler:seg-lazy-specification-materialize-platform, r=indirect [LazySpecification] Select the best platform match when materializing Closes #5006 This was not fun to track down >.< --- lib/bundler/lazy_specification.rb | 6 ++++- spec/install/gemfile/gemspec_spec.rb | 33 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 36ff5c59ed2..83ab9ef9670 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -55,7 +55,11 @@ def to_lock end def __materialize__ - @specification = source.specs.search(Gem::Dependency.new(name, version)).last + @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name + source.gemspec.tap {|s| s.source = source } + else + source.specs.search(Gem::Dependency.new(name, version)).last + end end def respond_to?(*args) diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb index 9a6bd5f1e83..698756525c1 100644 --- a/spec/install/gemfile/gemspec_spec.rb +++ b/spec/install/gemfile/gemspec_spec.rb @@ -409,4 +409,37 @@ end end end + + context "with multiple platforms" do + before do + build_lib("foo", :path => tmp.join("foo")) do |s| + s.version = "1.0.0" + s.add_development_dependency "rack" + s.write "foo-universal-java.gemspec", build_spec("foo", "1.0.0", "universal-java") {|sj| sj.runtime "rack", "1.0.0" }.first.to_ruby + end + end + + it "installs the ruby platform gemspec" do + simulate_platform "ruby" + + install_gemfile! <<-G + source "file://#{gem_repo1}" + gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + G + + expect(the_bundle).to include_gems "foo 1.0.0", "rack 1.0.0" + end + + it "installs the ruby platform gemspec and skips dev deps with --without development" do + simulate_platform "ruby" + + install_gemfile! <<-G, :without => "development" + source "file://#{gem_repo1}" + gemspec :path => '#{tmp.join("foo")}', :name => 'foo' + G + + expect(the_bundle).to include_gem "foo 1.0.0" + expect(the_bundle).not_to include_gem "rack" + end + end end