summaryrefslogtreecommitdiff
path: root/lib/bundler
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2022-07-29 14:59:56 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2022-07-29 15:46:15 +0900
commitbfd09b1116bcc747bab922b23c7322e4ec66c2c2 (patch)
tree38c52d7a1f5790f8902eb585267e5da5f9e76399 /lib/bundler
parentf29f1d22c3d62b72b8943eefb384cd7a52251ea1 (diff)
Merge rubygems master from https://github.com/rubygems/rubygems/commit/446cc57a7ccdf1924deb291be9571219e7ba8523
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6198
Diffstat (limited to 'lib/bundler')
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/definition.rb31
-rw-r--r--lib/bundler/installer.rb9
-rw-r--r--lib/bundler/man/bundle-config.17
-rw-r--r--lib/bundler/man/bundle-config.1.ronn5
-rw-r--r--lib/bundler/man/bundle-inject.15
-rw-r--r--lib/bundler/man/bundle-inject.1.ronn4
-rw-r--r--lib/bundler/man/bundle-install.14
-rw-r--r--lib/bundler/man/bundle-install.1.ronn6
-rw-r--r--lib/bundler/man/bundle.15
-rw-r--r--lib/bundler/man/bundle.1.ronn3
-rw-r--r--lib/bundler/ruby_version.rb10
-rw-r--r--lib/bundler/rubygems_ext.rb9
-rw-r--r--lib/bundler/settings.rb1
-rw-r--r--lib/bundler/source/metadata.rb2
15 files changed, 89 insertions, 14 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index e1c284130b..e9ef47f9ba 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -218,6 +218,8 @@ module Bundler
"Specify the number of jobs to run in parallel"
method_option "local", :type => :boolean, :banner =>
"Do not attempt to fetch gems remotely and use the gem cache instead"
+ method_option "prefer-local", :type => :boolean, :banner =>
+ "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely"
method_option "no-cache", :type => :boolean, :banner =>
"Don't update the existing gem cache."
method_option "redownload", :type => :boolean, :aliases => "--force", :banner =>
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 4cb829470a..3e93b45171 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -70,6 +70,7 @@ module Bundler
@unlock = unlock
@optional_groups = optional_groups
@remote = false
+ @prefer_local = false
@specs = nil
@ruby_version = ruby_version
@gemfiles = gemfiles
@@ -170,6 +171,13 @@ module Bundler
resolve
end
+ def resolve_prefering_local!
+ @prefer_local = true
+ @remote = true
+ sources.remote!
+ resolve
+ end
+
def resolve_with_cache!
sources.cached!
resolve
@@ -528,6 +536,19 @@ module Bundler
@remote && sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source?
end
+ def pin_locally_available_names(source_requirements)
+ source_requirements.each_with_object({}) do |(name, original_source), new_source_requirements|
+ local_source = original_source.dup
+ local_source.local_only!
+
+ new_source_requirements[name] = if local_source.specs.search(name).any?
+ local_source
+ else
+ original_source
+ end
+ end
+ end
+
def current_ruby_platform_locked?
return false unless generic_local_platform == Gem::Platform::RUBY
return false if Bundler.settings[:force_ruby_platform] && !@platforms.include?(Gem::Platform::RUBY)
@@ -765,7 +786,7 @@ module Bundler
def metadata_dependencies
@metadata_dependencies ||= [
- Dependency.new("Ruby\0", RubyVersion.system.gem_version),
+ Dependency.new("Ruby\0", Gem.ruby_version),
Dependency.new("RubyGems\0", Gem::VERSION),
]
end
@@ -792,7 +813,9 @@ module Bundler
# specs will be available later when the resolver knows where to
# look for that gemspec (or its dependencies)
source_requirements = if precompute_source_requirements_for_indirect_dependencies?
- { :default => sources.default_source }.merge(source_map.all_requirements)
+ all_requirements = source_map.all_requirements
+ all_requirements = pin_locally_available_names(all_requirements) if @prefer_local
+ { :default => sources.default_source }.merge(all_requirements)
else
{ :default => Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements)
end
@@ -806,7 +829,9 @@ module Bundler
end
def requested_groups
- groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with]
+ values = groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with]
+ values &= Bundler.settings[:only] unless Bundler.settings[:only].empty?
+ values
end
def lockfiles_equal?(current, proposed, preserve_unknown_sections)
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index f195d36600..b7b0e36dfd 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -268,7 +268,14 @@ module Bundler
return false if @definition.nothing_changed? && !@definition.missing_specs?
end
- options["local"] ? @definition.resolve_with_cache! : @definition.resolve_remotely!
+ if options["local"]
+ @definition.resolve_with_cache!
+ elsif options["prefer-local"]
+ @definition.resolve_prefering_local!
+ else
+ @definition.resolve_remotely!
+ end
+
true
end
diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1
index 76b444d8c6..b5cee57f29 100644
--- a/lib/bundler/man/bundle-config.1
+++ b/lib/bundler/man/bundle-config.1
@@ -74,6 +74,10 @@ Creates a directory (defaults to \fB~/bin\fR) and place any executables from the
In deployment mode, Bundler will \'roll\-out\' the bundle for \fBproduction\fR use\. Please check carefully if you want to have this option enabled in \fBdevelopment\fR or \fBtest\fR environments\.
.
.TP
+\fBonly\fR
+A space\-separated list of groups to install only gems of the specified groups\.
+.
+.TP
\fBpath\fR
The location to install the specified gems to\. This defaults to Rubygems\' setting\. Bundler shares this location with Rubygems, \fBgem install \.\.\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \.\.\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\.
.
@@ -223,6 +227,9 @@ The following is a list of all configuration keys and their purpose\. You can le
\fBno_prune\fR (\fBBUNDLE_NO_PRUNE\fR): Whether Bundler should leave outdated gems unpruned when caching\.
.
.IP "\(bu" 4
+\fBonly\fR (\fBBUNDLE_ONLY\fR): A space\-separated list of groups to install only gems of the specified groups\.
+.
+.IP "\(bu" 4
\fBpath\fR (\fBBUNDLE_PATH\fR): The location on disk where all gems in your bundle will be located regardless of \fB$GEM_HOME\fR or \fB$GEM_PATH\fR values\. Bundle gems not found in this location will be installed by \fBbundle install\fR\. Defaults to \fBGem\.dir\fR\. When \-\-deployment is used, defaults to vendor/bundle\.
.
.IP "\(bu" 4
diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn
index 8a636641c0..e2af773141 100644
--- a/lib/bundler/man/bundle-config.1.ronn
+++ b/lib/bundler/man/bundle-config.1.ronn
@@ -74,6 +74,9 @@ The options that can be configured are:
`production` use. Please check carefully if you want to have this option
enabled in `development` or `test` environments.
+* `only`:
+ A space-separated list of groups to install only gems of the specified groups.
+
* `path`:
The location to install the specified gems to. This defaults to Rubygems'
setting. Bundler shares this location with Rubygems, `gem install ...` will
@@ -218,6 +221,8 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
Whether `bundle package` should skip installing gems.
* `no_prune` (`BUNDLE_NO_PRUNE`):
Whether Bundler should leave outdated gems unpruned when caching.
+* `only` (`BUNDLE_ONLY`):
+ A space-separated list of groups to install only gems of the specified groups.
* `path` (`BUNDLE_PATH`):
The location on disk where all gems in your bundle will be located regardless
of `$GEM_HOME` or `$GEM_PATH` values. Bundle gems not found in this location
diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1
index 0f6627d9a3..53f2eaae0a 100644
--- a/lib/bundler/man/bundle-inject.1
+++ b/lib/bundler/man/bundle-inject.1
@@ -30,4 +30,7 @@ bundle inject \'rack\' \'> 0\'
.IP "" 0
.
.P
-This will inject the \'rack\' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock
+This will inject the \'rack\' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock\.
+.
+.P
+The \fBbundle inject\fR command was deprecated in Bundler 2\.1 and will be removed in Bundler 3\.0\.
diff --git a/lib/bundler/man/bundle-inject.1.ronn b/lib/bundler/man/bundle-inject.1.ronn
index f454341896..95704eddad 100644
--- a/lib/bundler/man/bundle-inject.1.ronn
+++ b/lib/bundler/man/bundle-inject.1.ronn
@@ -19,4 +19,6 @@ Example:
bundle inject 'rack' '> 0'
This will inject the 'rack' gem with a version greater than 0 in your
-[`Gemfile(5)`][Gemfile(5)] and Gemfile.lock
+[`Gemfile(5)`][Gemfile(5)] and Gemfile.lock.
+
+The `bundle inject` command was deprecated in Bundler 2.1 and will be removed in Bundler 3.0.
diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1
index c742efd142..8e94fe2437 100644
--- a/lib/bundler/man/bundle-install.1
+++ b/lib/bundler/man/bundle-install.1
@@ -70,6 +70,10 @@ The maximum number of parallel download and install jobs\. The default is the nu
Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems\' cache or in \fBvendor/cache\fR\. Note that if an appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\.
.
.TP
+\fB\-\-prefer\-local\fR
+Force using locally installed gems, or gems already present in Rubygems\' cache or in \fBvendor/cache\fR, when resolving, even if newer versions are available remotely\. Only attempt to connect to \fBrubygems\.org\fR for gems that are not present locally\.
+.
+.TP
\fB\-\-no\-cache\fR
Do not update the cache in \fBvendor/cache\fR with the newly bundled gems\. This does not remove any gems in the cache but keeps the newly bundled gems from being cached during the install\.
.
diff --git a/lib/bundler/man/bundle-install.1.ronn b/lib/bundler/man/bundle-install.1.ronn
index bec05187f3..47200ac2d5 100644
--- a/lib/bundler/man/bundle-install.1.ronn
+++ b/lib/bundler/man/bundle-install.1.ronn
@@ -109,6 +109,12 @@ automatically and that requires `bundler` to silently remember them. Since
appropriate platform-specific gem exists on `rubygems.org` it will not be
found.
+* `--prefer-local`:
+ Force using locally installed gems, or gems already present in Rubygems' cache
+ or in `vendor/cache`, when resolving, even if newer versions are available
+ remotely. Only attempt to connect to `rubygems.org` for gems that are not
+ present locally.
+
* `--no-cache`:
Do not update the cache in `vendor/cache` with the newly bundled gems. This
does not remove any gems in the cache but keeps the newly bundled gems from
diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1
index c80ef51992..efc4d7e93f 100644
--- a/lib/bundler/man/bundle.1
+++ b/lib/bundler/man/bundle.1
@@ -81,7 +81,7 @@ Show the source location of a particular gem in the bundle
Show all of the outdated gems in the current bundle
.
.TP
-\fBbundle console(1)\fR
+\fBbundle console(1)\fR (deprecated)
Start an IRB session in the current bundle
.
.TP
@@ -129,5 +129,8 @@ These commands are obsolete and should no longer be used:
.IP "\(bu" 4
\fBbundle cache(1)\fR
.
+.IP "\(bu" 4
+\fBbundle inject(1)\fR
+.
.IP "" 0
diff --git a/lib/bundler/man/bundle.1.ronn b/lib/bundler/man/bundle.1.ronn
index 86d771f024..52a00d43ee 100644
--- a/lib/bundler/man/bundle.1.ronn
+++ b/lib/bundler/man/bundle.1.ronn
@@ -67,7 +67,7 @@ We divide `bundle` subcommands into primary commands and utilities:
* [`bundle outdated(1)`](bundle-outdated.1.html):
Show all of the outdated gems in the current bundle
-* `bundle console(1)`:
+* `bundle console(1)` (deprecated):
Start an IRB session in the current bundle
* [`bundle open(1)`](bundle-open.1.html):
@@ -108,3 +108,4 @@ and execute it, passing down any extra arguments to it.
These commands are obsolete and should no longer be used:
* `bundle cache(1)`
+* `bundle inject(1)`
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 3f51cf4528..9161c6afde 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -32,12 +32,12 @@ module Bundler
@engine = engine && engine.to_s || "ruby"
@engine_versions = (engine_version && Array(engine_version)) || @versions
@engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last
- @patchlevel = patchlevel
+ @patchlevel = patchlevel || (@gem_version.prerelease? ? "-1" : nil)
end
def to_s(versions = self.versions)
output = String.new("ruby #{versions_string(versions)}")
- output << "p#{patchlevel}" if patchlevel
+ output << "p#{patchlevel}" if patchlevel && patchlevel != "-1"
output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby"
output
@@ -46,7 +46,7 @@ module Bundler
# @private
PATTERN = /
ruby\s
- ([\d.]+) # ruby version
+ (\d+\.\d+\.\d+(?:\.\S+)?) # ruby version
(?:p(-?\d+))? # optional patchlevel
(?:\s\((\S+)\s(.+)\))? # optional engine info
/xo.freeze
@@ -103,8 +103,8 @@ module Bundler
def self.system
ruby_engine = RUBY_ENGINE.dup
- ruby_version = RUBY_VERSION.dup
- ruby_engine_version = RUBY_ENGINE_VERSION.dup
+ ruby_version = Gem.ruby_version.to_s
+ ruby_engine_version = RUBY_ENGINE == "ruby" ? ruby_version : RUBY_ENGINE_VERSION.dup
patchlevel = RUBY_PATCHLEVEL.to_s
@ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version)
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index a47692d1f2..e8e03fcf8f 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -17,6 +17,15 @@ require "rubygems/source"
require_relative "match_platform"
+# Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
+# versions and ignore patchlevels
+# (https://github.com/rubygems/rubygems/pull/5472,
+# https://github.com/rubygems/rubygems/pull/5486). May be removed once RubyGems
+# 3.3.12 support is dropped.
+unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1
+ Gem.instance_variable_set(:@ruby_version, Gem::Version.new(RUBY_VERSION))
+end
+
module Gem
class Specification
include ::Bundler::MatchPlatform
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 398c66055a..cf5675274e 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -57,6 +57,7 @@ module Bundler
].freeze
ARRAY_KEYS = %w[
+ only
with
without
].freeze
diff --git a/lib/bundler/source/metadata.rb b/lib/bundler/source/metadata.rb
index 185fe70824..23531b8bd4 100644
--- a/lib/bundler/source/metadata.rb
+++ b/lib/bundler/source/metadata.rb
@@ -5,7 +5,7 @@ module Bundler
class Metadata < Source
def specs
@specs ||= Index.build do |idx|
- idx << Gem::Specification.new("Ruby\0", RubyVersion.system.gem_version)
+ idx << Gem::Specification.new("Ruby\0", Gem.ruby_version)
idx << Gem::Specification.new("RubyGems\0", Gem::VERSION) do |s|
s.required_rubygems_version = Gem::Requirement.default
end