summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Cutrer <cody@instructure.com>2014-09-08 22:26:08 -0600
committerCody Cutrer <cody@instructure.com>2014-12-23 11:04:38 -0700
commit288420b8069f07f0d11e8403128544ce0138a905 (patch)
treec9e9fb9a882dae87009a97a224e3db3e8617dc7c
parent17919e790cd8f6fb369d6afc81f0afec6fb5ad8b (diff)
downloadbundler-288420b8069f07f0d11e8403128544ce0138a905.tar.gz
implement all_platforms options for cache/package
so that a single cache directory can be used with multiple ruby versions
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/cli/cache.rb1
-rw-r--r--lib/bundler/cli/package.rb8
-rw-r--r--lib/bundler/definition.rb2
-rw-r--r--lib/bundler/runtime.rb1
-rw-r--r--spec/commands/package_spec.rb12
6 files changed, 24 insertions, 2 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 90cb4d6f85..1fec4f0ab2 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -228,6 +228,7 @@ module Bundler
desc "cache [OPTIONS]", "Cache all the gems to vendor/cache", :hide => true
method_option "all", :type => :boolean, :banner => "Include all sources (including path, git and svn)."
+ method_option "all-platforms", :type => :boolean, :banner => "Include gems for all platforms, not just the current one"
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def cache
require 'bundler/cli/cache'
@@ -236,6 +237,7 @@ module Bundler
desc "package [OPTIONS]", "Locks and then caches all of the gems into vendor/cache"
method_option "all", :type => :boolean, :banner => "Include all sources (including path, git and svn)."
+ method_option "all-platforms", :type => :boolean, :banner => "Include gems for all platforms, not just the current one"
method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile"
method_option "no-install", :type => :boolean, :banner => "Don't actually install the gems, just package."
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb
index 653ead7f56..751cb80149 100644
--- a/lib/bundler/cli/cache.rb
+++ b/lib/bundler/cli/cache.rb
@@ -9,6 +9,7 @@ module Bundler
Bundler.definition.validate_ruby!
Bundler.definition.resolve_with_cache!
setup_cache_all
+ Bundler.settings[:cache_all_platforms] = options["all-platforms"] if options.key?("all-platforms")
Bundler.load.cache
Bundler.settings[:no_prune] = true if options["no-prune"]
Bundler.load.lock
diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb
index 5adad44c35..f72a6c5c20 100644
--- a/lib/bundler/cli/package.rb
+++ b/lib/bundler/cli/package.rb
@@ -9,6 +9,7 @@ module Bundler
def run
Bundler.ui.level = "error" if options[:quiet]
Bundler.settings[:path] = File.expand_path(options[:path]) if options[:path]
+ Bundler.settings[:cache_all_platforms] = options["all-platforms"] if options.key?("all-platforms")
setup_cache_all
install
@@ -22,7 +23,12 @@ module Bundler
def install
require 'bundler/cli/install'
- Bundler::CLI::Install.new(options.dup).run
+ options = self.options.dup
+ if Bundler.settings[:cache_all_platforms]
+ options["local"] = false
+ options["update"] = true
+ end
+ Bundler::CLI::Install.new(options).run
end
def setup_cache_all
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 3afb53ba9e..29b3970bb2 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -129,7 +129,7 @@ module Bundler
# @return [Bundler::SpecSet]
def specs
@specs ||= begin
- specs = resolve.materialize(requested_dependencies)
+ specs = resolve.materialize(Bundler.settings[:cache_all_platforms] ? dependencies : requested_dependencies)
unless specs["bundler"].any?
local = Bundler.settings[:frozen] ? rubygems_index : index
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 905cd1d7dd..52377d270e 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -112,6 +112,7 @@ module Bundler
Bundler.ui.info "Updating files in vendor/cache"
specs.each do |spec|
next if spec.name == 'bundler'
+ 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 e193e239ba..d87ebc56bf 100644
--- a/spec/commands/package_spec.rb
+++ b/spec/commands/package_spec.rb
@@ -42,6 +42,18 @@ describe "bundle package" do
expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
end
end
+
+ context "with --all-platforms" do
+ it "puts the gems in vendor/cache even for other rubies", :ruby => "2.1" do
+ gemfile <<-D
+ source "file://#{gem_repo1}"
+ gem 'rack', :platforms => :ruby_19
+ D
+
+ bundle "package --all-platforms"
+ expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist
+ end
+ end
end
describe "bundle install with gem sources" do