Skip to content

Commit

Permalink
* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2…
Browse files Browse the repository at this point in the history
….6.1.

  Please see entries of 2.6.0 and 2.6.1 on
  https://github.com/rubygems/rubygems/blob/master/History.txt
  [fix GH-1270] Patch by @segiddins

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
hsbt committed Mar 4, 2016
1 parent f1321bd commit 5a90f9e
Show file tree
Hide file tree
Showing 35 changed files with 474 additions and 100 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Fri Mar 4 09:28:18 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>

* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems-2.6.1.
Please see entries of 2.6.0 and 2.6.1 on
https://github.com/rubygems/rubygems/blob/master/History.txt
[fix GH-1270] Patch by @segiddins

Thu Mar 3 14:09:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>

* lib/ostruct.rb (modifiable?, new_ostruct_member!, table!):
Expand Down
57 changes: 48 additions & 9 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'thread'

module Gem
VERSION = '2.5.2'
VERSION = '2.6.1'
end

# Must be first since it unloads the prelude from 1.9.2
Expand Down Expand Up @@ -174,6 +174,14 @@ module Gem
@pre_reset_hooks ||= []
@post_reset_hooks ||= []

def self.env_requirement(gem_name)
@env_requirements_by_name ||= {}
@env_requirements_by_name[gem_name] ||= begin
req = ENV["GEM_REQUIREMENT_#{gem_name.upcase}"] || '>= 0'.freeze
Gem::Requirement.create(req)
end
end

##
# Try to activate a gem containing +path+. Returns true if
# activation succeeded or wasn't needed because it was already
Expand All @@ -192,8 +200,13 @@ def self.try_activate path

begin
spec.activate
rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
Gem::Specification.find_by_name(spec.name).activate
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
spec_by_name = Gem::Specification.find_by_name(spec.name)
if spec_by_name.nil?
raise e
else
spec_by_name.activate
end
end

return true
Expand Down Expand Up @@ -326,16 +339,38 @@ def self.deflate(data)
# lookup files.

def self.paths
@paths ||= Gem::PathSupport.new
@paths ||= Gem::PathSupport.new(ENV)
end

# Initialize the filesystem paths to use from +env+.
# +env+ is a hash-like object (typically ENV) that
# is queried for 'GEM_HOME', 'GEM_PATH', and 'GEM_SPEC_CACHE'
# Keys for the +env+ hash should be Strings, and values of the hash should
# be Strings or +nil+.

def self.paths=(env)
clear_paths
@paths = Gem::PathSupport.new env
target = {}
env.each_pair do |k,v|
case k
when 'GEM_HOME', 'GEM_PATH', 'GEM_SPEC_CACHE'
case v
when nil, String
target[k] = v
when Array
unless Gem::Deprecate.skip
warn <<-eowarn
Array values in the parameter are deprecated. Please use a String or nil.
An Array was passed in from #{caller[3]}
eowarn
end
target[k] = v.join File::PATH_SEPARATOR
end
else
target[k] = v
end
end
@paths = Gem::PathSupport.new ENV.to_hash.merge(target)
Gem::Specification.dirs = @paths.path
end

Expand Down Expand Up @@ -430,7 +465,9 @@ def self.find_files(glob, check_load_path=true)

files = find_files_from_load_path glob if check_load_path

files.concat Gem::Specification.stubs.map { |spec|
gem_specifications = @gemdeps ? Gem.loaded_specs.values : Gem::Specification.stubs

files.concat gem_specifications.map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
}.flatten

Expand Down Expand Up @@ -939,9 +976,11 @@ def self.ui
# by the unit tests to provide environment isolation.

def self.use_paths(home, *paths)
paths = nil if paths == [nil]
paths = paths.first if Array === Array(paths).first
self.paths = { "GEM_HOME" => home, "GEM_PATH" => paths }
paths.flatten!
paths.compact!
hash = { "GEM_HOME" => home, "GEM_PATH" => paths.empty? ? home : paths.join(File::PATH_SEPARATOR) }
hash.delete_if { |_, v| v.nil? }
self.paths = hash
end

##
Expand Down
3 changes: 1 addition & 2 deletions lib/rubygems/basic_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def extension_dir
# Returns path to the extensions directory.

def extensions_dir
@extensions_dir ||= Gem.default_ext_dir_for(base_dir) ||
Gem.default_ext_dir_for(base_dir) ||
File.join(base_dir, 'extensions', Gem::Platform.local.to_s,
Gem.extension_api_version)
end
Expand Down Expand Up @@ -196,7 +196,6 @@ def gems_dir

def internal_init # :nodoc:
@extension_dir = nil
@extensions_dir = nil
@full_gem_path = nil
@gem_dir = nil
@ignored = nil
Expand Down
9 changes: 8 additions & 1 deletion lib/rubygems/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def invoke_with_build_args(args, build_args)

options[:build_args] = build_args

self.ui = Gem::SilentUI.new if options[:silent]

if options[:help] then
show_help
elsif @when_invoked then
Expand Down Expand Up @@ -520,10 +522,15 @@ def wrap(text, width) # :doc:
end
end

add_common_option('-q', '--quiet', 'Silence commands') do |value, options|
add_common_option('-q', '--quiet', 'Silence command progress meter') do |value, options|
Gem.configuration.verbose = false
end

add_common_option("--silent",
"Silence rubygems output") do |value, options|
options[:silent] = true
end

# Backtrace and config-file are added so they show up in the help
# commands. Both options are actually handled before the other
# options get parsed.
Expand Down
11 changes: 8 additions & 3 deletions lib/rubygems/commands/cleanup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def execute
end

def clean_gems
@original_home = Gem.dir
@original_path = Gem.path

get_primary_gems
get_candidate_gems
get_gems_to_cleanup
Expand All @@ -87,9 +90,6 @@ def clean_gems

deps = deplist.strongly_connected_components.flatten

@original_home = Gem.dir
@original_path = Gem.path

deps.reverse_each do |spec|
uninstall_dep spec
end
Expand All @@ -108,6 +108,7 @@ def get_candidate_gems
end

def get_gems_to_cleanup

gems_to_cleanup = @candidate_gems.select { |spec|
@primary_gems[spec.name].version != spec.version
}
Expand All @@ -116,6 +117,10 @@ def get_gems_to_cleanup
spec.default_gem?
}

gems_to_cleanup = gems_to_cleanup.select { |spec|
spec.base_dir == @original_home
}

@default_gems += default_gems
@default_gems.uniq!
@gems_to_cleanup = gems_to_cleanup.uniq
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def check_version # :nodoc:
end

def execute

if options.include? :gemdeps then
install_from_gemdeps
return # not reached
Expand Down
4 changes: 4 additions & 0 deletions lib/rubygems/commands/open_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def initialize
"Opens gem sources in EDITOR") do |editor, options|
options[:editor] = editor || get_env_editor
end
add_option('-v', '--version VERSION', String,
"Opens specific gem version") do |version|
options[:version] = version
end
end

def arguments # :nodoc:
Expand Down
10 changes: 7 additions & 3 deletions lib/rubygems/commands/push_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ def send_gem name
@host = gem_data.spec.metadata['default_gem_server']
end

# Always include this, even if it's nil
args << @host
push_host = nil

if gem_data.spec.metadata.has_key?('allowed_push_host')
args << gem_data.spec.metadata['allowed_push_host']
push_host = gem_data.spec.metadata['allowed_push_host']
end

@host ||= push_host

# Always include @host, even if it's nil
args += [ @host, push_host ]

say "Pushing gem to #{@host || Gem.host}..."

response = rubygems_api_request(*args) do |request|
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/commands/update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def check_update_arguments # :nodoc:
end

def execute

if options[:system] then
update_rubygems
return
Expand Down
13 changes: 11 additions & 2 deletions lib/rubygems/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,18 @@ def rubygems_api_key
# Sets the RubyGems.org API key to +api_key+

def rubygems_api_key= api_key
set_api_key :rubygems_api_key, api_key

@rubygems_api_key = api_key
end

##
# Set a specific host's API key to +api_key+

def set_api_key host, api_key
check_credentials_permissions

config = load_file(credentials_path).merge(:rubygems_api_key => api_key)
config = load_file(credentials_path).merge(host => api_key)

dirname = File.dirname credentials_path
Dir.mkdir(dirname) unless File.exist? dirname
Expand All @@ -320,7 +329,7 @@ def rubygems_api_key= api_key
f.write config.to_yaml
end

@rubygems_api_key = api_key
load_api_keys # reload
end

def load_file(filename)
Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ def merge other
end

def matching_specs platform_only = false
env_req = Gem.env_requirement(name)
matches = Gem::Specification.stubs_for(name).find_all { |spec|
requirement.satisfied_by? spec.version
requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
}.map(&:to_spec)

if platform_only
Expand Down
10 changes: 9 additions & 1 deletion lib/rubygems/gemcutter_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def sign_in sign_in_host = nil

with_response response do |resp|
say "Signed in."
Gem.configuration.rubygems_api_key = resp.body
set_api_key host, resp.body
end
end

Expand Down Expand Up @@ -156,5 +156,13 @@ def with_response response, error_prefix = nil
end
end

def set_api_key host, key
if host == Gem::DEFAULT_HOST
Gem.configuration.rubygems_api_key = key
else
Gem.configuration.set_api_key host, key
end
end

end

1 change: 1 addition & 0 deletions lib/rubygems/install_update_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def add_install_update_options
"Print post install message") do |value, options|
options[:post_install_message] = value
end

end

##
Expand Down
36 changes: 13 additions & 23 deletions lib/rubygems/path_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,36 @@ class Gem::PathSupport
# Constructor. Takes a single argument which is to be treated like a
# hashtable, or defaults to ENV, the system environment.
#
def initialize(env=ENV)
@env = env

# note 'env' vs 'ENV'...
@home = env["GEM_HOME"] || ENV["GEM_HOME"] || Gem.default_dir
def initialize(env)
@home = env["GEM_HOME"] || Gem.default_dir

if File::ALT_SEPARATOR then
@home = @home.gsub(File::ALT_SEPARATOR, File::SEPARATOR)
end

self.path = env["GEM_PATH"] || ENV["GEM_PATH"]
@path = split_gem_path env["GEM_PATH"], @home

@spec_cache_dir =
env["GEM_SPEC_CACHE"] || ENV["GEM_SPEC_CACHE"] ||
Gem.default_spec_cache_dir
@spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir

@spec_cache_dir = @spec_cache_dir.dup.untaint
end

private

##
# Set the Gem search path (as reported by Gem.path).
# Split the Gem search path (as reported by Gem.path).

def path=(gpaths)
def split_gem_path gpaths, home
# FIX: it should be [home, *path], not [*path, home]

gem_path = []

# FIX: I can't tell wtf this is doing.
gpaths ||= (ENV['GEM_PATH'] || "").empty? ? nil : ENV["GEM_PATH"]

if gpaths
if gpaths.kind_of?(Array)
gem_path = gpaths.dup
else
gem_path = gpaths.split(Gem.path_separator)
if gpaths.end_with?(Gem.path_separator)
gem_path += default_path
end
gem_path = gpaths.split(Gem.path_separator)
# Handle the path_separator being set to a regexp, which will cause
# end_with? to error
if gpaths =~ /#{Gem.path_separator}\z/
gem_path += default_path
end

if File::ALT_SEPARATOR then
Expand All @@ -70,12 +60,12 @@ def path=(gpaths)
end
end

gem_path << @home
gem_path << home
else
gem_path = default_path
end

@path = gem_path.uniq
gem_path.uniq
end

# Return the default Gem path
Expand Down

0 comments on commit 5a90f9e

Please sign in to comment.