From d0a54673202458455244f79ed212a97727f0c7c7 Mon Sep 17 00:00:00 2001 From: David Rodríguez Date: Fri, 26 Apr 2019 13:26:21 +0200 Subject: Update rubygems with latest upstream changes Closes: https://github.com/ruby/ruby/pull/2154 --- lib/rubygems.rb | 38 ++++------- lib/rubygems/command_manager.rb | 6 -- lib/rubygems/commands/dependency_command.rb | 2 +- lib/rubygems/commands/setup_command.rb | 14 +++-- lib/rubygems/commands/unpack_command.rb | 1 - lib/rubygems/config_file.rb | 7 ++- lib/rubygems/core_ext/kernel_require.rb | 2 +- lib/rubygems/dependency_installer.rb | 98 ----------------------------- lib/rubygems/installer.rb | 10 +-- lib/rubygems/package.rb | 1 - lib/rubygems/security/signer.rb | 3 +- lib/rubygems/specification.rb | 13 ++-- lib/rubygems/specification_policy.rb | 3 + lib/rubygems/test_case.rb | 20 ++---- lib/rubygems/uninstaller.rb | 2 +- lib/rubygems/version.rb | 4 +- 16 files changed, 51 insertions(+), 173 deletions(-) (limited to 'lib') diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 54bd995b83..21af9ac8f8 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -174,8 +174,6 @@ module Gem write_binary_errors end.freeze - USE_BUNDLER_FOR_GEMDEPS = !ENV['DONT_USE_BUNDLER_FOR_GEMDEPS'] # :nodoc: - @@win_platform = nil @configuration = nil @@ -253,8 +251,6 @@ module Gem # TODO: fails test_self_bin_path_bin_file_gone_in_latest # Gem::Specification.find_by_name(name, *requirements).bin_file exec_name - raise ArgumentError, "you must supply exec_name" unless exec_name - requirements = Gem::Requirement.default if requirements.empty? @@ -262,6 +258,8 @@ module Gem end def self.find_spec_for_exe(name, exec_name, requirements) + raise ArgumentError, "you must supply exec_name" unless exec_name + dep = Gem::Dependency.new name, requirements loaded = Gem.loaded_specs[name] @@ -297,8 +295,8 @@ module Gem # # This method should *only* be used in bin stub files. - def self.activate_bin_path(name, exec_name, requirement) # :nodoc: - spec = find_spec_for_exe name, exec_name, [requirement] + def self.activate_bin_path(name, exec_name = nil, *requirements) # :nodoc: + spec = find_spec_for_exe name, exec_name, requirements Gem::LOADED_SPECS_MUTEX.synchronize do spec.activate finish_resolve @@ -1183,27 +1181,15 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} raise ArgumentError, "Unable to find gem dependencies file at #{path}" end - if USE_BUNDLER_FOR_GEMDEPS - - ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) - require 'rubygems/user_interaction' - Gem::DefaultUserInteraction.use_ui(ui) do - require "bundler" - @gemdeps = Bundler.setup - Bundler.ui = nil - @gemdeps.requested_specs.map(&:to_spec).sort_by(&:name) - end - - else - - rs = Gem::RequestSet.new - @gemdeps = rs.load_gemdeps path - - rs.resolve_current.map do |s| - s.full_spec.tap(&:activate) - end - + ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path) + require 'rubygems/user_interaction' + Gem::DefaultUserInteraction.use_ui(ui) do + require "bundler" + @gemdeps = Bundler.setup + Bundler.ui = nil + @gemdeps.requested_specs.map(&:to_spec).sort_by(&:name) end + rescue => e case e when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError) diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb index 8ab0d98ed4..8ad723be55 100644 --- a/lib/rubygems/command_manager.rb +++ b/lib/rubygems/command_manager.rb @@ -169,12 +169,6 @@ class Gem::CommandManager when '-v', '--version' then say Gem::VERSION terminate_interaction 0 - when '--no-ri', '--no-rdoc' then - # This was added to compensate for a deprecation warning not being shown - # in Rubygems 2.x.x. - # TODO: Remove when Rubygems 3.1 is released. - alert_error "Invalid option: #{args.first}. Use --no-document instead." - terminate_interaction 1 when /^-/ then alert_error clean_text("Invalid option: #{args.first}. See 'gem --help'.") terminate_interaction 1 diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb index 8e198ac93a..00ab19bed4 100644 --- a/lib/rubygems/commands/dependency_command.rb +++ b/lib/rubygems/commands/dependency_command.rb @@ -208,7 +208,7 @@ use with other commands. def name_pattern(args) args << '' if args.empty? - if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m + if args.length == 1 and args.first =~ /\A(.*)(i)?\z/m flags = $2 ? Regexp::IGNORECASE : nil Regexp.new $1, flags else diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index e3afc8cff8..f5e5236a06 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -319,7 +319,7 @@ By default, this RubyGems will install gem as: def install_lib(lib_dir) libs = { 'RubyGems' => 'lib' } - libs['Bundler'] = 'bundler/lib' if Gem::USE_BUNDLER_FOR_GEMDEPS + libs['Bundler'] = 'bundler/lib' libs.each do |tool, path| say "Installing #{tool}" if @verbose @@ -382,8 +382,6 @@ By default, this RubyGems will install gem as: end def install_default_bundler_gem(bin_dir) - return unless Gem::USE_BUNDLER_FOR_GEMDEPS - specs_dir = Gem::Specification.default_specifications_dir specs_dir = File.join(options[:destdir], specs_dir) unless Gem.win_platform? mkdir_p specs_dir, :mode => 0755 @@ -430,8 +428,12 @@ By default, this RubyGems will install gem as: Dir.chdir("bundler") do built_gem = Gem::Package.build(bundler_spec) - installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true) - installer.install + begin + installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], install_as_default: true, bin_dir: bin_dir, wrappers: true) + installer.install + ensure + FileUtils.rm_f built_gem + end end say "Bundler #{bundler_spec.version} installed" @@ -544,7 +546,7 @@ abort "#{deprecation_message}" def remove_old_lib_files(lib_dir) lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' } - lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' if Gem::USE_BUNDLER_FOR_GEMDEPS + lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler' lib_dirs.each do |old_lib_dir, new_lib_dir| lib_files = rb_files_in(new_lib_dir) lib_files.concat(template_files_in(new_lib_dir)) if new_lib_dir =~ /bundler/ diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index 4a1bd8a0d6..f7ffea3e95 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require 'rubygems/command' -require 'rubygems/installer' require 'rubygems/version_option' require 'rubygems/security_option' require 'rubygems/remote_fetcher' diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index a5c552dc9f..52591f49bb 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -197,9 +197,10 @@ class Gem::ConfigFile platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) system_config = load_file SYSTEM_WIDE_CONFIG_FILE user_config = load_file config_file_name.dup.untaint - environment_config = (ENV['GEMRC'] || '').split(/[:;]/).inject({}) do |result, file| - result.merge load_file file - end + environment_config = (ENV['GEMRC'] || '') + .split(File::PATH_SEPARATOR).inject({}) do |result, file| + result.merge load_file file + end @hash = operating_system_config.merge platform_config unless arg_list.index '--norc' diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 3b78011619..014090a16e 100755 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -39,7 +39,7 @@ module Kernel if spec = Gem.find_unresolved_default_spec(path) Gem.remove_unresolved_default_spec(spec) begin - Kernel.send(:gem, spec.name) + Kernel.send(:gem, spec.name, "#{Gem::Requirement.default}.a") rescue Exception RUBYGEMS_ACTIVATION_MONITOR.exit raise diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index b1f1946d79..9610670b3f 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -106,62 +106,6 @@ class Gem::DependencyInstaller @errors = [] end - ## - #-- - # TODO remove at RubyGems 4, no longer used - - def add_found_dependencies(to_do, dependency_list) # :nodoc: - seen = {} - dependencies = Hash.new { |h, name| h[name] = Gem::Dependency.new name } - - until to_do.empty? do - spec = to_do.shift - - # HACK why is spec nil? - next if spec.nil? or seen[spec.name] - seen[spec.name] = true - - deps = spec.runtime_dependencies - - if @development - if @dev_shallow - if @toplevel_specs.include? spec.full_name - deps |= spec.development_dependencies - end - else - deps |= spec.development_dependencies - end - end - - deps.each do |dep| - dependencies[dep.name] = dependencies[dep.name].merge dep - - if @minimal_deps - next if Gem::Specification.any? do |installed_spec| - dep.name == installed_spec.name and - dep.requirement.satisfied_by? installed_spec.version - end - end - - results = Gem::Deprecate.skip_during do - find_gems_with_sources(dep) - end - - results.sorted.each do |t| - to_do.push t.spec - end - - results.remove_installed! dep - - @available << results - results.inject_into_list dependency_list - end - end - - dependency_list.remove_specs_unsatisfied_by dependencies - end - deprecate :add_found_dependencies, :none, 2018, 12 - ## # Creates an AvailableSet to install from based on +dep_or_name+ and # +version+ @@ -325,48 +269,6 @@ class Gem::DependencyInstaller end deprecate :find_spec_by_name_and_version, :none, 2019, 12 - ## - # Gathers all dependencies necessary for the installation from local and - # remote sources unless the ignore_dependencies was given. - #-- - # TODO remove at RubyGems 4 - - def gather_dependencies # :nodoc: - specs = @available.all_specs - - # these gems were listed by the user, always install them - keep_names = specs.map { |spec| spec.full_name } - - if @dev_shallow - @toplevel_specs = keep_names - end - - dependency_list = Gem::DependencyList.new @development - dependency_list.add(*specs) - to_do = specs.dup - - Gem::Deprecate.skip_during do - add_found_dependencies to_do, dependency_list unless @ignore_dependencies - end - - # REFACTOR maybe abstract away using Gem::Specification.include? so - # that this isn't dependent only on the currently installed gems - dependency_list.specs.reject! do |spec| - not keep_names.include?(spec.full_name) and - Gem::Specification.include?(spec) - end - - unless dependency_list.ok? or @ignore_dependencies or @force - reason = dependency_list.why_not_ok?.map do |k,v| - "#{k} requires #{v.join(", ")}" - end.join("; ") - raise Gem::DependencyError, "Unable to resolve dependencies: #{reason}" - end - - @gems_to_install = dependency_list.dependency_order.reverse - end - deprecate :gather_dependencies, :none, 2018, 12 - def in_background(what) # :nodoc: fork_happened = false if @build_docs_in_background and Process.respond_to?(:fork) diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 8b80125922..76c3bcf1d7 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -193,7 +193,7 @@ class Gem::Installer @bin_dir = options[:bin_dir] if options[:bin_dir] - if options[:user_install] and not options[:unpack] + if options[:user_install] @gem_home = Gem.user_dir @bin_dir = Gem.bindir gem_home unless options[:bin_dir] check_that_user_bin_dir_is_in_path @@ -428,6 +428,7 @@ class Gem::Installer @gem_dir = directory extract_files end + deprecate :unpack, :none, 2020, 04 ## # The location of the spec file that is installed. @@ -726,10 +727,9 @@ class Gem::Installer end end - def verify_gem_home(unpack = false) # :nodoc: + def verify_gem_home # :nodoc: FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755 - raise Gem::FilePermissionError, gem_home unless - unpack or File.writable?(gem_home) + raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home) end def verify_spec @@ -898,7 +898,7 @@ TEXT # The dependent check will be skipped if the install is ignoring dependencies. def pre_install_checks - verify_gem_home options[:unpack] + verify_gem_home # The name and require_paths must be verified first, since it could contain # ruby code that would be eval'ed in #ensure_loadable_spec diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 4ad4f8c3a9..de811bf4e4 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -265,7 +265,6 @@ class Gem::Package raise ArgumentError, "skip_validation = true and strict_validation = true are incompatible" if skip_validation && strict_validation Gem.load_yaml - require 'rubygems/security' @spec.mark_version @spec.validate true, strict_validation unless skip_validation diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb index 4e835e5b80..5e4ba6ebba 100644 --- a/lib/rubygems/security/signer.rb +++ b/lib/rubygems/security/signer.rb @@ -85,7 +85,6 @@ class Gem::Security::Signer @digest_name = Gem::Security::DIGEST_NAME if @key && !@key.is_a?(OpenSSL::PKey::RSA) - @passphrase ||= ask_for_password("Enter PEM pass phrase:") @key = OpenSSL::PKey::RSA.new(File.read(@key), @passphrase) end @@ -144,6 +143,8 @@ class Gem::Security::Signer raise Gem::Security::Exception, 'no certs provided' if @cert_chain.empty? if @cert_chain.length == 1 and @cert_chain.last.not_after < Time.now + alert("Your certificate has expired, trying to re-sign it...") + re_sign_key( expiration_length: (Gem::Security::ONE_DAY * options[:expiration_length_days]) ) diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index ca590ea579..942e49bf84 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -654,8 +654,8 @@ class Gem::Specification < Gem::BasicSpecification # # This gem will work with 1.8.6 or greater... # spec.required_ruby_version = '>= 1.8.6' # - # # Only with ruby 2.0.x - # spec.required_ruby_version = '~> 2.0' + # # Only with final releases of major version 2 where minor version is at least 3 + # spec.required_ruby_version = '~> 2.3' # # # Only prereleases or final releases after 2.6.0.preview2 # spec.required_ruby_version = '> 2.6.0.preview2' @@ -812,7 +812,7 @@ class Gem::Specification < Gem::BasicSpecification def self.stubs @@stubs ||= begin pattern = "*.gemspec" - stubs = Gem.loaded_specs.values + default_stubs(pattern) + installed_stubs(dirs, pattern) + stubs = Gem.loaded_specs.values + installed_stubs(dirs, pattern) + default_stubs(pattern) stubs = uniq_by(stubs) { |stub| stub.full_name } _resort!(stubs) @@ -843,8 +843,9 @@ class Gem::Specification < Gem::BasicSpecification @@stubs_by_name[name] || [] else pattern = "#{name}-*.gemspec" - stubs = Gem.loaded_specs.values + default_stubs(pattern) + - installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } + stubs = Gem.loaded_specs.values + + installed_stubs(dirs, pattern).select { |s| Gem::Platform.match s.platform } + + default_stubs(pattern) stubs = uniq_by(stubs) { |stub| stub.full_name }.group_by(&:name) stubs.each_value { |v| _resort!(v) } @@ -2594,8 +2595,6 @@ class Gem::Specification < Gem::BasicSpecification # checks.. def validate(packaging = true, strict = false) - require 'rubygems/user_interaction' - extend Gem::UserInteraction normalize validation_policy = Gem::SpecificationPolicy.new(self) diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb index a4c6888cd1..24c1145907 100644 --- a/lib/rubygems/specification_policy.rb +++ b/lib/rubygems/specification_policy.rb @@ -1,8 +1,11 @@ require 'delegate' require 'uri' +require 'rubygems/user_interaction' class Gem::SpecificationPolicy < SimpleDelegator + include Gem::UserInteraction + VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/.freeze # :nodoc: SPECIAL_CHARACTERS = /\A[#{Regexp.escape('.-_')}]+/.freeze # :nodoc: diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 6061be1a84..8e909e4afe 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true # TODO: $SAFE = 1 -if defined? Gem::QuickLoader - Gem::QuickLoader.load_full_rubygems_library -else - require 'rubygems' -end +require 'rubygems' # If bundler gemspec exists, add to stubs bundler_gemspec = File.expand_path("../../../bundler/bundler.gemspec", __FILE__) @@ -38,9 +34,8 @@ unless Gem::Dependency.new('rdoc', '>= 3.10').matching_specs.empty? gem 'json' end -if Gem::USE_BUNDLER_FOR_GEMDEPS - require 'bundler' -end +require 'bundler' + require 'minitest/autorun' require 'rubygems/deprecate' @@ -261,9 +256,8 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni @current_dir = Dir.pwd @fetcher = nil - if Gem::USE_BUNDLER_FOR_GEMDEPS - Bundler.ui = Bundler::UI::Silent.new - end + Bundler.ui = Bundler::UI::Silent.new + @back_ui = Gem::DefaultUserInteraction.ui @ui = Gem::MockGemUi.new # This needs to be a new instance since we call use_ui(@ui) when we want to @@ -368,9 +362,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem.loaded_specs.clear Gem.clear_default_specs Gem::Specification.unresolved_deps.clear - if Gem::USE_BUNDLER_FOR_GEMDEPS - Bundler.reset! - end + Bundler.reset! Gem.configuration.verbose = true Gem.configuration.update_sources = true diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index fe423a7ebd..291bb6d611 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -46,7 +46,7 @@ class Gem::Uninstaller # TODO document the valid options @gem = gem @version = options[:version] || Gem::Requirement.default - @gem_home = File.expand_path(options[:install_dir] || Gem.dir) + @gem_home = File.realpath(options[:install_dir] || Gem.dir) @force_executables = options[:executables] @force_all = options[:all] @force_ignore = options[:ignore] diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index c23b157708..86a23509d6 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -344,8 +344,8 @@ class Gem::Version return unless Gem::Version === other return 0 if @version == other._version || canonical_segments == other.canonical_segments - lhsegments = _segments - rhsegments = other._segments + lhsegments = canonical_segments + rhsegments = other.canonical_segments lhsize = lhsegments.size rhsize = rhsegments.size -- cgit v1.2.3