diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-01-25 23:32:01 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 23:32:01 +0900 |
commit | a22eca82314ae36668d8c1a591ffbbfa8f93147c (patch) | |
tree | b855091cbc6d28deba95467610017985dd30f78b /lib | |
parent | fee5b8f263211faef10ed9f3e43c1e8b34548bbd (diff) |
Merge the latest stable versions of RubyGems and Bundler to Ruby 3.2.x (#7061)
[Bug #19350]
* Merge RubyGems-3.4.2 and Bundler-2.4.2
* Merge RubyGems-3.4.3 and Bundler-2.4.3
* Generate parser-text.rb of racc when sync it
* Ignore LICENSE files of libraries vendored in rubygems [ci skip]
* Adjust spec of bundler like as `sync_default_gems` [ci skip]
* Fixed a typo
* Removed vendored LICENSE file.
* Update LEGAL sections for pub_grub
* Merge RubyGems-3.4.4 and Bundler-2.4.4
* Merge RubyGems-3.4.5 and Bundler-2.4.5
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Diffstat (limited to 'lib')
60 files changed, 383 insertions, 290 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 6745740f11..ee73bdb506 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -509,6 +509,7 @@ module Bundler subcommand "config", Config desc "open GEM", "Opens the source directory of the given bundled gem" + method_option "path", :type => :string, :lazy_default => "", :banner => "Open relative path of the gem source." def open(name) require_relative "cli/open" Open.new(options, name).run diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb index ea504344f3..8522ec92d6 100644 --- a/lib/bundler/cli/open.rb +++ b/lib/bundler/cli/open.rb @@ -2,23 +2,25 @@ module Bundler class CLI::Open - attr_reader :options, :name + attr_reader :options, :name, :path def initialize(options, name) @options = options @name = name + @path = options[:path] unless options[:path].nil? end def run + raise InvalidOption, "Cannot specify `--path` option without a value" if !@path.nil? && @path.empty? editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? } return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match) if spec.default_gem? Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist." else - path = spec.full_gem_path - Dir.chdir(path) do + root_path = spec.full_gem_path + Dir.chdir(root_path) do require "shellwords" - command = Shellwords.split(editor) + [path] + command = Shellwords.split(editor) << File.join([root_path, path].compact) Bundler.with_original_env do system(*command) end || Bundler.ui.info("Could not run '#{command.join(" ")}'") diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 348f1b6a3d..e27374f35d 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -79,6 +79,7 @@ module Bundler @locked_bundler_version = nil @locked_ruby_version = nil @new_platform = nil + @removed_platform = nil if lockfile && File.exist?(lockfile) @lockfile_contents = Bundler.read_file(lockfile) @@ -129,7 +130,7 @@ module Bundler end @unlocking ||= @unlock[:ruby] ||= (!@locked_ruby_version ^ !@ruby_version) - add_current_platform unless current_ruby_platform_locked? || Bundler.frozen_bundle? + add_current_platform unless Bundler.frozen_bundle? converge_path_sources_to_gemspec_sources @path_changes = converge_paths @@ -158,13 +159,6 @@ module Bundler resolve end - def resolve_prefering_local! - @prefer_local = true - @remote = true - sources.remote! - resolve - end - def resolve_with_cache! sources.cached! resolve @@ -176,6 +170,23 @@ module Bundler resolve end + def resolution_mode=(options) + if options["local"] + @remote = false + else + @remote = true + @prefer_local = options["prefer-local"] + end + end + + def setup_sources_for_resolve + if @remote == false + sources.cached! + else + sources.remote! + end + end + # For given dependency list returns a SpecSet with Gemspec of all the required # dependencies. # 1. The method first resolves the dependencies specified in Gemfile @@ -267,7 +278,7 @@ module Bundler SpecSet.new(filter_specs(@locked_specs, @dependencies - deleted_deps)) else Bundler.ui.debug "Found no changes, using resolution from the lockfile" - if @locked_gems.may_include_redundant_platform_specific_gems? + if @removed_platform || @locked_gems.may_include_redundant_platform_specific_gems? SpecSet.new(filter_specs(@locked_specs, @dependencies)) else @locked_specs @@ -446,7 +457,9 @@ module Bundler end def remove_platform(platform) - return if @platforms.delete(Gem::Platform.new(platform)) + removed_platform = @platforms.delete(Gem::Platform.new(platform)) + @removed_platform ||= removed_platform + return if removed_platform raise InvalidOption, "Unable to remove the platform `#{platform}` since the only platforms are #{@platforms.join ", "}" end @@ -470,31 +483,19 @@ module Bundler private def resolver - @resolver ||= begin - last_resolve = converge_locked_specs - remove_ruby_from_platforms_if_necessary!(current_dependencies) - Resolver.new(source_requirements, last_resolve, gem_version_promoter, additional_base_requirements_for_resolve(last_resolve)) - end + @resolver ||= Resolver.new(resolution_packages, gem_version_promoter) end def expanded_dependencies - @expanded_dependencies ||= dependencies + metadata_dependencies + dependencies + metadata_dependencies end def resolution_packages @resolution_packages ||= begin - packages = Hash.new do |h, k| - h[k] = Resolver::Package.new(k, @platforms, @originally_locked_specs, @unlock[:gems]) - end - - expanded_dependencies.each do |dep| - name = dep.name - platforms = dep.gem_platforms(@platforms) - - packages[name] = Resolver::Package.new(name, platforms, @originally_locked_specs, @unlock[:gems], :dependency => dep) - end - - packages + last_resolve = converge_locked_specs + remove_ruby_from_platforms_if_necessary!(current_dependencies) + packages = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, :locked_specs => @originally_locked_specs, :unlock => @unlock[:gems], :prerelease => gem_version_promoter.pre?) + additional_base_requirements_for_resolve(packages, last_resolve) end end @@ -528,13 +529,15 @@ module Bundler break if incomplete_specs.empty? Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies") - @resolve = start_resolution(:exclude_specs => incomplete_specs) + setup_sources_for_resolve + resolution_packages.delete(incomplete_specs) + @resolve = start_resolution specs = resolve.materialize(dependencies) still_incomplete_specs = specs.incomplete_specs if still_incomplete_specs == incomplete_specs - package = resolution_packages[incomplete_specs.first.name] + package = resolution_packages.get_package(incomplete_specs.first.name) resolver.raise_not_found! package end @@ -547,14 +550,14 @@ module Bundler specs end - def start_resolution(exclude_specs: []) - result = resolver.start(expanded_dependencies, resolution_packages, :exclude_specs => exclude_specs) + def start_resolution + result = resolver.start SpecSet.new(SpecSet.new(result).for(dependencies, false, @platforms)) end def precompute_source_requirements_for_indirect_dependencies? - @remote && sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source? + sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source? end def pin_locally_available_names(source_requirements) @@ -584,6 +587,8 @@ module Bundler end def add_current_platform + return if current_ruby_platform_locked? + add_platform(local_platform) end @@ -880,11 +885,12 @@ module Bundler current == proposed end - def additional_base_requirements_for_resolve(last_resolve) - return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources) - converge_specs(@originally_locked_specs - last_resolve).map do |locked_spec| - Dependency.new(locked_spec.name, ">= #{locked_spec.version}") - end.uniq + def additional_base_requirements_for_resolve(resolution_packages, last_resolve) + return resolution_packages unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources) + converge_specs(@originally_locked_specs - last_resolve).each do |locked_spec| + resolution_packages.base_requirements[locked_spec.name] = Gem::Requirement.new(">= #{locked_spec.version}") + end + resolution_packages end def remove_ruby_from_platforms_if_necessary!(dependencies) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 179fea4dfd..e74158a9f5 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -277,8 +277,8 @@ module Bundler if repo_name =~ GITHUB_PULL_REQUEST_URL { "git" => "https://github.com/#{$1}.git", - "branch" => "refs/pull/#{$2}/head", - "ref" => nil, + "branch" => nil, + "ref" => "refs/pull/#{$2}/head", "tag" => nil, } else diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 04d7dc6f23..680e812ac8 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -249,17 +249,13 @@ module Bundler # returns whether or not a re-resolve was needed def resolve_if_needed(options) + @definition.resolution_mode = options + if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file? return false if @definition.nothing_changed? && !@definition.missing_specs? end - if options["local"] - @definition.resolve_with_cache! - elsif options["prefer-local"] - @definition.resolve_prefering_local! - else - @definition.resolve_remotely! - end + @definition.setup_sources_for_resolve true end diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index ca51691b5c..6749892930 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -16,7 +16,6 @@ module Bundler @dependencies = [] @platform = platform || Gem::Platform::RUBY @source = source - @specification = nil @force_ruby_platform = default_force_ruby_platform end @@ -80,37 +79,46 @@ module Bundler def materialize_for_installation source.local! - candidates = if source.is_a?(Source::Path) || !ruby_platform_materializes_to_ruby_platform? - target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform + matching_specs = source.specs.search(use_exact_resolved_specifications? ? self : [name, version]) + return self if matching_specs.empty? - GemHelpers.select_best_platform_match(source.specs.search([name, version]), target_platform) + candidates = if use_exact_resolved_specifications? + matching_specs else - source.specs.search(self) - end + target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform - return self if candidates.empty? + installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform) - __materialize__(candidates) - end + specification = __materialize__(installable_candidates, :fallback_to_non_installable => false) + return specification unless specification.nil? - def __materialize__(candidates) - @specification = begin - search = candidates.reverse.find do |spec| - spec.is_a?(StubSpecification) || - (spec.matches_current_ruby? && - spec.matches_current_rubygems?) - end - if search.nil? && Bundler.frozen_bundle? - search = candidates.last - else - search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification)) + if target_platform != platform + installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform) end - search + + installable_candidates end + + __materialize__(candidates) end - def respond_to?(*args) - super || @specification ? @specification.respond_to?(*args) : nil + # If in frozen mode, we fallback to a non-installable candidate because by + # doing this we avoid re-resolving and potentially end up changing the + # lock file, which is not allowed. In that case, we will give a proper error + # about the mismatch higher up the stack, right before trying to install the + # bad gem. + def __materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?) + search = candidates.reverse.find do |spec| + spec.is_a?(StubSpecification) || + (spec.matches_current_ruby? && + spec.matches_current_rubygems?) + end + if search.nil? && fallback_to_non_installable + search = candidates.last + else + search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification)) + end + search end def to_s @@ -132,16 +140,8 @@ module Bundler private - def to_ary - nil - end - - def method_missing(method, *args, &blk) - raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification - - return super unless respond_to?(method) - - @specification.send(method, *args, &blk) + def use_exact_resolved_specifications? + @use_exact_resolved_specifications ||= !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform? end # diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index fd6949b38d..805bd5450d 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-ADD" "1" "December 2022" "" "" +.TH "BUNDLE\-ADD" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1 index 260d880d2b..f5efe77e10 100644 --- a/lib/bundler/man/bundle-binstubs.1 +++ b/lib/bundler/man/bundle-binstubs.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-BINSTUBS" "1" "December 2022" "" "" +.TH "BUNDLE\-BINSTUBS" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-binstubs\fR \- Install the binstubs of the listed gems diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1 index 4c48a83387..a17f1a6b06 100644 --- a/lib/bundler/man/bundle-cache.1 +++ b/lib/bundler/man/bundle-cache.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CACHE" "1" "December 2022" "" "" +.TH "BUNDLE\-CACHE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1 index c2df7837b8..f1bf0b1821 100644 --- a/lib/bundler/man/bundle-check.1 +++ b/lib/bundler/man/bundle-check.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CHECK" "1" "December 2022" "" "" +.TH "BUNDLE\-CHECK" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1 index 82df62ba18..b05a8eb0eb 100644 --- a/lib/bundler/man/bundle-clean.1 +++ b/lib/bundler/man/bundle-clean.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CLEAN" "1" "December 2022" "" "" +.TH "BUNDLE\-CLEAN" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 91215f7b13..fdb06c321d 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CONFIG" "1" "December 2022" "" "" +.TH "BUNDLE\-CONFIG" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-config\fR \- Set bundler configuration options @@ -39,7 +39,7 @@ Bundler default config .IP "" 0 . .P -Executing \fBbundle config list\fR with will print a list of all bundler configuration for the current bundle, and where that configuration was set\. +Executing \fBbundle config list\fR will print a list of all bundler configuration for the current bundle, and where that configuration was set\. . .P Executing \fBbundle config get <name>\fR will print the value of that configuration setting, and where it was set\. diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn index 6f9edc9c39..bc8b27cf89 100644 --- a/lib/bundler/man/bundle-config.1.ronn +++ b/lib/bundler/man/bundle-config.1.ronn @@ -19,7 +19,7 @@ Bundler loads configuration settings in this order: 3. Global config (`~/.bundle/config`) 4. Bundler default config -Executing `bundle config list` with will print a list of all bundler +Executing `bundle config list` will print a list of all bundler configuration for the current bundle, and where that configuration was set. diff --git a/lib/bundler/man/bundle-console.1 b/lib/bundler/man/bundle-console.1 index d802e04c9a..6cb0f0f810 100644 --- a/lib/bundler/man/bundle-console.1 +++ b/lib/bundler/man/bundle-console.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-CONSOLE" "1" "December 2022" "" "" +.TH "BUNDLE\-CONSOLE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-console\fR \- Deprecated way to open an IRB session with the bundle pre\-loaded diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1 index 2c6ebbc6ed..bfe928c9a1 100644 --- a/lib/bundler/man/bundle-doctor.1 +++ b/lib/bundler/man/bundle-doctor.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-DOCTOR" "1" "December 2022" "" "" +.TH "BUNDLE\-DOCTOR" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-doctor\fR \- Checks the bundle for common problems diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1 index 7d06945bc9..281f3faede 100644 --- a/lib/bundler/man/bundle-exec.1 +++ b/lib/bundler/man/bundle-exec.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-EXEC" "1" "December 2022" "" "" +.TH "BUNDLE\-EXEC" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-exec\fR \- Execute a command in the context of the bundle @@ -74,13 +74,13 @@ Finally, \fBbundle exec\fR also implicitly modifies \fBGemfile\.lock\fR if the l By default, when attempting to \fBbundle exec\fR to a file with a ruby shebang, Bundler will \fBKernel\.load\fR that file instead of using \fBKernel\.exec\fR\. For the vast majority of cases, this is a performance improvement\. In a rare few cases, this could cause some subtle side\-effects (such as dependence on the exact contents of \fB$0\fR or \fB__FILE__\fR) and the optimization can be disabled by enabling the \fBdisable_exec_load\fR setting\. . .SS "Shelling out" -Any Ruby code that opens a subshell (like \fBsystem\fR, backticks, or \fB%x{}\fR) will automatically use the current Bundler environment\. If you need to shell out to a Ruby command that is not part of your current bundle, use the \fBwith_clean_env\fR method with a block\. Any subshells created inside the block will be given the environment present before Bundler was activated\. For example, Homebrew commands run Ruby, but don\'t work inside a bundle: +Any Ruby code that opens a subshell (like \fBsystem\fR, backticks, or \fB%x{}\fR) will automatically use the current Bundler environment\. If you need to shell out to a Ruby command that is not part of your current bundle, use the \fBwith_unbundled_env\fR method with a block\. Any subshells created inside the block will be given the environment present before Bundler was activated\. For example, Homebrew commands run Ruby, but don\'t work inside a bundle: . .IP "" 4 . .nf -Bundler\.with_clean_env do +Bundler\.with_unbundled_env do `brew install wget` end . @@ -89,13 +89,13 @@ end .IP "" 0 . .P -Using \fBwith_clean_env\fR is also necessary if you are shelling out to a different bundle\. Any Bundler commands run in a subshell will inherit the current Gemfile, so commands that need to run in the context of a different bundle also need to use \fBwith_clean_env\fR\. +Using \fBwith_unbundled_env\fR is also necessary if you are shelling out to a different bundle\. Any Bundler commands run in a subshell will inherit the current Gemfile, so commands that need to run in the context of a different bundle also need to use \fBwith_unbundled_env\fR\. . .IP "" 4 . .nf -Bundler\.with_clean_env do +Bundler\.with_unbundled_env do Dir\.chdir "/other/bundler/project" do `bundle exec \./script` end diff --git a/lib/bundler/man/bundle-exec.1.ronn b/lib/bundler/man/bundle-exec.1.ronn index 5f5e78ed12..05948095e2 100644 --- a/lib/bundler/man/bundle-exec.1.ronn +++ b/lib/bundler/man/bundle-exec.1.ronn @@ -84,20 +84,20 @@ the `disable_exec_load` setting. Any Ruby code that opens a subshell (like `system`, backticks, or `%x{}`) will automatically use the current Bundler environment. If you need to shell out to a Ruby command that is not part of your current bundle, use the -`with_clean_env` method with a block. Any subshells created inside the block +`with_unbundled_env` method with a block. Any subshells created inside the block will be given the environment present before Bundler was activated. For example, Homebrew commands run Ruby, but don't work inside a bundle: - Bundler.with_clean_env do + Bundler.with_unbundled_env do `brew install wget` end -Using `with_clean_env` is also necessary if you are shelling out to a different +Using `with_unbundled_env` is also necessary if you are shelling out to a different bundle. Any Bundler commands run in a subshell will inherit the current Gemfile, so commands that need to run in the context of a different bundle also -need to use `with_clean_env`. +need to use `with_unbundled_env`. - Bundler.with_clean_env do + Bundler.with_unbundled_env do Dir.chdir "/other/bundler/project" do `bundle exec ./script` end diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1 index 11cc002194..4bac1bf442 100644 --- a/lib/bundler/man/bundle-gem.1 +++ b/lib/bundler/man/bundle-gem.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-GEM" "1" "December 2022" "" "" +.TH "BUNDLE\-GEM" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem diff --git a/lib/bundler/man/bundle-help.1 b/lib/bundler/man/bundle-help.1 index bc12edf18b..47a42a497e 100644 --- a/lib/bundler/man/bundle-help.1 +++ b/lib/bundler/man/bundle-help.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-HELP" "1" "December 2022" "" "" +.TH "BUNDLE\-HELP" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-help\fR \- Displays detailed help for each subcommand diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1 index 9a02b4f665..e9f5583e85 100644 --- a/lib/bundler/man/bundle-info.1 +++ b/lib/bundler/man/bundle-info.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INFO" "1" "December 2022" "" "" +.TH "BUNDLE\-INFO" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-info\fR \- Show information for the given gem in your bundle diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1 index fe6593f117..9e8b059f1f 100644 --- a/lib/bundler/man/bundle-init.1 +++ b/lib/bundler/man/bundle-init.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INIT" "1" "December 2022" "" "" +.TH "BUNDLE\-INIT" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-init\fR \- Generates a Gemfile into the current working directory diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1 index 781e82bdc8..0b0766a40c 100644 --- a/lib/bundler/man/bundle-inject.1 +++ b/lib/bundler/man/bundle-inject.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INJECT" "1" "December 2022" "" "" +.TH "BUNDLE\-INJECT" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-inject\fR \- Add named gem(s) with version requirements to Gemfile diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1 index c0be8e9b45..fcf6a6a66c 100644 --- a/lib/bundler/man/bundle-install.1 +++ b/lib/bundler/man/bundle-install.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-INSTALL" "1" "December 2022" "" "" +.TH "BUNDLE\-INSTALL" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-install\fR \- Install the dependencies specified in your Gemfile diff --git a/lib/bundler/man/bundle-list.1 b/lib/bundler/man/bundle-list.1 index 5bbd8806c4..37d2c837e4 100644 --- a/lib/bundler/man/bundle-list.1 +++ b/lib/bundler/man/bundle-list.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-LIST" "1" "December 2022" "" "" +.TH "BUNDLE\-LIST" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-list\fR \- List all the gems in the bundle diff --git a/lib/bundler/man/bundle-lock.1 b/lib/bundler/man/bundle-lock.1 index de1acf6d41..422da46d00 100644 --- a/lib/bundler/man/bundle-lock.1 +++ b/lib/bundler/man/bundle-lock.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-LOCK" "1" "December 2022" "" "" +.TH "BUNDLE\-LOCK" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-lock\fR \- Creates / Updates a lockfile without installing diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1 index 0b0dc29c7b..c831bf9ce9 100644 --- a/lib/bundler/man/bundle-open.1 +++ b/lib/bundler/man/bundle-open.1 @@ -1,13 +1,13 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-OPEN" "1" "December 2022" "" "" +.TH "BUNDLE\-OPEN" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-open\fR \- Opens the source directory for a gem in your bundle . .SH "SYNOPSIS" -\fBbundle open\fR [GEM] +\fBbundle open\fR [GEM] [\-\-path=PATH] . .SH "DESCRIPTION" Opens the source directory of the provided GEM in your editor\. @@ -30,3 +30,23 @@ bundle open \'rack\' . .P Will open the source directory for the \'rack\' gem in your bundle\. +. +.IP "" 4 +. +.nf + +bundle open \'rack\' \-\-path \'README\.md\' +. +.fi +. +.IP "" 0 +. +.P +Will open the README\.md file of the \'rack\' gem source in your bundle\. +. +.SH "OPTIONS" +. +.TP +\fB\-\-path\fR +Specify GEM source relative path to open\. + diff --git a/lib/bundler/man/bundle-open.1.ronn b/lib/bundler/man/bundle-open.1.ronn index 497beac93f..a857f3a965 100644 --- a/lib/bundler/man/bundle-open.1.ronn +++ b/lib/bundler/man/bundle-open.1.ronn @@ -3,7 +3,7 @@ bundle-open(1) -- Opens the source directory for a gem in your bundle ## SYNOPSIS -`bundle open` [GEM] +`bundle open` [GEM] [--path=PATH] ## DESCRIPTION @@ -17,3 +17,11 @@ Example: bundle open 'rack' Will open the source directory for the 'rack' gem in your bundle. + + bundle open 'rack' --path 'README.md' + +Will open the README.md file of the 'rack' gem source in your bundle. + +## OPTIONS +* `--path`: + Specify GEM source relative path to open. diff --git a/lib/bundler/man/bundle-outdated.1 b/lib/bundler/man/bundle-outdated.1 index 35283b31ec..40fe8a4def 100644 --- a/lib/bundler/man/bundle-outdated.1 +++ b/lib/bundler/man/bundle-outdated.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-OUTDATED" "1" "December 2022" "" "" +.TH "BUNDLE\-OUTDATED" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-outdated\fR \- List installed gems with newer versions available diff --git a/lib/bundler/man/bundle-platform.1 b/lib/bundler/man/bundle-platform.1 index dac8f3adf8..d0015a80ef 100644 --- a/lib/bundler/man/bundle-platform.1 +++ b/lib/bundler/man/bundle-platform.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PLATFORM" "1" "December 2022" "" "" +.TH "BUNDLE\-PLATFORM" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-platform\fR \- Displays platform compatibility information diff --git a/lib/bundler/man/bundle-plugin.1 b/lib/bundler/man/bundle-plugin.1 index bddf33fb1b..a231bb1e3d 100644 --- a/lib/bundler/man/bundle-plugin.1 +++ b/lib/bundler/man/bundle-plugin.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PLUGIN" "1" "December 2022" "" "" +.TH "BUNDLE\-PLUGIN" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-plugin\fR \- Manage Bundler plugins diff --git a/lib/bundler/man/bundle-pristine.1 b/lib/bundler/man/bundle-pristine.1 index 536d432320..8f4bad3db6 100644 --- a/lib/bundler/man/bundle-pristine.1 +++ b/lib/bundler/man/bundle-pristine.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-PRISTINE" "1" "December 2022" "" "" +.TH "BUNDLE\-PRISTINE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-pristine\fR \- Restores installed gems to their pristine condition diff --git a/lib/bundler/man/bundle-remove.1 b/lib/bundler/man/bundle-remove.1 index 99e684dd00..97a65016ac 100644 --- a/lib/bundler/man/bundle-remove.1 +++ b/lib/bundler/man/bundle-remove.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-REMOVE" "1" "December 2022" "" "" +.TH "BUNDLE\-REMOVE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-remove\fR \- Removes gems from the Gemfile diff --git a/lib/bundler/man/bundle-show.1 b/lib/bundler/man/bundle-show.1 index 504dbdb73a..82706d45f3 100644 --- a/lib/bundler/man/bundle-show.1 +++ b/lib/bundler/man/bundle-show.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-SHOW" "1" "December 2022" "" "" +.TH "BUNDLE\-SHOW" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem diff --git a/lib/bundler/man/bundle-update.1 b/lib/bundler/man/bundle-update.1 index e5a55c1073..65448f4806 100644 --- a/lib/bundler/man/bundle-update.1 +++ b/lib/bundler/man/bundle-update.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-UPDATE" "1" "December 2022" "" "" +.TH "BUNDLE\-UPDATE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-update\fR \- Update your gems to the latest available versions diff --git a/lib/bundler/man/bundle-version.1 b/lib/bundler/man/bundle-version.1 index 7a97172fd7..bb03e8b5d6 100644 --- a/lib/bundler/man/bundle-version.1 +++ b/lib/bundler/man/bundle-version.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-VERSION" "1" "December 2022" "" "" +.TH "BUNDLE\-VERSION" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-version\fR \- Prints Bundler version information diff --git a/lib/bundler/man/bundle-viz.1 b/lib/bundler/man/bundle-viz.1 index e73fd9224c..23fb95b738 100644 --- a/lib/bundler/man/bundle-viz.1 +++ b/lib/bundler/man/bundle-viz.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE\-VIZ" "1" "December 2022" "" "" +.TH "BUNDLE\-VIZ" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\-viz\fR \- Generates a visual dependency graph for your Gemfile diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1 index 681c6645f2..39f3807f30 100644 --- a/lib/bundler/man/bundle.1 +++ b/lib/bundler/man/bundle.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BUNDLE" "1" "December 2022" "" "" +.TH "BUNDLE" "1" "January 2023" "" "" . .SH "NAME" \fBbundle\fR \- Ruby Dependency Management diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5 index 894ac0f9e8..740a01e0cc 100644 --- a/lib/bundler/man/gemfile.5 +++ b/lib/bundler/man/gemfile.5 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GEMFILE" "5" "December 2022" "" "" +.TH "GEMFILE" "5" "January 2023" "" "" . .SH "NAME" \fBGemfile\fR \- A format for describing gem dependencies for Ruby programs diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 6037148294..8237ff53fe 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -9,26 +9,21 @@ module Bundler class Resolver require_relative "vendored_pub_grub" require_relative "resolver/base" - require_relative "resolver/package" require_relative "resolver/candidate" require_relative "resolver/incompatibility" require_relative "resolver/root" include GemHelpers - def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements) - @source_requirements = source_requirements - @base = Resolver::Base.new(base, additional_base_requirements) + def initialize(base, gem_version_promoter) + @source_requirements = base.source_requirements + @base = base @gem_version_promoter = gem_version_promoter end - def start(requirements, packages, exclude_specs: []) - exclude_specs.each do |spec| - remove_from_candidates(spec) - end - - @requirements = requirements - @packages = packages + def start + @requirements = @base.requirements + @packages = @base.packages root, logger = setup_solver @@ -78,33 +73,26 @@ module Bundler rescue PubGrub::SolveFailure => e incompatibility = e.incompatibility - names_to_unlock = [] - extended_explanation = nil + names_to_unlock, names_to_allow_prereleases_for, extended_explanation = find_names_to_relax(incompatibility) - while incompatibility.conflict? - cause = incompatibility.cause - incompatibility = cause.incompatibility - - incompatibility.terms.each do |term| - name = term.package.name - names_to_unlock << name if base_requirements[name] + names_to_relax = names_to_unlock + names_to_allow_prereleases_for - no_versions_incompat = [cause.incompatibility, cause.satisfier].find {|incompat| incompat.cause.is_a?(PubGrub::Incompatibility::NoVersions) } - next unless no_versions_incompat + if names_to_relax.any? + if names_to_unlock.any? + Bundler.ui.debug "Found conflicts with locked dependencies. Will retry with #{names_to_unlock.join(", ")} unlocked...", true - extended_explanation = no_versions_incompat.extended_explanation + @base.unlock_names(names_to_unlock) end - end - - names_to_unlock.uniq! - if names_to_unlock.any? - Bundler.ui.debug "Found conflicts with locked dependencies. Retrying with #{names_to_unlock.join(", ")} unlocked...", true + if names_to_allow_prereleases_for.any? + Bundler.ui.debug "Found conflicts with dependencies with prereleases. Will retrying considering prereleases for #{names_to_allow_prereleases_for.join(", ")}...", true - @base.unlock_names(names_to_unlock) + @base.include_prereleases(names_to_allow_prereleases_for) + end root, logger = setup_solver + Bundler.ui.debug "Retrying resolution...", true retry end @@ -118,6 +106,35 @@ module Bundler raise SolveFailure.new(explanation) end + def find_names_to_relax(incompatibility) + names_to_unlock = [] + names_to_allow_prereleases_for = [] + extended_explanation = nil + + while incompatibility.conflict? + cause = incompatibility.cause + incompatibility = cause.incompatibility + + incompatibility.terms.each do |term| + package = term.package + name = package.name + + if base_requirements[name] + names_to_unlock << name + elsif package.ignores_prereleases? + names_to_allow_prereleases_for << name + end + + no_versions_incompat = [cause.incompatibility, cause.satisfier].find {|incompat| incompat.cause.is_a?(PubGrub::Incompatibility::NoVersions) } + next unless no_versions_incompat + + extended_explanation = no_versions_incompat.extended_explanation + end + end + + [names_to_unlock.uniq, names_to_allow_prereleases_for.uniq, extended_explanation] + end + def parse_dependency(package, dependency) range = if repository_for(package).is_a?(Source::Gemspec) PubGrub::VersionRange.any @@ -215,7 +232,7 @@ module Bundler def all_versions_for(package) name = package.name - results = (@base[name] + @all_specs[name]).uniq(&:full_name) + results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] } locked_requirement = base_requirements[name] results = filter_matching_specs(results, locked_requirement) if locked_requirement @@ -284,6 +301,12 @@ module Bundler end end + def filter_prereleases(specs, package) + return specs unless package.ignores_prereleases? + + specs.reject {|s| s.version.prerelease? } + end + def requirement_satisfied_by?(requirement, spec) requirement.satisfied_by?(spec.version) || spec.source.is_a?(Source::Gemspec) end @@ -304,25 +327,20 @@ module Bundler @base.base_requirements end - def remove_from_candidates(spec) - @base.delete(spec) - end - def prepare_dependencies(requirements, packages) to_dependency_hash(requirements, packages).map do |dep_package, dep_constraint| name = dep_package.name - # If a dependency is scoped to a platform different from the current - # one, we ignore it. However, it may reappear during resolution as a - # transitive dependency of another package, so we need to reset the - # package so the proper versions are considered if reintroduced later. - if dep_package.platforms.empty? - @packages.delete(name) - next + next [dep_package, dep_constraint] if name == "bundler" + + versions = versions_for(dep_package, dep_constraint.range) + if versions.empty? && dep_package.ignores_prereleases? + @sorted_versions.delete(dep_package) + dep_package.consider_prereleases! + versions = versions_for(dep_package, dep_constraint.range) end + next [dep_package, dep_constraint] unless versions.empty? - next [dep_package, dep_constraint] if name == "bundler" - next [dep_package, dep_constraint] unless versions_for(dep_package, dep_constraint.range).empty? next unless dep_package.current_platform? raise_not_found!(dep_package) @@ -337,7 +355,8 @@ module Bundler def requirement_to_range(requirement) ranges = requirement.requirements.map do |(op, version)| - ver = Resolver::Candidate.new(version) + ver = Resolver::Candidate.new(version).generic! + platform_ver = Resolver::Candidate.new(version).platform_specific! case op when "~>" @@ -345,17 +364,17 @@ module Bundler bump = Resolver::Candidate.new(version.bump.to_s + ".A") PubGrub::VersionRange.new(:name => name, :min => ver, :max => bump, :include_min => true) when ">" - PubGrub::VersionRange.new(:min => ver) + PubGrub::VersionRange.new(:min => platform_ver) when ">=" PubGrub::VersionRange.new(:min => ver, :include_min => true) when "<" PubGrub::VersionRange.new(:max => ver) when "<=" - PubGrub::VersionRange.new(:max => ver, :include_max => true) + PubGrub::VersionRange.new(:max => platform_ver, :include_max => true) when "=" - PubGrub::VersionRange.new(:min => ver, :max => ver, :include_min => true, :include_max => true) + PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true) when "!=" - PubGrub::VersionRange.new(:min => ver, :max => ver, :include_min => true, :include_max => true).invert + PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true).invert else raise "bad version specifier: #{op}" end diff --git a/lib/bundler/resolver/base.rb b/lib/bundler/resolver/base.rb index 78b798f4ec..6921c047a7 100644 --- a/lib/bundler/resolver/base.rb +++ b/lib/bundler/resolver/base.rb @@ -1,19 +1,47 @@ # frozen_string_literal: true +require_relative "package" + module Bundler class Resolver class Base - def initialize(base, additional_base_requirements) + attr_reader :packages, :requirements, :source_requirements + + def initialize(source_requirements, dependencies, base, platforms, options) + @source_requirements = source_requirements + @base = base - @additional_base_requirements = additional_base_requirements + + @packages = Hash.new do |hash, name| + hash[name] = Package.new(name, platforms, **options) + end + + @requirements = dependencies.map do |dep| + dep_platforms = dep.gem_platforms(platforms) + + # Dependencies scoped to external platforms are ignored + next if dep_platforms.empty? + + name = dep.name + + @packages[name] = Package.new(name, dep_platforms, **options.merge(:dependency => dep)) + + dep + end.compact end def [](name) @base[name] end - def delete(spec) - @base.delete(spec) + def delete(specs) + specs.each do |spec| + @base.delete(spec) + end + end + + def get_package(name) + @packages[name] end def base_requirements @@ -24,10 +52,14 @@ module Bundler names.each do |name| @base.delete_by_name(name) - @additional_base_requirements.reject! {|dep| dep.name == name } + @base_requirements.delete(name) end + end - @base_requirements = nil + def include_prereleases(names) + names.each do |name| + get_package(name).consider_prereleases! + end end private @@ -38,7 +70,6 @@ module Bundler req = Gem::Requirement.new(ls.version) base_requirements[ls.name] = req end - @additional_base_requirements.each {|d| base_requirements[d.name] = d.requirement } base_requirements end end diff --git a/lib/bundler/resolver/candidate.rb b/lib/bundler/resolver/candidate.rb index cf5691ccc7..e695ef08ee 100644 --- a/lib/bundler/resolver/candidate.rb +++ b/lib/bundler/resolver/candidate.rb @@ -26,9 +26,8 @@ module Bundler def initialize(version, specs: []) @spec_group = Resolver::SpecGroup.new(specs) - @platforms = specs.map(&:platform).sort_by(&:to_s).uniq @version = Gem::Version.new(version) - @ruby_only = @platforms == [Gem::Platform::RUBY] + @ruby_only = specs.map(&:platform).uniq == [Gem::Platform::RUBY] end def dependencies @@ -41,6 +40,18 @@ module Bundler @spec_group.to_specs(package.force_ruby_platform?) end + def generic! + @ruby_only = true + + self + end + + def platform_specific! + @ruby_only = false + + self + end + def prerelease? @version.prerelease? end @@ -53,27 +64,20 @@ module Bundler [@version, @ruby_only ? -1 : 1] end - def canonical? - !@spec_group.empty? - end - def <=>(other) return unless other.is_a?(self.class) - return @version <=> other.version unless canonical? && other.canonical? sort_obj <=> other.sort_obj end def ==(other) return unless other.is_a?(self.class) - return @version == other.version unless canonical? && other.canonical? sort_obj == other.sort_obj end def eql?(other) return unless other.is_a?(self.class) - return @version.eql?(other.version) unless canonical? || other.canonical? sort_obj.eql?(other.sort_obj) end @@ -83,9 +87,7 @@ module Bundler end def to_s - return @version.to_s if @platforms.empty? || @ruby_only - - "#{@version} (#{@platforms.join(", ")})" + @version.to_s end end end diff --git a/lib/bundler/resolver/package.rb b/lib/bundler/resolver/package.rb index 7d64632860..7499a75006 100644 --- a/lib/bundler/resolver/package.rb +++ b/lib/bundler/resolver/package.rb @@ -15,12 +15,13 @@ module Bundler class Package attr_reader :name, :platforms, :dependency, :locked_version - def initialize(name, platforms, locked_specs, unlock, dependency: nil) + def initialize(name, platforms, locked_specs:, unlock:, prerelease: false, dependency: nil) @name = name @platforms = platforms @locked_version = locked_specs[name].first&.version @unlock = unlock @dependency = dependency || Dependency.new(name, @locked_version) + @prerelease = @dependency.prerelease? || @locked_version&.prerelease? || prerelease ? :consider_first : :ignore end def to_s @@ -47,8 +48,16 @@ module Bundler @unlock.empty? || @unlock.include?(name) end + def ignores_prereleases? + @prerelease == :ignore + end + def prerelease_specified? - @dependency.prerelease? + @prerelease == :consider_first + end + + def consider_prereleases! + @prerelease = :consider_last end def force_ruby_platform? diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 0a6afe0e5a..794a03e62d 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -284,7 +284,7 @@ module Bundler Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION - Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__) + Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__) unless RUBY_VERSION < "2.7" end def set_path diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 7eefd291a2..c39071705a 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -292,7 +292,7 @@ module Bundler end def dependency_api_available? - api_fetchers.any? + @allow_remote && api_fetchers.any? end protected diff --git a/lib/bundler/templates/newgem/Cargo.toml.tt b/lib/bundler/templates/newgem/Cargo.toml.tt index 7be7550cce..f5a460c9bb 100644 --- a/lib/bundler/templates/newgem/Cargo.toml.tt +++ b/lib/bundler/templates/newgem/Cargo.toml.tt @@ -1,5 +1,5 @@ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is -# a Rust project. Your extensions depedencies should be added to the Cargo.toml +# a Rust project. Your extensions dependencies should be added to the Cargo.toml # in the ext/ directory. [workspace] diff --git a/lib/bundler/vendor/pub_grub/LICENSE.txt b/lib/bundler/vendor/pub_grub/LICENSE.txt deleted file mode 100644 index 411840a4a0..0000000000 --- a/lib/bundler/vendor/pub_grub/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 John Hawthorn - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb index c222542435..9133332d01 100644 --- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb @@ -20,6 +20,10 @@ module Bundler::PubGrub range.eql?(other.range) end + def ==(other) + package == other.package && range == other.range + end + class << self def exact(package, version) range = VersionRange.new(min: version, max: version, include_min: true, include_max: true) diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb index e384178973..506b447b36 100644 --- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb @@ -397,7 +397,7 @@ module Bundler::PubGrub def constraints return ["any"] if any? - return ["= #{min}"] if min == max + return ["= #{min}"] if min.to_s == max.to_s c = [] c << "#{include_min ? ">=" : ">"} #{min}" if min diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb index c898a6522d..bbc10c3804 100644 --- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb @@ -148,7 +148,7 @@ module Bundler::PubGrub while !ranges.empty? ne = [] range = ranges.shift - while !ranges.empty? && ranges[0].min == range.max + while !ranges.empty? && ranges[0].min.to_s == range.max.to_s ne << range.max range = range.span(ranges.shift) end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 70e317089c..2aba18e298 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.4.1".freeze + VERSION = "2.4.5".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/rubygems.rb b/lib/rubygems.rb index f6c92d52ab..520fd4951b 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -8,7 +8,7 @@ require "rbconfig" module Gem - VERSION = "3.4.1".freeze + VERSION = "3.4.5".freeze end # Must be first since it unloads the prelude from 1.9.2 @@ -119,10 +119,6 @@ module Gem # to avoid deprecation warnings in Ruby 2.7. UNTAINT = RUBY_VERSION < "2.7" ? :untaint.to_sym : proc {} - # When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn - KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" || - (RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0") - ## # An Array of Regexps that match windows Ruby platforms. @@ -1349,7 +1345,16 @@ end Gem::Specification.load_defaults require_relative "rubygems/core_ext/kernel_gem" -require_relative "rubygems/core_ext/kernel_require" -require_relative "rubygems/core_ext/kernel_warn" + +path = File.join(__dir__, "rubygems/core_ext/kernel_require.rb") +# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn +if RUBY_ENGINE == "truffleruby" || + (RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0") + file = "<internal:#{path}>" +else + require_relative "rubygems/core_ext/kernel_warn" + file = path +end +eval File.read(path), nil, file require ENV["BUNDLER_SETUP"] if ENV["BUNDLER_SETUP"] && !defined?(Bundler) diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index badc21023a..f4688d793b 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -630,7 +630,11 @@ RubyGems is a package manager for Ruby. Usage: gem -h/--help gem -v/--version - gem command [arguments...] [options...] + gem [global options...] command [arguments...] [options...] + + Global options: + -C PATH run as if gem was started in <PATH> + instead of the current working directory Examples: gem install rake diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb index 8d31d85b44..1bdbd50530 100644 --- a/lib/rubygems/command_manager.rb +++ b/lib/rubygems/command_manager.rb @@ -175,14 +175,20 @@ class Gem::CommandManager when "-v", "--version" then say Gem::VERSION terminate_interaction 0 + when "-C" then + args.shift + start_point = args.shift + if Dir.exist?(start_point) + Dir.chdir(start_point) { invoke_command(args, build_args) } + else + alert_error clean_text("#{start_point} isn't a directory.") + terminate_interaction 1 + end when /^-/ then alert_error clean_text("Invalid option: #{args.first}. See 'gem --help'.") terminate_interaction 1 else - cmd_name = args.shift.downcase - cmd = find_command cmd_name - cmd.deprecation_warning if cmd.deprecated? - cmd.invoke_with_build_args args, build_args + invoke_command(args, build_args) end end @@ -237,4 +243,11 @@ class Gem::CommandManager ui.backtrace e end end + + def invoke_command(args, build_args) + cmd_name = args.shift.downcase + cmd = find_command cmd_name + cmd.deprecation_warning if cmd.deprecated? + cmd.invoke_with_build_args args, build_args + end end diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb index accbd7e97d..5d6152d3b9 100644 --- a/lib/rubygems/commands/build_command.rb +++ b/lib/rubygems/commands/build_command.rb @@ -26,6 +26,9 @@ class Gem::Commands::BuildCommand < Gem::Command add_option "-C PATH", "Run as if gem build was started in <PATH> instead of the current working directory." do |value, options| options[:build_path] = value end + deprecate_option "-C", + version: "4.0", + extra_msg: "-C is a global flag now. Use `gem -C PATH build GEMSPEC_FILE [options]` instead" end def arguments # :nodoc: diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 4a0f7aa3e4..959a6186dc 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -15,7 +15,7 @@ The owner command lets you add and remove owners of a gem on a push server (the default is https://rubygems.org). Multiple owners can be added or removed at the same time, if the flag is given multiple times. -The supported user identifiers are dependant on the push server. +The supported user identifiers are dependent on the push server. For rubygems.org, both e-mail and handle are supported, even though the user identifier field is called "email". diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb index 6f96cab84f..b2f97b9ed9 100644 --- a/lib/rubygems/core_ext/kernel_gem.rb +++ b/lib/rubygems/core_ext/kernel_gem.rb @@ -1,9 +1,4 @@ # frozen_string_literal: true -## -# RubyGems adds the #gem method to allow activation of specific gem versions -# and overrides the #require method on Kernel to make gems appear as if they -# live on the <code>$LOAD_PATH</code>. See the documentation of these methods -# for further detail. module Kernel diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 8064d813e1..b92d6f9965 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -13,12 +13,12 @@ module Kernel # Make sure we have a reference to Ruby's original Kernel#require unless defined?(gem_original_require) + # :stopdoc: alias gem_original_require require private :gem_original_require + # :startdoc: end - file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__ - module_eval <<'RUBY', file, __LINE__ + 1 # rubocop:disable Style/EvalWithLocation ## # When RubyGems is required, Kernel#require is replaced with our own which # is capable of loading gems on demand. @@ -33,7 +33,7 @@ module Kernel # The normal <tt>require</tt> functionality of returning false if # that file has already been loaded is preserved. - def require(path) + def require(path) # :doc: if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?) monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned? end @@ -147,17 +147,17 @@ module Kernel RUBYGEMS_ACTIVATION_MONITOR.exit return gem_original_require(path) rescue LoadError => load_error - RUBYGEMS_ACTIVATION_MONITOR.enter + if load_error.path == path + RUBYGEMS_ACTIVATION_MONITOR.enter - begin - if load_error.path == path and Gem.try_activate(path) - require_again = true + begin + require_again = Gem.try_activate(path) + ensure + RUBYGEMS_ACTIVATION_MONITOR.exit end - ensure - RUBYGEMS_ACTIVATION_MONITOR.exit - end - return gem_original_require(path) if require_again + return gem_original_require(path) if require_again + end raise load_error ensure @@ -168,7 +168,6 @@ module Kernel end end end -RUBY private :require diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb index f0f173c0b1..1f4c77f04b 100644 --- a/lib/rubygems/core_ext/kernel_warn.rb +++ b/lib/rubygems/core_ext/kernel_warn.rb @@ -1,53 +1,50 @@ # frozen_string_literal: true -if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES +module Kernel + rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. - module Kernel - rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. + original_warn = instance_method(:warn) - original_warn = instance_method(:warn) + remove_method :warn + class << self remove_method :warn + end - class << self - remove_method :warn + module_function define_method(:warn) {|*messages, **kw| + unless uplevel = kw[:uplevel] + if Gem.java_platform? && RUBY_VERSION < "3.1" + return original_warn.bind(self).call(*messages) + else + return original_warn.bind(self).call(*messages, **kw) + end end - module_function define_method(:warn) {|*messages, **kw| - unless uplevel = kw[:uplevel] - if Gem.java_platform? && RUBY_VERSION < "3.1" - return original_warn.bind(self).call(*messages) - else - return original_warn.bind(self).call(*messages, **kw) + # Ensure `uplevel` fits a `long` + uplevel, = [uplevel].pack("l!").unpack("l!") + + if uplevel >= 0 + start = 0 + while uplevel >= 0 + loc, = caller_locations(start, 1) + unless loc + # No more backtrace + start += uplevel + break end - end - # Ensure `uplevel` fits a `long` - uplevel, = [uplevel].pack("l!").unpack("l!") - - if uplevel >= 0 - start = 0 - while uplevel >= 0 - loc, = caller_locations(start, 1) - unless loc - # No more backtrace - start += uplevel - break - end + start += 1 - start += 1 - - if path = loc.path - unless path.start_with?(rubygems_path) || path.start_with?("<internal:") - # Non-rubygems frames - uplevel -= 1 - end + if path = loc.path + unless path.start_with?(rubygems_path) || path.start_with?("<internal:") + # Non-rubygems frames + uplevel -= 1 end end - kw[:uplevel] = start end + kw[:uplevel] = start + end - original_warn.bind(self).call(*messages, **kw) - } - end + original_warn.bind(self).call(*messages, **kw) + } end diff --git a/lib/rubygems/ext/cargo_builder.rb b/lib/rubygems/ext/cargo_builder.rb index 3851e8d523..60ab5544fe 100644 --- a/lib/rubygems/ext/cargo_builder.rb +++ b/lib/rubygems/ext/cargo_builder.rb @@ -203,7 +203,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder !!Gem::WIN_PATTERNS.find {|r| target_platform =~ r } end - # Interpolate substition vars in the arg (i.e. $(DEFFILE)) + # Interpolate substitution vars in the arg (i.e. $(DEFFILE)) def maybe_resolve_ldflag_variable(input_arg, dest_dir) var_matches = input_arg.match(/\$\((\w+)\)/) diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 1e7a5c503a..128871f2bf 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -158,7 +158,7 @@ class Gem::Platform # Of note, this method is not commutative. Indeed the OS 'linux' has a # special case: the version is the libc name, yet while "no version" stands # as a wildcard for a binary gem platform (as for other OSes), for the - # runtime platform "no version" stands for 'gnu'. To be able to disinguish + # runtime platform "no version" stands for 'gnu'. To be able to distinguish # these, the method receiver is the gem platform, while the argument is # the runtime platform. # |