diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index d4a7837072c..a0abb7508a3 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -127,16 +127,16 @@ def cache(custom_path = nil) Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}" - # Do not try to cache specification for the gem described by the .gemspec - root_gem_name = nil + # Do not try to cache specification for the gem described any of the gemspecs + root_gem_names = nil if gemspec_cache_hash = Bundler.instance_variable_get(:@gemspec_cache) - gemspec = gemspec_cache_hash.values.first - root_gem_name = gemspec.name unless gemspec.nil? + gemspecs = gemspec_cache_hash.values + root_gem_names = gemspecs.map(&:name) end specs.each do |spec| next if spec.name == "bundler" - next if !Dir.glob("*.gemspec").empty? && spec.source.class == Bundler::Source::Path && root_gem_name && spec.name == root_gem_name + next if !Dir.glob("*.gemspec").empty? && spec.source.class == Bundler::Source::Path && root_gem_names.include?(spec.name) spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true) spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache) end diff --git a/spec/commands/package_spec.rb b/spec/commands/package_spec.rb index 8cf6de4c8c5..3e4b602963f 100644 --- a/spec/commands/package_spec.rb +++ b/spec/commands/package_spec.rb @@ -95,6 +95,51 @@ end end end + + context "with multiple gemspecs" do + before do + File.open(bundled_app("mygem.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "nokogiri", "=1.4.2" + end + G + end + File.open(bundled_app("mygem_client.gemspec"), "w") do |f| + f.write <<-G + Gem::Specification.new do |s| + s.name = "mygem_test" + s.version = "0.1.1" + s.summary = "" + s.authors = ["gem author"] + s.add_development_dependency "weakling", "=0.0.3" + end + G + end + end + + it "caches all dependencies except bundler and the gemspec specified gems" do + gemfile <<-D + source "file://#{gem_repo1}" + gem 'rack' + gemspec :name => 'mygem' + gemspec :name => 'mygem_client' + D + + bundle! "package --all" + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/nokogiri-1.4.2.gem")).to exist + expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist + expect(bundled_app("vendor/cache/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/mygem_test-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end end context "with --path" do