Skip to content

Commit

Permalink
RubyGems 2.6.1 + @segiddins patch in rubygems/rubygems#1542.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 10, 2016
1 parent 6339521 commit bdb4a36
Show file tree
Hide file tree
Showing 170 changed files with 3,113 additions and 1,288 deletions.
132 changes: 106 additions & 26 deletions lib/ruby/stdlib/rubygems.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# -*- ruby -*-
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
Expand All @@ -9,7 +10,7 @@
require 'thread'

module Gem
VERSION = '2.4.8'
VERSION = '2.6.1'
end

# Must be first since it unloads the prelude from 1.9.2
Expand All @@ -26,12 +27,12 @@ module Gem
# For user documentation, see:
#
# * <tt>gem help</tt> and <tt>gem help [command]</tt>
# * {RubyGems User Guide}[http://docs.rubygems.org/read/book/1]
# * {Frequently Asked Questions}[http://docs.rubygems.org/read/book/3]
# * {RubyGems User Guide}[http://guides.rubygems.org/]
# * {Frequently Asked Questions}[http://guides.rubygems.org/faqs]
#
# For gem developer documentation see:
#
# * {Creating Gems}[http://docs.rubygems.org/read/chapter/5]
# * {Creating Gems}[http://guides.rubygems.org/make-your-own-gem]
# * Gem::Specification
# * Gem::Version for version dependency notes
#
Expand Down Expand Up @@ -156,6 +157,7 @@ module Gem
@@win_platform = nil

@configuration = nil
@gemdeps = nil
@loaded_specs = {}
LOADED_SPECS_MUTEX = Mutex.new
@path_to_default_spec_map = {}
Expand Down Expand Up @@ -184,18 +186,19 @@ def self.try_activate path
# or if it was ambiguous (and thus unresolved) the code in our custom
# require will try to activate the more specific version.

spec = Gem::Specification.find_inactive_by_path path

unless spec
spec = Gem::Specification.find_by_path path
return true if spec && spec.activated?
return false
end
spec = Gem::Specification.find_by_path path
return false unless spec
return true if spec.activated?

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 @@ -232,16 +235,20 @@ def self.bin_path(name, exec_name = nil, *requirements)
requirements = Gem::Requirement.default if
requirements.empty?

find_spec_for_exe(name, exec_name, requirements).bin_file exec_name
end

def self.find_spec_for_exe name, exec_name, requirements
dep = Gem::Dependency.new name, requirements

loaded = Gem.loaded_specs[name]

return loaded.bin_file exec_name if loaded && dep.matches_spec?(loaded)
return loaded if loaded && dep.matches_spec?(loaded)

specs = dep.matching_specs(true)

raise Gem::GemNotFoundException,
"can't find gem #{name} (#{requirements})" if specs.empty?
"can't find gem #{dep}" if specs.empty?

specs = specs.find_all { |spec|
spec.executables.include? exec_name
Expand All @@ -252,6 +259,24 @@ def self.bin_path(name, exec_name = nil, *requirements)
raise Gem::GemNotFoundException, msg
end

spec
end
private_class_method :find_spec_for_exe

##
# Find the full path to the executable for gem +name+. If the +exec_name+
# is not given, the gem's default_executable is chosen, otherwise the
# specified executable's path is returned. +requirements+ allows
# you to specify specific gem versions.
#
# A side effect of this method is that it will activate the gem that
# contains the executable.
#
# 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]
Gem::LOADED_SPECS_MUTEX.synchronize { spec.activate }
spec.bin_file exec_name
end

Expand Down Expand Up @@ -310,11 +335,10 @@ def self.configuration=(config)
# package is not available as a gem, return nil.

def self.datadir(gem_name)
# TODO: deprecate and move to Gem::Specification
# and drop the extra ", gem_name" which is uselessly redundant
# TODO: deprecate
spec = @loaded_specs[gem_name]
return nil if spec.nil?
File.join spec.full_gem_path, "data", gem_name
spec.datadir
end

##
Expand All @@ -329,16 +353,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 @@ -433,7 +479,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.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 @@ -580,6 +628,10 @@ def self.host= host
# gem's paths are inserted before site lib directory by default.

def self.load_path_insert_index
$LOAD_PATH.each_with_index do |path, i|
return i if path.instance_variable_defined?(:@gem_prelude_index)
end

index = $LOAD_PATH.index RbConfig::CONFIG['sitelibdir']

index
Expand All @@ -596,6 +648,9 @@ def self.load_yaml

test_syck = ENV['TEST_SYCK']

# Only Ruby 1.8 and 1.9 have syck
test_syck = false unless /^1\./ =~ RUBY_VERSION

unless test_syck
begin
gem 'psych', '>= 1.2.1'
Expand Down Expand Up @@ -777,6 +832,14 @@ def self.read_binary(path)
open path, 'rb' do |f|
f.read
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
open path, 'rb' do |f|
f.read
end
end
end

##
Expand All @@ -800,6 +863,15 @@ def self.ruby_api_version
@ruby_api_version ||= RbConfig::CONFIG['ruby_version'].dup
end

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
post_reset { @env_requirements_by_name = {} }

##
# Returns the latest release-version specification for the gem +name+.

Expand Down Expand Up @@ -927,9 +999,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 Expand Up @@ -1052,7 +1126,7 @@ def self.use_gemdeps path = nil
end

rs = Gem::RequestSet.new
rs.load_gemdeps path
@gemdeps = rs.load_gemdeps path

rs.resolve_current.map do |s|
sp = s.full_spec
Expand Down Expand Up @@ -1082,6 +1156,12 @@ class << self

attr_reader :loaded_specs

##
# GemDependencyAPI object, which is set when .use_gemdeps is called.
# This contains all the information from the Gemfile.

attr_reader :gemdeps

##
# Register a Gem::Specification for default gem.
#
Expand Down Expand Up @@ -1196,6 +1276,7 @@ def clear_default_specs
autoload :DependencyList, 'rubygems/dependency_list'
autoload :DependencyResolver, 'rubygems/resolver'
autoload :Installer, 'rubygems/installer'
autoload :Licenses, 'rubygems/util/licenses'
autoload :PathSupport, 'rubygems/path_support'
autoload :Platform, 'rubygems/platform'
autoload :RequestSet, 'rubygems/request_set'
Expand Down Expand Up @@ -1242,4 +1323,3 @@ def clear_default_specs
require 'rubygems/core_ext/kernel_require'

Gem.use_gemdeps

1 change: 1 addition & 0 deletions lib/ruby/stdlib/rubygems/available_set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
class Gem::AvailableSet

include Enumerable
Expand Down
Loading

0 comments on commit bdb4a36

Please sign in to comment.