From c9f6d2b4c5e540ba6a165c7a58432bf0081a7e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 20 Oct 2019 13:26:11 +0200 Subject: Normalize "bundle cache" vs "bundle package" Use the preferred `bundle cache` everywhere, but leave package as an alias. Remove duplicated tests. --- lib/bundler/cli.rb | 20 +- lib/bundler/cli/cache.rb | 48 +++++ lib/bundler/cli/package.rb | 48 ----- man/bundle-cache.1 | 55 ++++++ man/bundle-cache.1.txt | 78 ++++++++ man/bundle-cache.ronn | 72 +++++++ man/bundle-package.1 | 55 ------ man/bundle-package.1.txt | 78 -------- man/bundle-package.ronn | 72 ------- man/index.txt | 2 +- spec/cache/cache_path_spec.rb | 6 +- spec/cache/git_spec.rb | 342 +++++++++++++++++----------------- spec/cache/path_spec.rb | 214 +++++++++++---------- spec/commands/cache_spec.rb | 351 +++++++++++++++++++++++++++++++++++ spec/commands/package_spec.rb | 351 ----------------------------------- spec/install/deploy_spec.rb | 2 +- spec/install/gemfile/git_spec.rb | 2 +- spec/install/gemfile/sources_spec.rb | 2 +- spec/lock/lockfile_spec.rb | 2 +- spec/other/platform_spec.rb | 12 +- spec/plugins/source/example_spec.rb | 2 +- 21 files changed, 904 insertions(+), 910 deletions(-) create mode 100644 lib/bundler/cli/cache.rb delete mode 100644 lib/bundler/cli/package.rb create mode 100644 man/bundle-cache.1 create mode 100644 man/bundle-cache.1.txt create mode 100644 man/bundle-cache.ronn delete mode 100644 man/bundle-package.1 delete mode 100644 man/bundle-package.1.txt delete mode 100644 man/bundle-package.ronn create mode 100644 spec/commands/cache_spec.rb delete mode 100644 spec/commands/package_spec.rb diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 0083f7e7de..39f42c9a70 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -68,9 +68,7 @@ module Bundler version Bundler.ui.info "\n" - primary_commands = ["install", "update", - Bundler.feature_flag.bundler_3_mode? ? "cache" : "package", - "exec", "config", "help"] + primary_commands = ["install", "update", "cache", "exec", "config", "help"] list = self.class.printable_commands(true) by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] } @@ -412,7 +410,7 @@ module Bundler Outdated.new(options, gems).run end - desc "#{Bundler.feature_flag.bundler_3_mode? ? :cache : :package} [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" + desc "cache [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" unless Bundler.feature_flag.cache_all? method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)." @@ -421,24 +419,24 @@ module Bundler method_option "cache-path", :type => :string, :banner => "Specify a different cache path than the default (vendor/cache)." method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile" - method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only the package." + method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only update the cache." method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." method_option "path", :type => :string, :banner => "Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME).#{" Bundler will remember this value for future installs on this machine" unless Bundler.feature_flag.forget_cli_options?}" method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors." method_option "frozen", :type => :boolean, :banner => - "Do not allow the Gemfile.lock to be updated after this package operation's install" + "Do not allow the Gemfile.lock to be updated after this bundle cache operation's install" long_desc <<-D - The package command will copy the .gem files for every gem in the bundle into the + The cache command will copy the .gem files for every gem in the bundle into the directory ./vendor/cache. If you then check that directory into your source control repository, others who check out your source will be able to install the bundle without having to download any additional gems. D - def package - require_relative "cli/package" - Package.new(options).run + def cache + require_relative "cli/cache" + Cache.new(options).run end - map %w[cache pack] => :package + map %w[package pack] => :cache desc "exec [OPTIONS]", "Run the command in context of the bundle" method_option :keep_file_descriptors, :type => :boolean, :default => false diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb new file mode 100644 index 0000000000..5e8420990f --- /dev/null +++ b/lib/bundler/cli/cache.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Bundler + class CLI::Cache + attr_reader :options + + def initialize(options) + @options = options + end + + def run + Bundler.ui.level = "error" if options[:quiet] + Bundler.settings.set_command_option_if_given :path, options[:path] + Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] + + setup_cache_all + install + + # TODO: move cache contents here now that all bundles are locked + custom_path = Bundler.settings[:path] if options[:path] + + Bundler.settings.temporary(:cache_all_platforms => options["all-platforms"]) do + Bundler.load.cache(custom_path) + end + end + + private + + def install + require_relative "install" + options = self.options.dup + options["local"] = false if Bundler.settings[:cache_all_platforms] + Bundler::CLI::Install.new(options).run + end + + def setup_cache_all + all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil) + + Bundler.settings.set_command_option_if_given :cache_all, all + + if Bundler.definition.has_local_dependencies? && !Bundler.feature_flag.cache_all? + Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \ + "to cache them as well, please pass the --all flag. This will be the default " \ + "on Bundler 3.0." + end + end + end +end diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb deleted file mode 100644 index b31b67776d..0000000000 --- a/lib/bundler/cli/package.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -module Bundler - class CLI::Package - attr_reader :options - - def initialize(options) - @options = options - end - - def run - Bundler.ui.level = "error" if options[:quiet] - Bundler.settings.set_command_option_if_given :path, options[:path] - Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] - - setup_cache_all - install - - # TODO: move cache contents here now that all bundles are locked - custom_path = Bundler.settings[:path] if options[:path] - - Bundler.settings.temporary(:cache_all_platforms => options["all-platforms"]) do - Bundler.load.cache(custom_path) - end - end - - private - - def install - require_relative "install" - options = self.options.dup - options["local"] = false if Bundler.settings[:cache_all_platforms] - Bundler::CLI::Install.new(options).run - end - - def setup_cache_all - all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil) - - Bundler.settings.set_command_option_if_given :cache_all, all - - if Bundler.definition.has_local_dependencies? && !Bundler.feature_flag.cache_all? - Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \ - "to package them as well, please pass the --all flag. This will be the default " \ - "on Bundler 3.0." - end - end - end -end diff --git a/man/bundle-cache.1 b/man/bundle-cache.1 new file mode 100644 index 0000000000..a3ffa0e7f7 --- /dev/null +++ b/man/bundle-cache.1 @@ -0,0 +1,55 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "BUNDLE\-CACHE" "1" "October 2019" "" "" +. +.SH "NAME" +\fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application +. +.SH "SYNOPSIS" +\fBbundle cache\fR +. +.SH "DESCRIPTION" +Copy all of the \fB\.gem\fR files needed to run the application into the \fBvendor/cache\fR directory\. In the future, when running [bundle install(1)][bundle\-install], use the gems in the cache in preference to the ones on \fBrubygems\.org\fR\. +. +.SH "GIT AND PATH GEMS" +The \fBbundle cache\fR command can also package \fB:git\fR and \fB:path\fR dependencies besides \.gem files\. This needs to be explicitly enabled via the \fB\-\-all\fR option\. Once used, the \fB\-\-all\fR option will be remembered\. +. +.SH "SUPPORT FOR MULTIPLE PLATFORMS" +When using gems that have different packages for different platforms, Bundler supports caching of gems for other platforms where the Gemfile has been resolved (i\.e\. present in the lockfile) in \fBvendor/cache\fR\. This needs to be enabled via the \fB\-\-all\-platforms\fR option\. This setting will be remembered in your local bundler configuration\. +. +.SH "REMOTE FETCHING" +By default, if you run \fBbundle install(1)\fR](bundle\-install\.1\.html) after running bundle cache(1) \fIbundle\-cache\.1\.html\fR, bundler will still connect to \fBrubygems\.org\fR to check whether a platform\-specific gem exists for any of the gems in \fBvendor/cache\fR\. +. +.P +For instance, consider this Gemfile(5): +. +.IP "" 4 +. +.nf + +source "https://rubygems\.org" + +gem "nokogiri" +. +.fi +. +.IP "" 0 +. +.P +If you run \fBbundle cache\fR under C Ruby, bundler will retrieve the version of \fBnokogiri\fR for the \fB"ruby"\fR platform\. If you deploy to JRuby and run \fBbundle install\fR, bundler is forced to check to see whether a \fB"java"\fR platformed \fBnokogiri\fR exists\. +. +.P +Even though the \fBnokogiri\fR gem for the Ruby platform is \fItechnically\fR acceptable on JRuby, it has a C extension that does not run on JRuby\. As a result, bundler will, by default, still connect to \fBrubygems\.org\fR to check whether it has a version of one of your gems more specific to your platform\. +. +.P +This problem is also not limited to the \fB"java"\fR platform\. A similar (common) problem can happen when developing on Windows and deploying to Linux, or even when developing on OSX and deploying to Linux\. +. +.P +If you know for sure that the gems packaged in \fBvendor/cache\fR are appropriate for the platform you are on, you can run \fBbundle install \-\-local\fR to skip checking for more appropriate gems, and use the ones in \fBvendor/cache\fR\. +. +.P +One way to be sure that you have the right platformed versions of all your gems is to run \fBbundle cache\fR on an identical machine and check in the gems\. For instance, you can run \fBbundle cache\fR on an identical staging box during your staging process, and check in the \fBvendor/cache\fR before deploying to production\. +. +.P +By default, bundle cache(1) \fIbundle\-cache\.1\.html\fR fetches and also installs the gems to the default location\. To package the dependencies to \fBvendor/cache\fR without installing them to the local install location, you can run \fBbundle cache \-\-no\-install\fR\. diff --git a/man/bundle-cache.1.txt b/man/bundle-cache.1.txt new file mode 100644 index 0000000000..1acac3d82d --- /dev/null +++ b/man/bundle-cache.1.txt @@ -0,0 +1,78 @@ +BUNDLE-CACHE(1) BUNDLE-CACHE(1) + + + +NAME + bundle-cache - Package your needed .gem files into your application + +SYNOPSIS + bundle cache + +DESCRIPTION + Copy all of the .gem files needed to run the application into the ven- + dor/cache directory. In the future, when running [bundle + install(1)][bundle-install], use the gems in the cache in preference to + the ones on rubygems.org. + +GIT AND PATH GEMS + The bundle cache command can also package :git and :path dependencies + besides .gem files. This needs to be explicitly enabled via the --all + option. Once used, the --all option will be remembered. + +SUPPORT FOR MULTIPLE PLATFORMS + When using gems that have different packages for different platforms, + Bundler supports caching of gems for other platforms where the Gemfile + has been resolved (i.e. present in the lockfile) in vendor/cache. This + needs to be enabled via the --all-platforms option. This setting will + be remembered in your local bundler configuration. + +REMOTE FETCHING + By default, if you run bundle install(1)](bundle-install.1.html) after + running bundle cache(1) bundle-cache.1.html, bundler will still connect + to rubygems.org to check whether a platform-specific gem exists for any + of the gems in vendor/cache. + + For instance, consider this Gemfile(5): + + + + source "https://rubygems.org" + + gem "nokogiri" + + + + If you run bundle cache under C Ruby, bundler will retrieve the version + of nokogiri for the "ruby" platform. If you deploy to JRuby and run + bundle install, bundler is forced to check to see whether a "java" + platformed nokogiri exists. + + Even though the nokogiri gem for the Ruby platform is technically + acceptable on JRuby, it has a C extension that does not run on JRuby. + As a result, bundler will, by default, still connect to rubygems.org to + check whether it has a version of one of your gems more specific to + your platform. + + This problem is also not limited to the "java" platform. A similar + (common) problem can happen when developing on Windows and deploying to + Linux, or even when developing on OSX and deploying to Linux. + + If you know for sure that the gems packaged in vendor/cache are appro- + priate for the platform you are on, you can run bundle install --local + to skip checking for more appropriate gems, and use the ones in ven- + dor/cache. + + One way to be sure that you have the right platformed versions of all + your gems is to run bundle cache on an identical machine and check in + the gems. For instance, you can run bundle cache on an identical stag- + ing box during your staging process, and check in the vendor/cache + before deploying to production. + + By default, bundle cache(1) bundle-cache.1.html fetches and also + installs the gems to the default location. To package the dependencies + to vendor/cache without installing them to the local install location, + you can run bundle cache --no-install. + + + + October 2019 BUNDLE-CACHE(1) diff --git a/man/bundle-cache.ronn b/man/bundle-cache.ronn new file mode 100644 index 0000000000..383adb2ba3 --- /dev/null +++ b/man/bundle-cache.ronn @@ -0,0 +1,72 @@ +bundle-cache(1) -- Package your needed `.gem` files into your application +=========================================================================== + +## SYNOPSIS + +`bundle cache` + +## DESCRIPTION + +Copy all of the `.gem` files needed to run the application into the +`vendor/cache` directory. In the future, when running [bundle install(1)][bundle-install], +use the gems in the cache in preference to the ones on `rubygems.org`. + +## GIT AND PATH GEMS + +The `bundle cache` command can also package `:git` and `:path` dependencies +besides .gem files. This needs to be explicitly enabled via the `--all` option. +Once used, the `--all` option will be remembered. + +## SUPPORT FOR MULTIPLE PLATFORMS + +When using gems that have different packages for different platforms, Bundler +supports caching of gems for other platforms where the Gemfile has been resolved +(i.e. present in the lockfile) in `vendor/cache`. This needs to be enabled via +the `--all-platforms` option. This setting will be remembered in your local +bundler configuration. + +## REMOTE FETCHING + +By default, if you run `bundle install(1)`](bundle-install.1.html) after running +[bundle cache(1)](bundle-cache.1.html), bundler will still connect to `rubygems.org` +to check whether a platform-specific gem exists for any of the gems +in `vendor/cache`. + +For instance, consider this Gemfile(5): + + source "https://rubygems.org" + + gem "nokogiri" + +If you run `bundle cache` under C Ruby, bundler will retrieve +the version of `nokogiri` for the `"ruby"` platform. If you deploy +to JRuby and run `bundle install`, bundler is forced to check to +see whether a `"java"` platformed `nokogiri` exists. + +Even though the `nokogiri` gem for the Ruby platform is +_technically_ acceptable on JRuby, it has a C extension +that does not run on JRuby. As a result, bundler will, by default, +still connect to `rubygems.org` to check whether it has a version +of one of your gems more specific to your platform. + +This problem is also not limited to the `"java"` platform. +A similar (common) problem can happen when developing on Windows +and deploying to Linux, or even when developing on OSX and +deploying to Linux. + +If you know for sure that the gems packaged in `vendor/cache` +are appropriate for the platform you are on, you can run +`bundle install --local` to skip checking for more appropriate +gems, and use the ones in `vendor/cache`. + +One way to be sure that you have the right platformed versions +of all your gems is to run `bundle cache` on an identical +machine and check in the gems. For instance, you can run +`bundle cache` on an identical staging box during your +staging process, and check in the `vendor/cache` before +deploying to production. + +By default, [bundle cache(1)](bundle-cache.1.html) fetches and also +installs the gems to the default location. To package the +dependencies to `vendor/cache` without installing them to the +local install location, you can run `bundle cache --no-install`. diff --git a/man/bundle-package.1 b/man/bundle-package.1 deleted file mode 100644 index 10231d7ad1..0000000000 --- a/man/bundle-package.1 +++ /dev/null @@ -1,55 +0,0 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-PACKAGE" "1" "October 2019" "" "" -. -.SH "NAME" -\fBbundle\-package\fR \- Package your needed \fB\.gem\fR files into your application -. -.SH "SYNOPSIS" -\fBbundle package\fR -. -.SH "DESCRIPTION" -Copy all of the \fB\.gem\fR files needed to run the application into the \fBvendor/cache\fR directory\. In the future, when running [bundle install(1)][bundle\-install], use the gems in the cache in preference to the ones on \fBrubygems\.org\fR\. -. -.SH "GIT AND PATH GEMS" -The \fBbundle package\fR command can also package \fB:git\fR and \fB:path\fR dependencies besides \.gem files\. This needs to be explicitly enabled via the \fB\-\-all\fR option\. Once used, the \fB\-\-all\fR option will be remembered\. -. -.SH "SUPPORT FOR MULTIPLE PLATFORMS" -When using gems that have different packages for different platforms, Bundler supports caching of gems for other platforms where the Gemfile has been resolved (i\.e\. present in the lockfile) in \fBvendor/cache\fR\. This needs to be enabled via the \fB\-\-all\-platforms\fR option\. This setting will be remembered in your local bundler configuration\. -. -.SH "REMOTE FETCHING" -By default, if you run \fBbundle install(1)\fR](bundle\-install\.1\.html) after running bundle package(1) \fIbundle\-package\.1\.html\fR, bundler will still connect to \fBrubygems\.org\fR to check whether a platform\-specific gem exists for any of the gems in \fBvendor/cache\fR\. -. -.P -For instance, consider this Gemfile(5): -. -.IP "" 4 -. -.nf - -source "https://rubygems\.org" - -gem "nokogiri" -. -.fi -. -.IP "" 0 -. -.P -If you run \fBbundle package\fR under C Ruby, bundler will retrieve the version of \fBnokogiri\fR for the \fB"ruby"\fR platform\. If you deploy to JRuby and run \fBbundle install\fR, bundler is forced to check to see whether a \fB"java"\fR platformed \fBnokogiri\fR exists\. -. -.P -Even though the \fBnokogiri\fR gem for the Ruby platform is \fItechnically\fR acceptable on JRuby, it has a C extension that does not run on JRuby\. As a result, bundler will, by default, still connect to \fBrubygems\.org\fR to check whether it has a version of one of your gems more specific to your platform\. -. -.P -This problem is also not limited to the \fB"java"\fR platform\. A similar (common) problem can happen when developing on Windows and deploying to Linux, or even when developing on OSX and deploying to Linux\. -. -.P -If you know for sure that the gems packaged in \fBvendor/cache\fR are appropriate for the platform you are on, you can run \fBbundle install \-\-local\fR to skip checking for more appropriate gems, and use the ones in \fBvendor/cache\fR\. -. -.P -One way to be sure that you have the right platformed versions of all your gems is to run \fBbundle package\fR on an identical machine and check in the gems\. For instance, you can run \fBbundle package\fR on an identical staging box during your staging process, and check in the \fBvendor/cache\fR before deploying to production\. -. -.P -By default, bundle package(1) \fIbundle\-package\.1\.html\fR fetches and also installs the gems to the default location\. To package the dependencies to \fBvendor/cache\fR without installing them to the local install location, you can run \fBbundle package \-\-no\-install\fR\. diff --git a/man/bundle-package.1.txt b/man/bundle-package.1.txt deleted file mode 100644 index 707bec3cd6..0000000000 --- a/man/bundle-package.1.txt +++ /dev/null @@ -1,78 +0,0 @@ -BUNDLE-PACKAGE(1) BUNDLE-PACKAGE(1) - - - -NAME - bundle-package - Package your needed .gem files into your application - -SYNOPSIS - bundle package - -DESCRIPTION - Copy all of the .gem files needed to run the application into the ven- - dor/cache directory. In the future, when running [bundle - install(1)][bundle-install], use the gems in the cache in preference to - the ones on rubygems.org. - -GIT AND PATH GEMS - The bundle package command can also package :git and :path dependencies - besides .gem files. This needs to be explicitly enabled via the --all - option. Once used, the --all option will be remembered. - -SUPPORT FOR MULTIPLE PLATFORMS - When using gems that have different packages for different platforms, - Bundler supports caching of gems for other platforms where the Gemfile - has been resolved (i.e. present in the lockfile) in vendor/cache. This - needs to be enabled via the --all-platforms option. This setting will - be remembered in your local bundler configuration. - -REMOTE FETCHING - By default, if you run bundle install(1)](bundle-install.1.html) after - running bundle package(1) bundle-package.1.html, bundler will still - connect to rubygems.org to check whether a platform-specific gem exists - for any of the gems in vendor/cache. - - For instance, consider this Gemfile(5): - - - - source "https://rubygems.org" - - gem "nokogiri" - - - - If you run bundle package under C Ruby, bundler will retrieve the ver- - sion of nokogiri for the "ruby" platform. If you deploy to JRuby and - run bundle install, bundler is forced to check to see whether a "java" - platformed nokogiri exists. - - Even though the nokogiri gem for the Ruby platform is technically - acceptable on JRuby, it has a C extension that does not run on JRuby. - As a result, bundler will, by default, still connect to rubygems.org to - check whether it has a version of one of your gems more specific to - your platform. - - This problem is also not limited to the "java" platform. A similar - (common) problem can happen when developing on Windows and deploying to - Linux, or even when developing on OSX and deploying to Linux. - - If you know for sure that the gems packaged in vendor/cache are appro- - priate for the platform you are on, you can run bundle install --local - to skip checking for more appropriate gems, and use the ones in ven- - dor/cache. - - One way to be sure that you have the right platformed versions of all - your gems is to run bundle package on an identical machine and check in - the gems. For instance, you can run bundle package on an identical - staging box during your staging process, and check in the vendor/cache - before deploying to production. - - By default, bundle package(1) bundle-package.1.html fetches and also - installs the gems to the default location. To package the dependencies - to vendor/cache without installing them to the local install location, - you can run bundle package --no-install. - - - - October 2019 BUNDLE-PACKAGE(1) diff --git a/man/bundle-package.ronn b/man/bundle-package.ronn deleted file mode 100644 index ad745f8491..0000000000 --- a/man/bundle-package.ronn +++ /dev/null @@ -1,72 +0,0 @@ -bundle-package(1) -- Package your needed `.gem` files into your application -=========================================================================== - -## SYNOPSIS - -`bundle package` - -## DESCRIPTION - -Copy all of the `.gem` files needed to run the application into the -`vendor/cache` directory. In the future, when running [bundle install(1)][bundle-install], -use the gems in the cache in preference to the ones on `rubygems.org`. - -## GIT AND PATH GEMS - -The `bundle package` command can also package `:git` and `:path` dependencies -besides .gem files. This needs to be explicitly enabled via the `--all` option. -Once used, the `--all` option will be remembered. - -## SUPPORT FOR MULTIPLE PLATFORMS - -When using gems that have different packages for different platforms, Bundler -supports caching of gems for other platforms where the Gemfile has been resolved -(i.e. present in the lockfile) in `vendor/cache`. This needs to be enabled via -the `--all-platforms` option. This setting will be remembered in your local -bundler configuration. - -## REMOTE FETCHING - -By default, if you run `bundle install(1)`](bundle-install.1.html) after running -[bundle package(1)](bundle-package.1.html), bundler will still connect to `rubygems.org` -to check whether a platform-specific gem exists for any of the gems -in `vendor/cache`. - -For instance, consider this Gemfile(5): - - source "https://rubygems.org" - - gem "nokogiri" - -If you run `bundle package` under C Ruby, bundler will retrieve -the version of `nokogiri` for the `"ruby"` platform. If you deploy -to JRuby and run `bundle install`, bundler is forced to check to -see whether a `"java"` platformed `nokogiri` exists. - -Even though the `nokogiri` gem for the Ruby platform is -_technically_ acceptable on JRuby, it has a C extension -that does not run on JRuby. As a result, bundler will, by default, -still connect to `rubygems.org` to check whether it has a version -of one of your gems more specific to your platform. - -This problem is also not limited to the `"java"` platform. -A similar (common) problem can happen when developing on Windows -and deploying to Linux, or even when developing on OSX and -deploying to Linux. - -If you know for sure that the gems packaged in `vendor/cache` -are appropriate for the platform you are on, you can run -`bundle install --local` to skip checking for more appropriate -gems, and use the ones in `vendor/cache`. - -One way to be sure that you have the right platformed versions -of all your gems is to run `bundle package` on an identical -machine and check in the gems. For instance, you can run -`bundle package` on an identical staging box during your -staging process, and check in the `vendor/cache` before -deploying to production. - -By default, [bundle package(1)](bundle-package.1.html) fetches and also -installs the gems to the default location. To package the -dependencies to `vendor/cache` without installing them to the -local install location, you can run `bundle package --no-install`. diff --git a/man/index.txt b/man/index.txt index 400eb02267..ef2956b2f9 100644 --- a/man/index.txt +++ b/man/index.txt @@ -2,6 +2,7 @@ Gemfile(5) gemfile.5 bundle(1) bundle.1 bundle-add(1) bundle-add.1 bundle-binstubs(1) bundle-binstubs.1 +bundle-cache(1) bundle-cache.1 bundle-check(1) bundle-check.1 bundle-clean(1) bundle-clean.1 bundle-config(1) bundle-config.1 @@ -16,7 +17,6 @@ bundle-list(1) bundle-list.1 bundle-lock(1) bundle-lock.1 bundle-open(1) bundle-open.1 bundle-outdated(1) bundle-outdated.1 -bundle-package(1) bundle-package.1 bundle-platform(1) bundle-platform.1 bundle-pristine(1) bundle-pristine.1 bundle-remove(1) bundle-remove.1 diff --git a/spec/cache/cache_path_spec.rb b/spec/cache/cache_path_spec.rb index 1a61494130..12385427b1 100644 --- a/spec/cache/cache_path_spec.rb +++ b/spec/cache/cache_path_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "bundle package" do context "with --cache-path" do it "caches gems at given path" do - bundle :package, "cache-path" => "vendor/cache-foo" + bundle :cache, "cache-path" => "vendor/cache-foo" expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist end end @@ -18,14 +18,14 @@ RSpec.describe "bundle package" do context "with config cache_path" do it "caches gems at given path" do bundle "config set cache_path vendor/cache-foo" - bundle :package + bundle :cache expect(bundled_app("vendor/cache-foo/rack-1.0.0.gem")).to exist end end context "with absolute --cache-path" do it "caches gems at given path" do - bundle :package, "cache-path" => "/tmp/cache-foo" + bundle :cache, "cache-path" => "/tmp/cache-foo" expect(bundled_app("/tmp/cache-foo/rack-1.0.0.gem")).to exist end end diff --git a/spec/cache/git_spec.rb b/spec/cache/git_spec.rb index 1cb278e912..75525d405b 100644 --- a/spec/cache/git_spec.rb +++ b/spec/cache/git_spec.rb @@ -12,230 +12,228 @@ RSpec.describe "git base name" do end end -%w[cache package].each do |cmd| - RSpec.describe "bundle #{cmd} with git" do - it "copies repository to vendor cache and uses it" do - git = build_git "foo" - ref = git.ref_for("master", 11) - - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file - - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end - - it "copies repository to vendor cache and uses it even when installed with bundle --path" do - git = build_git "foo" - ref = git.ref_for("master", 11) +RSpec.describe "bundle cache with git" do + it "copies repository to vendor cache and uses it" do + git = build_git "foo" + ref = git.ref_for("master", 11) + + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache")).to be_file + + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "copies repository to vendor cache and uses it even when installed with bundle --path" do + git = build_git "foo" + ref = git.ref_for("master", 11) - bundle "install --path vendor/bundle" - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist + bundle "install --path vendor/bundle" + bundle "config set cache_all true" + bundle :cache - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{ref}/.git")).not_to exist - it "runs twice without exploding" do - build_git "foo" + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile! <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "runs twice without exploding" do + build_git "foo" - bundle "config set cache_all true" - bundle! cmd - bundle! cmd + install_gemfile! <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - expect(out).to include "Updating files in vendor/cache" - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + bundle "config set cache_all true" + bundle! :cache + bundle! :cache - it "tracks updates" do - git = build_git "foo" - old_ref = git.ref_for("master", 11) + expect(out).to include "Updating files in vendor/cache" + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "tracks updates" do + git = build_git "foo" + old_ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + bundle "config set cache_all true" + bundle :cache - ref = git.ref_for("master", 11) - expect(ref).not_to eq(old_ref) + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle! "update", :all => true - bundle "config set cache_all true" - bundle! cmd + ref = git.ref_for("master", 11) + expect(ref).not_to eq(old_ref) - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist + bundle! "update", :all => true + bundle "config set cache_all true" + bundle! :cache - FileUtils.rm_rf lib_path("foo-1.0") - run! "require 'foo'" - expect(out).to eq("CACHE") - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - it "tracks updates when specifying the gem" do - git = build_git "foo" - old_ref = git.ref_for("master", 11) + FileUtils.rm_rf lib_path("foo-1.0") + run! "require 'foo'" + expect(out).to eq("CACHE") + end - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + it "tracks updates when specifying the gem" do + git = build_git "foo" + old_ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle! cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + bundle "config set cache_all true" + bundle! :cache - ref = git.ref_for("master", 11) - expect(ref).not_to eq(old_ref) + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle "update foo" + ref = git.ref_for("master", 11) + expect(ref).not_to eq(old_ref) - expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist + bundle "update foo" - FileUtils.rm_rf lib_path("foo-1.0") - run "require 'foo'" - expect(out).to eq("CACHE") - end + expect(bundled_app("vendor/cache/foo-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/foo-1.0-#{old_ref}")).not_to exist - it "uses the local repository to generate the cache" do - git = build_git "foo" - ref = git.ref_for("master", 11) + FileUtils.rm_rf lib_path("foo-1.0") + run "require 'foo'" + expect(out).to eq("CACHE") + end - gemfile <<-G - gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master - G + it "uses the local repository to generate the cache" do + git = build_git "foo" + ref = git.ref_for("master", 11) - bundle %(config set local.foo #{lib_path("foo-1.0")}) - bundle "install" - bundle "config set cache_all true" - bundle cmd + gemfile <<-G + gem "foo", :git => '#{lib_path("foo-invalid")}', :branch => :master + G - expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist + bundle %(config set local.foo #{lib_path("foo-1.0")}) + bundle "install" + bundle "config set cache_all true" + bundle :cache - # Updating the local still uses the local. - update_git "foo" do |s| - s.write "lib/foo.rb", "puts :LOCAL" - end + expect(bundled_app("vendor/cache/foo-invalid-#{ref}")).to exist - run "require 'foo'" - expect(out).to eq("LOCAL") + # Updating the local still uses the local. + update_git "foo" do |s| + s.write "lib/foo.rb", "puts :LOCAL" end - it "copies repository to vendor cache, including submodules" do - build_git "submodule", "1.0" + run "require 'foo'" + expect(out).to eq("LOCAL") + end - git = build_git "has_submodule", "1.0" do |s| - s.add_dependency "submodule" - end + it "copies repository to vendor cache, including submodules" do + build_git "submodule", "1.0" - Dir.chdir(lib_path("has_submodule-1.0")) do - sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" - `git commit -m "submodulator"` - end + git = build_git "has_submodule", "1.0" do |s| + s.add_dependency "submodule" + end - install_gemfile <<-G - git "#{lib_path("has_submodule-1.0")}", :submodules => true do - gem "has_submodule" - end - G + Dir.chdir(lib_path("has_submodule-1.0")) do + sys_exec "git submodule add #{lib_path("submodule-1.0")} submodule-1.0" + `git commit -m "submodulator"` + end + + install_gemfile <<-G + git "#{lib_path("has_submodule-1.0")}", :submodules => true do + gem "has_submodule" + end + G - ref = git.ref_for("master", 11) - bundle "config set cache_all true" - bundle cmd + ref = git.ref_for("master", 11) + bundle "config set cache_all true" + bundle :cache - expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist - expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist - expect(the_bundle).to include_gems "has_submodule 1.0" - end + expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}")).to exist + expect(bundled_app("vendor/cache/has_submodule-1.0-#{ref}/submodule-1.0")).to exist + expect(the_bundle).to include_gems "has_submodule 1.0" + end - it "displays warning message when detecting git repo in Gemfile", :bundler => "< 3" do - build_git "foo" + it "displays warning message when detecting git repo in Gemfile", :bundler => "< 3" do + build_git "foo" - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - bundle cmd + bundle :cache - expect(err).to include("Your Gemfile contains path and git dependencies.") - end + expect(err).to include("Your Gemfile contains path and git dependencies.") + end - it "does not display warning message if cache_all is set in bundle config" do - build_git "foo" + it "does not display warning message if cache_all is set in bundle config" do + build_git "foo" - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - bundle cmd + bundle "config set cache_all true" + bundle :cache + bundle :cache - expect(err).not_to include("Your Gemfile contains path and git dependencies.") - end + expect(err).not_to include("Your Gemfile contains path and git dependencies.") + end - it "caches pre-evaluated gemspecs" do - git = build_git "foo" + it "caches pre-evaluated gemspecs" do + git = build_git "foo" - # Insert a gemspec method that shells out - spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n") - spec_lines.insert(-2, "s.description = `echo bob`") - update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") } + # Insert a gemspec method that shells out + spec_lines = lib_path("foo-1.0/foo.gemspec").read.split("\n") + spec_lines.insert(-2, "s.description = `echo bob`") + update_git("foo") {|s| s.write "foo.gemspec", spec_lines.join("\n") } - install_gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - bundle "config set cache_all true" - bundle cmd + install_gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + bundle "config set cache_all true" + bundle :cache - ref = git.ref_for("master", 11) - gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read - expect(gemspec).to_not match("`echo bob`") - end + ref = git.ref_for("master", 11) + gemspec = bundled_app("vendor/cache/foo-1.0-#{ref}/foo.gemspec").read + expect(gemspec).to_not match("`echo bob`") + end - it "can install after #{cmd} with git not installed" do - build_git "foo" + it "can install after bundle cache with git not installed" do + build_git "foo" - gemfile <<-G - gem "foo", :git => '#{lib_path("foo-1.0")}' - G - bundle! "config set cache_all true" - bundle! cmd, "all-platforms" => true, :install => false, :path => "./vendor/cache" + gemfile <<-G + gem "foo", :git => '#{lib_path("foo-1.0")}' + G + bundle! "config set cache_all true" + bundle! :cache, "all-platforms" => true, :install => false, :path => "./vendor/cache" - simulate_new_machine - with_path_as "" do - bundle! "config set deployment true" - bundle! :install, :local => true - expect(the_bundle).to include_gem "foo 1.0" - end + simulate_new_machine + with_path_as "" do + bundle! "config set deployment true" + bundle! :install, :local => true + expect(the_bundle).to include_gem "foo 1.0" end end end diff --git a/spec/cache/path_spec.rb b/spec/cache/path_spec.rb index 3bbd7b1805..79e8b4a82b 100644 --- a/spec/cache/path_spec.rb +++ b/spec/cache/path_spec.rb @@ -1,146 +1,144 @@ # frozen_string_literal: true -%w[cache package].each do |cmd| - RSpec.describe "bundle #{cmd} with path" do - it "is no-op when the path is within the bundle" do - build_lib "foo", :path => bundled_app("lib/foo") - - install_gemfile <<-G - gem "foo", :path => '#{bundled_app("lib/foo")}' - G - - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0")).not_to exist - expect(the_bundle).to include_gems "foo 1.0" - end +RSpec.describe "bundle cache with path" do + it "is no-op when the path is within the bundle" do + build_lib "foo", :path => bundled_app("lib/foo") + + install_gemfile <<-G + gem "foo", :path => '#{bundled_app("lib/foo")}' + G + + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0")).not_to exist + expect(the_bundle).to include_gems "foo 1.0" + end - it "copies when the path is outside the bundle " do - build_lib "foo" + it "copies when the path is outside the bundle " do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/foo-1.0")).to exist - expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/foo-1.0")).to exist + expect(bundled_app("vendor/cache/foo-1.0/.bundlecache")).to be_file - FileUtils.rm_rf lib_path("foo-1.0") - expect(the_bundle).to include_gems "foo 1.0" - end + FileUtils.rm_rf lib_path("foo-1.0") + expect(the_bundle).to include_gems "foo 1.0" + end - it "copies when the path is outside the bundle and the paths intersect" do - libname = File.basename(Dir.pwd) + "_gem" - libpath = File.join(File.dirname(Dir.pwd), libname) + it "copies when the path is outside the bundle and the paths intersect" do + libname = File.basename(Dir.pwd) + "_gem" + libpath = File.join(File.dirname(Dir.pwd), libname) - build_lib libname, :path => libpath + build_lib libname, :path => libpath - install_gemfile <<-G - gem "#{libname}", :path => '#{libpath}' - G + install_gemfile <<-G + gem "#{libname}", :path => '#{libpath}' + G - bundle "config set cache_all true" - bundle cmd - expect(bundled_app("vendor/cache/#{libname}")).to exist - expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file + bundle "config set cache_all true" + bundle :cache + expect(bundled_app("vendor/cache/#{libname}")).to exist + expect(bundled_app("vendor/cache/#{libname}/.bundlecache")).to be_file - FileUtils.rm_rf libpath - expect(the_bundle).to include_gems "#{libname} 1.0" - end + FileUtils.rm_rf libpath + expect(the_bundle).to include_gems "#{libname} 1.0" + end - it "updates the path on each cache" do - build_lib "foo" + it "updates the path on each cache" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd + bundle "config set cache_all true" + bundle :cache - build_lib "foo" do |s| - s.write "lib/foo.rb", "puts :CACHE" - end + build_lib "foo" do |s| + s.write "lib/foo.rb", "puts :CACHE" + end - bundle cmd + bundle :cache - expect(bundled_app("vendor/cache/foo-1.0")).to exist - FileUtils.rm_rf lib_path("foo-1.0") + expect(bundled_app("vendor/cache/foo-1.0")).to exist + FileUtils.rm_rf lib_path("foo-1.0") - run "require 'foo'" - expect(out).to eq("CACHE") - end + run "require 'foo'" + expect(out).to eq("CACHE") + end - it "removes stale entries cache" do - build_lib "foo" + it "removes stale entries cache" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd + bundle "config set cache_all true" + bundle :cache - install_gemfile <<-G - gem "bar", :path => '#{lib_path("bar-1.0")}' - G + install_gemfile <<-G + gem "bar", :path => '#{lib_path("bar-1.0")}' + G - bundle cmd - expect(bundled_app("vendor/cache/bar-1.0")).not_to exist - end + bundle :cache + expect(bundled_app("vendor/cache/bar-1.0")).not_to exist + end - it "raises a warning without --all", :bundler => "< 3" do - build_lib "foo" + it "raises a warning without --all", :bundler => "< 3" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle cmd - expect(err).to match(/please pass the \-\-all flag/) - expect(bundled_app("vendor/cache/foo-1.0")).not_to exist - end + bundle :cache + expect(err).to match(/please pass the \-\-all flag/) + expect(bundled_app("vendor/cache/foo-1.0")).not_to exist + end - it "stores the given flag" do - build_lib "foo" + it "stores the given flag" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - build_lib "bar" + bundle "config set cache_all true" + bundle :cache + build_lib "bar" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "bar", :path => '#{lib_path("bar-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + gem "bar", :path => '#{lib_path("bar-1.0")}' + G - bundle cmd - expect(bundled_app("vendor/cache/bar-1.0")).to exist - end + bundle :cache + expect(bundled_app("vendor/cache/bar-1.0")).to exist + end - it "can rewind chosen configuration" do - build_lib "foo" + it "can rewind chosen configuration" do + build_lib "foo" - install_gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - G + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G - bundle "config set cache_all true" - bundle cmd - build_lib "baz" + bundle "config set cache_all true" + bundle :cache + build_lib "baz" - gemfile <<-G - gem "foo", :path => '#{lib_path("foo-1.0")}' - gem "baz", :path => '#{lib_path("baz-1.0")}' - G + gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + gem "baz", :path => '#{lib_path("baz-1.0")}' + G - bundle "#{cmd} --no-all" - expect(bundled_app("vendor/cache/baz-1.0")).not_to exist - end + bundle "cache --no-all" + expect(bundled_app("vendor/cache/baz-1.0")).not_to exist end end diff --git a/spec/commands/cache_spec.rb b/spec/commands/cache_spec.rb new file mode 100644 index 0000000000..07ec186c2f --- /dev/null +++ b/spec/commands/cache_spec.rb @@ -0,0 +1,351 @@ +# frozen_string_literal: true + +RSpec.describe "bundle cache" do + context "with --gemfile" do + it "finds the gemfile" do + gemfile bundled_app("NotGemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + G + + bundle "cache --gemfile=NotGemfile" + + ENV["BUNDLE_GEMFILE"] = "NotGemfile" + expect(the_bundle).to include_gems "rack 1.0.0" + end + end + + context "with --all" do + context "without a gemspec" do + it "caches all dependencies except bundler itself" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gem 'bundler' + D + + bundle "config set cache_all true" + bundle :cache + + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + + context "with a gemspec" do + context "that has the same name as the gem" 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 + end + + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gemspec + D + + bundle "config set cache_all true" + bundle! :cache + + 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/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + end + end + + context "that has a different name as the gem" do + before do + File.open(bundled_app("mygem_diffname.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 + end + + it "caches all dependencies except bundler and the gemspec specified gem" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + gemspec + D + + bundle "config set cache_all true" + bundle! :cache + + 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/mygem-0.1.1.gem")).to_not exist + expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist + 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_uri_for(gem_repo1)}" + gem 'rack' + gemspec :name => 'mygem' + gemspec :name => 'mygem_test' + D + + bundle "config set cache_all true" + bundle! :cache + + 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", :bundler => "< 3" do + it "sets root directory for gems" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! :cache, forgotten_command_line_options(:path => bundled_app("test")) + + expect(the_bundle).to include_gems "rack 1.0.0" + expect(bundled_app("test/vendor/cache/")).to exist + end + end + + context "with --no-install" do + it "puts the gems in vendor/cache but does not install them" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! "cache --no-install" + + expect(the_bundle).not_to include_gems "rack 1.0.0" + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + end + + it "does not prevent installing gems with bundle install" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack' + D + + bundle! "cache --no-install" + bundle! "install" + + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not prevent installing gems with bundle update" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem "rack", "1.0.0" + D + + bundle! "cache --no-install" + bundle! "update --all" + + expect(the_bundle).to include_gems "rack 1.0.0" + end + end + + context "with --all-platforms" do + it "puts the gems in vendor/cache even for other rubies" do + gemfile <<-D + source "#{file_uri_for(gem_repo1)}" + gem 'rack', :platforms => :ruby_19 + D + + bundle "cache --all-platforms" + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + end + + it "does not attempt to install gems in without groups" do + build_repo4 do + build_gem "uninstallable", "2.0" do |s| + s.add_development_dependency "rake" + s.extensions << "Rakefile" + s.write "Rakefile", "task(:default) { raise 'CANNOT INSTALL' }" + end + end + + install_gemfile! <<-G, forgotten_command_line_options(:without => "wo") + source "file:#{gem_repo1}" + gem "rack" + group :wo do + gem "weakling" + gem "uninstallable", :source => "file:#{gem_repo4}" + end + G + + bundle! :cache, "all-platforms" => true + expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist + expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + + bundle! :install, forgotten_command_line_options(:without => "wo") + expect(the_bundle).to include_gem "rack 1.0" + expect(the_bundle).not_to include_gems "weakling", "uninstallable" + end + end + + context "with --frozen" do + before do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundle "install" + end + + subject { bundle :cache, forgotten_command_line_options(:frozen => true) } + + it "tries to install with frozen" do + bundle! "config set deployment true" + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + gem "rack-obama" + G + subject + expect(exitstatus).to eq(16) if exitstatus + expect(err).to include("deployment mode") + expect(err).to include("You have added to the Gemfile") + expect(err).to include("* rack-obama") + bundle "env" + expect(out).to include("frozen").or include("deployment") + end + end +end + +RSpec.describe "bundle install with gem sources" do + describe "when cached and locked" do + it "does not hit the remote at all" do + build_repo2 + install_gemfile <<-G + source "#{file_uri_for(gem_repo2)}" + gem "rack" + G + + bundle :cache + simulate_new_machine + FileUtils.rm_rf gem_repo2 + + bundle "install --local" + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not hit the remote at all" do + build_repo2 + install_gemfile! <<-G + source "#{file_uri_for(gem_repo2)}" + gem "rack" + G + + bundle! :cache + simulate_new_machine + FileUtils.rm_rf gem_repo2 + + bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle") + expect(the_bundle).to include_gems "rack 1.0.0" + end + + it "does not reinstall already-installed gems" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundle :cache + + build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s| + s.write "lib/rack.rb", "raise 'omg'" + end + + bundle :install + expect(err).to be_empty + expect(the_bundle).to include_gems "rack 1.0" + end + + it "ignores cached gems for the wrong platform" do + simulate_platform "java" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "platform_specific" + G + bundle :cache + end + + simulate_new_machine + + simulate_platform "ruby" do + install_gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "platform_specific" + G + run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" + expect(out).to eq("1.0.0 RUBY") + end + end + + it "does not update the cache if --no-cache is passed" do + gemfile <<-G + source "#{file_uri_for(gem_repo1)}" + gem "rack" + G + bundled_app("vendor/cache").mkpath + expect(bundled_app("vendor/cache").children).to be_empty + + bundle "install --no-cache" + expect(bundled_app("vendor/cache").children).to be_empty + end + end +end diff --git a/spec/commands/package_spec.rb b/spec/commands/package_spec.rb deleted file mode 100644 index da22c002eb..0000000000 --- a/spec/commands/package_spec.rb +++ /dev/null @@ -1,351 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe "bundle package" do - context "with --gemfile" do - it "finds the gemfile" do - gemfile bundled_app("NotGemfile"), <<-G - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - G - - bundle "package --gemfile=NotGemfile" - - ENV["BUNDLE_GEMFILE"] = "NotGemfile" - expect(the_bundle).to include_gems "rack 1.0.0" - end - end - - context "with --all" do - context "without a gemspec" do - it "caches all dependencies except bundler itself" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gem 'bundler' - D - - bundle "config set cache_all true" - bundle :package - - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - - context "with a gemspec" do - context "that has the same name as the gem" 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 - end - - it "caches all dependencies except bundler and the gemspec specified gem" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gemspec - D - - bundle "config set cache_all true" - bundle! :package - - 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/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - end - end - - context "that has a different name as the gem" do - before do - File.open(bundled_app("mygem_diffname.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 - end - - it "caches all dependencies except bundler and the gemspec specified gem" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - gemspec - D - - bundle "config set cache_all true" - bundle! :package - - 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/mygem-0.1.1.gem")).to_not exist - expect(bundled_app("vendor/cache/bundler-0.9.gem")).to_not exist - 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_uri_for(gem_repo1)}" - gem 'rack' - gemspec :name => 'mygem' - gemspec :name => 'mygem_test' - D - - bundle "config set cache_all true" - bundle! :package - - 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", :bundler => "< 3" do - it "sets root directory for gems" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! :package, forgotten_command_line_options(:path => bundled_app("test")) - - expect(the_bundle).to include_gems "rack 1.0.0" - expect(bundled_app("test/vendor/cache/")).to exist - end - end - - context "with --no-install" do - it "puts the gems in vendor/cache but does not install them" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! "package --no-install" - - expect(the_bundle).not_to include_gems "rack 1.0.0" - expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist - end - - it "does not prevent installing gems with bundle install" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem 'rack' - D - - bundle! "package --no-install" - bundle! "install" - - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not prevent installing gems with bundle update" do - gemfile <<-D - source "#{file_uri_for(gem_repo1)}" - gem "rack", "1.0.0" - D - - bundle! "package --no-install" - bundle! "update --all" - - expect(the_bundle).to include_gems "rack 1.0.0" - end - end - - context "with --all-platforms" do - it "puts the gems in vendor/cache even for other rubies" do - gemfile <<-D - source "#{file_uri_for(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 - - it "does not attempt to install gems in without groups" do - build_repo4 do - build_gem "uninstallable", "2.0" do |s| - s.add_development_dependency "rake" - s.extensions << "Rakefile" - s.write "Rakefile", "task(:default) { raise 'CANNOT INSTALL' }" - end - end - - install_gemfile! <<-G, forgotten_command_line_options(:without => "wo") - source "file:#{gem_repo1}" - gem "rack" - group :wo do - gem "weakling" - gem "uninstallable", :source => "file:#{gem_repo4}" - end - G - - bundle! :package, "all-platforms" => true - expect(bundled_app("vendor/cache/weakling-0.0.3.gem")).to exist - expect(bundled_app("vendor/cache/uninstallable-2.0.gem")).to exist - expect(the_bundle).to include_gem "rack 1.0" - expect(the_bundle).not_to include_gems "weakling", "uninstallable" - - bundle! :install, forgotten_command_line_options(:without => "wo") - expect(the_bundle).to include_gem "rack 1.0" - expect(the_bundle).not_to include_gems "weakling", "uninstallable" - end - end - - context "with --frozen" do - before do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundle "install" - end - - subject { bundle :package, forgotten_command_line_options(:frozen => true) } - - it "tries to install with frozen" do - bundle! "config set deployment true" - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - gem "rack-obama" - G - subject - expect(exitstatus).to eq(16) if exitstatus - expect(err).to include("deployment mode") - expect(err).to include("You have added to the Gemfile") - expect(err).to include("* rack-obama") - bundle "env" - expect(out).to include("frozen").or include("deployment") - end - end -end - -RSpec.describe "bundle install with gem sources" do - describe "when cached and locked" do - it "does not hit the remote at all" do - build_repo2 - install_gemfile <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" - G - - bundle :pack - simulate_new_machine - FileUtils.rm_rf gem_repo2 - - bundle "install --local" - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not hit the remote at all" do - build_repo2 - install_gemfile! <<-G - source "#{file_uri_for(gem_repo2)}" - gem "rack" - G - - bundle! :pack - simulate_new_machine - FileUtils.rm_rf gem_repo2 - - bundle! :install, forgotten_command_line_options(:deployment => true, :path => "vendor/bundle") - expect(the_bundle).to include_gems "rack 1.0.0" - end - - it "does not reinstall already-installed gems" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundle :pack - - build_gem "rack", "1.0.0", :path => bundled_app("vendor/cache") do |s| - s.write "lib/rack.rb", "raise 'omg'" - end - - bundle :install - expect(err).to be_empty - expect(the_bundle).to include_gems "rack 1.0" - end - - it "ignores cached gems for the wrong platform" do - simulate_platform "java" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "platform_specific" - G - bundle :pack - end - - simulate_new_machine - - simulate_platform "ruby" do - install_gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "platform_specific" - G - run "require 'platform_specific' ; puts PLATFORM_SPECIFIC" - expect(out).to eq("1.0.0 RUBY") - end - end - - it "does not update the cache if --no-cache is passed" do - gemfile <<-G - source "#{file_uri_for(gem_repo1)}" - gem "rack" - G - bundled_app("vendor/cache").mkpath - expect(bundled_app("vendor/cache").children).to be_empty - - bundle "install --no-cache" - expect(bundled_app("vendor/cache").children).to be_empty - end - end -end diff --git a/spec/install/deploy_spec.rb b/spec/install/deploy_spec.rb index 79a344eaa1..d607f8bb46 100644 --- a/spec/install/deploy_spec.rb +++ b/spec/install/deploy_spec.rb @@ -390,7 +390,7 @@ You have deleted from the Gemfile: expect(the_bundle).to include_gems "foo 1.0" bundle "config set cache_all true" - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/foo")).to be_directory bundle! "install --local" diff --git a/spec/install/gemfile/git_spec.rb b/spec/install/gemfile/git_spec.rb index 014724a292..08789820d8 100644 --- a/spec/install/gemfile/git_spec.rb +++ b/spec/install/gemfile/git_spec.rb @@ -1391,7 +1391,7 @@ In Gemfile: end G bundle "config set cache_all true" - bundle :package + bundle :cache simulate_new_machine bundle! "install", :env => { "PATH" => "" } diff --git a/spec/install/gemfile/sources_spec.rb b/spec/install/gemfile/sources_spec.rb index b2861e1c00..61943ef2e5 100644 --- a/spec/install/gemfile/sources_spec.rb +++ b/spec/install/gemfile/sources_spec.rb @@ -102,7 +102,7 @@ RSpec.describe "bundle install with gems on multiple sources" do end it "can cache and deploy" do - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist expect(bundled_app("vendor/cache/rack-obama-1.0.gem")).to exist diff --git a/spec/lock/lockfile_spec.rb b/spec/lock/lockfile_spec.rb index df30bc0400..e291fb7917 100644 --- a/spec/lock/lockfile_spec.rb +++ b/spec/lock/lockfile_spec.rb @@ -621,7 +621,7 @@ RSpec.describe "the lockfile format" do G bundle "config set cache_all true" - bundle! :package + bundle! :cache bundle! :install, :local => true lockfile_should_be <<-G diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index 051c555980..d40b4d76bc 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -781,7 +781,7 @@ G #{ruby_version_correct} G - bundle :pack + bundle :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end @@ -794,7 +794,7 @@ G #{ruby_version_correct_engineless} G - bundle :pack + bundle :cache expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist end end @@ -806,7 +806,7 @@ G #{ruby_version_incorrect} G - bundle :pack + bundle :cache should_be_ruby_version_incorrect end @@ -817,7 +817,7 @@ G #{engine_incorrect} G - bundle :pack + bundle :cache should_be_engine_incorrect end @@ -829,7 +829,7 @@ G #{engine_version_incorrect} G - bundle :pack + bundle :cache should_be_engine_version_incorrect end end @@ -842,7 +842,7 @@ G #{patchlevel_incorrect} G - bundle :pack + bundle :cache should_be_patchlevel_incorrect end end diff --git a/spec/plugins/source/example_spec.rb b/spec/plugins/source/example_spec.rb index 1ef7c2134d..64002d8f46 100644 --- a/spec/plugins/source/example_spec.rb +++ b/spec/plugins/source/example_spec.rb @@ -169,7 +169,7 @@ RSpec.describe "real source plugins" do it "bundler package copies repository to vendor cache" do bundle! :install, forgotten_command_line_options(:path => "vendor/bundle") bundle "config set cache_all true" - bundle! :package + bundle! :cache expect(bundled_app("vendor/cache/a-path-gem-1.0-#{uri_hash}")).to exist -- cgit v1.2.1