ruby-changes:60495
From: David <ko1@a...>
Date: Tue, 24 Mar 2020 15:39:40 +0900 (JST)
Subject: [ruby-changes:60495] 96064e6f1c (master): Sync rubygems with current master (#2889)
https://git.ruby-lang.org/ruby.git/commit/?id=96064e6f1c From 96064e6f1ce100a37680dc8f9509f06b3350e9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Tue, 24 Mar 2020 07:39:24 +0100 Subject: Sync rubygems with current master (#2889) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index f7380c7..9bd4e9b 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -190,6 +190,8 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L190 @pre_reset_hooks ||= [] @post_reset_hooks ||= [] + @default_source_date_epoch = nil + ## # Try to activate a gem containing +path+. Returns true if # activation succeeded or wasn't needed because it was already @@ -317,6 +319,13 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L319 end ## + # The path were rubygems plugins are to be installed. + + def self.plugindir(install_dir=Gem.dir) + File.join install_dir, 'plugins' + end + + ## # Reset the +dir+ and +path+ values. The next time +dir+ or +path+ # is requested, the values will be calculated from scratch. This is # mainly used by the unit tests to provide test isolation. @@ -423,10 +432,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L432 paths.spec_cache_dir end - def self.plugins_dir - File.join(dir, "plugins") - end - ## # Quietly ensure the Gem directory +dir+ contains all the proper # subdirectories. If we can't create a directory due to a permission @@ -466,7 +471,10 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L471 subdirs.each do |name| subdir = File.join dir, name next if File.exist? subdir - FileUtils.mkdir_p subdir, **options rescue nil + begin + FileUtils.mkdir_p subdir, **options + rescue Errno::EACCES + end end ensure File.umask old_umask @@ -863,8 +871,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L871 def self.ruby if @ruby.nil? - @ruby = File.join(RbConfig::CONFIG['bindir'], - "#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}") + @ruby = RbConfig.ruby @ruby = "\"#{@ruby}\"" if @ruby =~ /\s/ end @@ -1099,7 +1106,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1106 # Find rubygems plugin files in the standard location and load them def self.load_plugins - load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugins_dir) + load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir) end ## @@ -1182,20 +1189,43 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1189 end ## - # The SOURCE_DATE_EPOCH environment variable (or, if that's not set, the current time), converted to Time object. - # This is used throughout RubyGems for enabling reproducible builds. + # If the SOURCE_DATE_EPOCH environment variable is set, returns it's value. + # Otherwise, returns the time that `Gem.source_date_epoch_string` was + # first called in the same format as SOURCE_DATE_EPOCH. + # + # NOTE(@duckinator): The implementation is a tad weird because we want to: + # 1. Make builds reproducible by default, by having this function always + # return the same result during a given run. + # 2. Allow changing ENV['SOURCE_DATE_EPOCH'] at runtime, since multiple + # tests that set this variable will be run in a single process. # - # If it is not set as an environment variable already, this also sets it. + # If you simplify this function and a lot of tests fail, that is likely + # due to #2 above. # # Details on SOURCE_DATE_EPOCH: # https://reproducible-builds.org/specs/source-date-epoch/ - def self.source_date_epoch - if ENV["SOURCE_DATE_EPOCH"].nil? || ENV["SOURCE_DATE_EPOCH"].empty? - ENV["SOURCE_DATE_EPOCH"] = Time.now.to_i.to_s - end + def self.source_date_epoch_string + # The value used if $SOURCE_DATE_EPOCH is not set. + @default_source_date_epoch ||= Time.now.to_i.to_s + + specified_epoch = ENV["SOURCE_DATE_EPOCH"] + + # If it's empty or just whitespace, treat it like it wasn't set at all. + specified_epoch = nil if !specified_epoch.nil? && specified_epoch.strip.empty? + + epoch = specified_epoch || @default_source_date_epoch + + epoch.strip + end - Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc.freeze + ## + # Returns the value of Gem.source_date_epoch_string, as a Time object. + # + # This is used throughout RubyGems for enabling reproducible builds. + + def self.source_date_epoch + Time.at(self.source_date_epoch_string.to_i).utc.freeze end # FIX: Almost everywhere else we use the `def self.` way of defining class diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index 38da773..ea6698f 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -82,12 +82,19 @@ To install the missing version, run `gem install bundler:#{vr.first}` https://github.com/ruby/ruby/blob/trunk/lib/rubygems/bundler_version_finder.rb#L82 def self.lockfile_contents gemfile = ENV["BUNDLE_GEMFILE"] gemfile = nil if gemfile && gemfile.empty? - Gem::Util.traverse_parents Dir.pwd do |directory| - next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.tap(&Gem::UNTAINT)) } - gemfile = File.join directory, gemfile - break - end unless gemfile + unless gemfile + begin + Gem::Util.traverse_parents(Dir.pwd) do |directory| + next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.tap(&Gem::UNTAINT)) } + + gemfile = File.join directory, gemfile + break + end + rescue Errno::ENOENT + return + end + end return unless gemfile diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 11b6645..9b7b41d 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -77,7 +77,7 @@ class Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/command.rb#L77 when Array @extra_args = value when String - @extra_args = value.split(' ') + @extra_args = value.split end end @@ -174,8 +174,7 @@ class Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/command.rb#L174 alert_error msg unless suppress_suggestions - suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name gem_name - + suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name(gem_name, :latest, 10) unless suggestions.empty? alert_error "Possible alternatives: #{suggestions.join(", ")}" end @@ -625,8 +624,7 @@ class Gem::Command https://github.com/ruby/ruby/blob/trunk/lib/rubygems/command.rb#L624 # :stopdoc: HELP = <<-HELP.freeze -RubyGems is a sophisticated package manager for Ruby. This is a -basic help message containing pointers to more information. +RubyGems is a package manager for Ruby. Usage: gem -h/--help diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 26d6828..989ca58 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -167,7 +167,7 @@ prefix or only the files that are requireable. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/contents_command.rb#L167 end def spec_for(name) - spec = Gem::Specification.find_all_by_name(name, @version).last + spec = Gem::Specification.find_all_by_name(name, @version).first return spec if spec diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index 7031ac0..494b3ee 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -184,14 +184,14 @@ command to remove old versions. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L184 else require "tmpdir" tmpdir = Dir.mktmpdir - FileUtils.mv Gem.plugins_dir, tmpdir + FileUtils.mv Gem.plugindir, tmpdir status = yield if status FileUtils.rm_rf tmpdir else - FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugins_dir + FileUtils.mv File.join(tmpdir, "plugins"), Gem.plugindir end status diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 60f4d18..a8d170f 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -43,18 +43,21 @@ module Kernel https://github.com/ruby/ruby/blob/trunk/lib/rubygems/core_ext/kernel_require.rb#L43 # https://github.com/rubygems/rubygems/pull/1868 resolved_path = begin rp = nil - $LOAD_PATH[0...Gem.load_path_insert_index || -1].each do |lp| - safe_lp = lp.dup.tap(&Gem::UNTAINT) - begin - if File.symlink? safe_lp # for backward compatibility - next + Gem.suffixes.each do |s| + load_path_insert_index = Gem.load_path_insert_index + break unless load_path_insert_index + + $LOAD_PATH[0...load_path_insert_index].each do |lp| + safe_lp = lp.dup.tap(&Gem::UNTAINT) + begin + if File.symlink? safe_lp # for backward compatibility + next + end + rescue SecurityError + RUBYGEMS_ACTIVATION_MONITOR.exit + raise end - rescue SecurityError - RUBYGEMS_ACTIVATION_MONITOR.exit - raise - end - Gem.suffixes.each do |s| full_path = File.expand_path(File.joi (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/