Skip to content

Commit

Permalink
Revert "Update to RubyGems 2.6.1. Fixes #3631."
Browse files Browse the repository at this point in the history
This reverts commit 8395657.
headius committed Mar 5, 2016

Verified

This commit was signed with the committer’s verified signature.
makenowjust Hiroya Fujinami
1 parent 8395657 commit 765042f
Showing 166 changed files with 1,047 additions and 3,070 deletions.
1 change: 0 additions & 1 deletion lib/ruby/shared/gauntlet_rubygems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'gauntlet'

107 changes: 25 additions & 82 deletions lib/ruby/shared/rubygems.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# -*- ruby -*-
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
@@ -10,7 +9,7 @@
require 'thread'

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

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

@configuration = nil
@gemdeps = nil
@loaded_specs = {}
LOADED_SPECS_MUTEX = Mutex.new
@path_to_default_spec_map = {}
@@ -174,14 +172,6 @@ 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
@@ -194,19 +184,18 @@ 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_by_path path
return false unless spec
return true if spec.activated?
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

begin
spec.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
rescue Gem::LoadError # this could fail due to gem dep collisions, go lax
Gem::Specification.find_by_name(spec.name).activate
end

return true
@@ -252,7 +241,7 @@ def self.bin_path(name, exec_name = nil, *requirements)
specs = dep.matching_specs(true)

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

specs = specs.find_all { |spec|
spec.executables.include? exec_name
@@ -321,10 +310,11 @@ def self.configuration=(config)
# package is not available as a gem, return nil.

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

##
@@ -339,38 +329,16 @@ def self.deflate(data)
# lookup files.

def self.paths
@paths ||= Gem::PathSupport.new(ENV)
@paths ||= Gem::PathSupport.new
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
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)
@paths = Gem::PathSupport.new env
Gem::Specification.dirs = @paths.path
end

@@ -465,9 +433,7 @@ def self.find_files(glob, check_load_path=true)

files = find_files_from_load_path glob if check_load_path

gem_specifications = @gemdeps ? Gem.loaded_specs.values : Gem::Specification.stubs

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

@@ -614,10 +580,6 @@ 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
@@ -634,9 +596,6 @@ 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'
@@ -818,14 +777,6 @@ 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

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

def self.use_paths(home, *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
paths = nil if paths == [nil]
paths = paths.first if Array === Array(paths).first
self.paths = { "GEM_HOME" => home, "GEM_PATH" => paths }
end

##
@@ -1103,7 +1052,7 @@ def self.use_gemdeps path = nil
end

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

rs.resolve_current.map do |s|
sp = s.full_spec
@@ -1133,12 +1082,6 @@ 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.
#
@@ -1253,7 +1196,6 @@ 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'
@@ -1300,3 +1242,4 @@ def clear_default_specs
require 'rubygems/core_ext/kernel_require'

Gem.use_gemdeps

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

include Enumerable
144 changes: 53 additions & 91 deletions lib/ruby/shared/rubygems/basic_specification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# BasicSpecification is an abstract class which implements some common code
# used by both Specification and StubSpecification.
@@ -23,29 +22,17 @@ class Gem::BasicSpecification
##
# The path this gemspec was loaded from. This attribute is not persisted.

attr_accessor :loaded_from
attr_reader :loaded_from

##
# Allows correct activation of git: and path: gems.

attr_writer :full_gem_path # :nodoc:

def initialize
internal_init
end

def self.default_specifications_dir
File.join(Gem.default_dir, "specifications", "default")
end

##
# The path to the gem.build_complete file within the extension install
# directory.

def gem_build_complete_path # :nodoc:
File.join extension_dir, 'gem.build_complete'
end

##
# True when the gem has been activated

@@ -59,24 +46,39 @@ def activated?
# eg: /usr/local/lib/ruby/gems/1.8

def base_dir
raise NotImplementedError
return Gem.dir unless loaded_from
@base_dir ||= if default_gem? then
File.dirname File.dirname File.dirname loaded_from
else
File.dirname File.dirname loaded_from
end
end

##
# Return true if this spec can require +file+.

def contains_requirable_file? file
if @ignored then
return false
elsif missing_extensions? then
@ignored = true

warn "Ignoring #{full_name} because its extensions are not built. " +
"Try: gem pristine #{name} --version #{version}"
return false
end
@contains_requirable_file ||= {}
@contains_requirable_file[file] ||=
begin
if instance_variable_defined?(:@ignored) then
return false
elsif missing_extensions? then
@ignored = true

warn "Ignoring #{full_name} because its extensions are not built. " +
"Try: gem pristine #{name} --version #{version}"
return false
end

have_file? file, Gem.suffixes
suffixes = Gem.suffixes

full_require_paths.any? do |dir|
base = "#{dir}/#{file}"
suffixes.any? { |suf| File.file? "#{base}#{suf}" }
end
end ? :yes : :no
@contains_requirable_file[file] == :yes
end

def default_gem?
@@ -88,14 +90,14 @@ def default_gem?
# Returns full path to the directory where gem's extensions are installed.

def extension_dir
@extension_dir ||= File.expand_path(File.join(extensions_dir, full_name)).untaint
@extension_dir ||= File.expand_path File.join(extensions_dir, full_name)
end

##
# Returns path to the extensions directory.

def extensions_dir
Gem.default_ext_dir_for(base_dir) ||
@extensions_dir ||= Gem.default_ext_dir_for(base_dir) ||
File.join(base_dir, 'extensions', Gem::Platform.local.to_s,
Gem.extension_api_version)
end
@@ -104,7 +106,7 @@ def find_full_gem_path # :nodoc:
# TODO: also, shouldn't it default to full_name if it hasn't been written?
path = File.expand_path File.join(gems_dir, full_name)
path.untaint
path
path if File.directory? path
end

private :find_full_gem_path
@@ -125,9 +127,9 @@ def full_gem_path

def full_name
if platform == Gem::Platform::RUBY or platform.nil? then
"#{name}-#{version}".dup.untaint
"#{name}-#{version}".untaint
else
"#{name}-#{version}-#{platform}".dup.untaint
"#{name}-#{version}-#{platform}".untaint
end
end

@@ -139,23 +141,15 @@ def full_require_paths
@full_require_paths ||=
begin
full_paths = raw_require_paths.map do |path|
File.join full_gem_path, path.untaint
File.join full_gem_path, path
end

full_paths << extension_dir if have_extensions?
full_paths << extension_dir unless @extensions.nil? || @extensions.empty?

full_paths
end
end

##
# The path to the data directory for this gem.

def datadir
# TODO: drop the extra ", gem_name" which is uselessly redundant
File.expand_path(File.join(gems_dir, full_name, "data", name)).untaint
end

##
# Full path of the target library file.
# If the file is not in this gem, return nil.
@@ -167,8 +161,8 @@ def to_fullpath path
begin
fullpath = nil
suffixes = Gem.suffixes
suffixes.find do |suf|
full_require_paths.find do |dir|
full_require_paths.find do |dir|
suffixes.find do |suf|
File.file?(fullpath = "#{dir}/#{path}#{suf}")
end
end ? fullpath : nil
@@ -191,14 +185,23 @@ def gem_dir
# gem directory. eg: /usr/local/lib/ruby/1.8/gems

def gems_dir
raise NotImplementedError
# TODO: this logic seems terribly broken, but tests fail if just base_dir
@gems_dir ||= File.join(loaded_from && base_dir || Gem.dir, "gems")
end

def internal_init # :nodoc:
##
# Set the path the Specification was loaded from. +path+ is converted to a
# String.

def loaded_from= path
@loaded_from = path && path.to_s

@extension_dir = nil
@extensions_dir = nil
@full_gem_path = nil
@gem_dir = nil
@ignored = nil
@gems_dir = nil
@base_dir = nil
end

##
@@ -216,7 +219,7 @@ def platform
end

def raw_require_paths # :nodoc:
raise NotImplementedError
Array(@require_paths)
end

##
@@ -237,7 +240,7 @@ def raw_require_paths # :nodoc:
# spec.require_path = '.'

def require_paths
return raw_require_paths unless have_extensions?
return raw_require_paths if @extensions.nil? || @extensions.empty?

[extension_dir].concat raw_require_paths
end
@@ -249,8 +252,8 @@ def require_paths
def source_paths
paths = raw_require_paths.dup

if have_extensions? then
ext_dirs = extensions.map do |extension|
if @extensions then
ext_dirs = @extensions.map do |extension|
extension.split(File::SEPARATOR, 2).first
end.uniq

@@ -260,30 +263,6 @@ def source_paths
paths.uniq
end

##
# Return all files in this gem that match for +glob+.

def matches_for_glob glob # TODO: rename?
# TODO: do we need these?? Kill it
glob = File.join(self.lib_dirs_glob, glob)

Dir[glob].map { |f| f.untaint } # FIX our tests are broken, run w/ SAFE=1
end

##
# Returns a string usable in Dir.glob to match all requirable paths
# for this spec.

def lib_dirs_glob
dirs = if self.require_paths.size > 1 then
"{#{self.require_paths.join(',')}}"
else
self.require_paths.first
end

"#{self.full_gem_path}/#{dirs}".dup.untaint
end

##
# Return a Gem::Specification from this gem

@@ -306,22 +285,5 @@ def stubbed?
raise NotImplementedError
end

private

def have_extensions?; !extensions.empty?; end

def have_file? file, suffixes
return true if raw_require_paths.any? do |path|
base = File.join(gems_dir, full_name, path.untaint, file).untaint
suffixes.any? { |suf| File.file? base + suf }
end

if have_extensions?
base = File.join extension_dir, file
suffixes.any? { |suf| File.file? base + suf }
else
false
end
end

end

18 changes: 3 additions & 15 deletions lib/ruby/shared/rubygems/command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -154,7 +153,7 @@ def execute

def show_lookup_failure(gem_name, version, errors, domain)
if errors and !errors.empty?
msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n".dup
msg = "Could not find a valid gem '#{gem_name}' (#{version}), here is why:\n"
errors.each { |x| msg << " #{x.wordy}\n" }
alert_error msg
else
@@ -300,8 +299,6 @@ 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
@@ -522,15 +519,10 @@ def wrap(text, width) # :doc:
end
end

add_common_option('-q', '--quiet', 'Silence command progress meter') do |value, options|
add_common_option('-q', '--quiet', 'Silence commands') 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.
@@ -547,11 +539,6 @@ def wrap(text, width) # :doc:
'Turn on Ruby debugging') do
end

add_common_option('--norc',
'Avoid loading any .gemrc file') do
end


# :stopdoc:

HELP = <<-HELP
@@ -592,3 +579,4 @@ def wrap(text, width) # :doc:

module Gem::Commands
end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/command_manager.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
5 changes: 0 additions & 5 deletions lib/ruby/shared/rubygems/commands/build_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/package'

@@ -42,10 +41,6 @@ def usage # :nodoc:
def execute
gemspec = get_one_gem_name

unless File.exist? gemspec
gemspec += '.gemspec' if File.exist? gemspec + '.gemspec'
end

if File.exist? gemspec then
spec = Gem::Specification.load gemspec

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/cert_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/security'
begin
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/check_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/validator'
12 changes: 3 additions & 9 deletions lib/ruby/shared/rubygems/commands/cleanup_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/dependency_list'
require 'rubygems/uninstaller'
@@ -76,9 +75,6 @@ def execute
end

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

get_primary_gems
get_candidate_gems
get_gems_to_cleanup
@@ -90,6 +86,9 @@ 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
@@ -108,7 +107,6 @@ def get_candidate_gems
end

def get_gems_to_cleanup

gems_to_cleanup = @candidate_gems.select { |spec|
@primary_gems[spec.name].version != spec.version
}
@@ -117,10 +115,6 @@ 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
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/contents_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'English'
require 'rubygems/command'
require 'rubygems/version_option'
45 changes: 17 additions & 28 deletions lib/ruby/shared/rubygems/commands/dependency_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/version_option'
@@ -62,24 +61,27 @@ def fetch_remote_specs dependency # :nodoc:
ss.map { |spec, _| spec }
end

def fetch_specs name_pattern, dependency # :nodoc:
def fetch_specs dependency # :nodoc:
specs = []

if local?
specs.concat Gem::Specification.stubs.find_all { |spec|
name_pattern =~ spec.name and
dependency.requirement.satisfied_by? spec.version
}.map(&:to_spec)
end

specs.concat dependency.matching_specs if local?
specs.concat fetch_remote_specs dependency if remote?

ensure_specs specs

specs.uniq.sort
end

def gem_dependency pattern, version, prerelease # :nodoc:
def gem_dependency args, version, prerelease # :nodoc:
args << '' if args.empty?

pattern = if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then
flags = $2 ? Regexp::IGNORECASE : nil
Regexp.new $1, flags
else
/\A#{Regexp.union(*args)}/
end

dependency = Gem::Deprecate.skip_during {
Gem::Dependency.new pattern, version
}
@@ -100,7 +102,7 @@ def display_pipe specs # :nodoc:
end

def display_readable specs, reverse # :nodoc:
response = String.new
response = ''

specs.each do |spec|
response << print_dependencies(spec)
@@ -119,12 +121,10 @@ def display_readable specs, reverse # :nodoc:
def execute
ensure_local_only_reverse_dependencies

pattern = name_pattern options[:args]

dependency =
gem_dependency pattern, options[:version], options[:prerelease]
gem_dependency options[:args], options[:version], options[:prerelease]

specs = fetch_specs pattern, dependency
specs = fetch_specs dependency

reverse = reverse_dependencies specs

@@ -153,7 +153,7 @@ def ensure_specs specs # :nodoc:
end

def print_dependencies(spec, level = 0) # :nodoc:
response = String.new
response = ''
response << ' ' * level + "Gem #{spec.full_name}\n"
unless spec.dependencies.empty? then
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
@@ -203,16 +203,5 @@ def find_reverse_dependencies spec # :nodoc:
result
end

private

def name_pattern args
args << '' if args.empty?

if args.length == 1 and args.first =~ /\A\/(.*)\/(i)?\z/m then
flags = $2 ? Regexp::IGNORECASE : nil
Regexp.new $1, flags
else
/\A#{Regexp.union(*args)}/
end
end
end

8 changes: 3 additions & 5 deletions lib/ruby/shared/rubygems/commands/environment_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Commands::EnvironmentCommand < Gem::Command
@@ -72,7 +71,7 @@ def usage # :nodoc:
end

def execute
out = String.new
out = ''
arg = options[:args][0]
out <<
case arg
@@ -104,7 +103,7 @@ def add_path out, path
end

def show_environment # :nodoc:
out = "RubyGems Environment:\n".dup
out = "RubyGems Environment:\n"

out << " - RUBYGEMS VERSION: #{Gem::VERSION}\n"

@@ -114,8 +113,6 @@ def show_environment # :nodoc:

out << " - INSTALLATION DIRECTORY: #{Gem.dir}\n"

out << " - USER INSTALLATION DIRECTORY: #{Gem.user_dir}\n"

out << " - RUBYGEMS PREFIX: #{Gem.prefix}\n" unless Gem.prefix.nil?

out << " - RUBY EXECUTABLE: #{Gem.ruby}\n"
@@ -158,3 +155,4 @@ def show_environment # :nodoc:
end

end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/fetch_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/version_option'
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/indexer'

11 changes: 10 additions & 1 deletion lib/ruby/shared/rubygems/commands/help_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Commands::HelpCommand < Gem::Command
@@ -371,5 +370,15 @@ def show_command_help command_name # :nodoc:
end
end

def show_help # :nodoc:
command = @command_manager[options[:help]]
if command then
# help with provided command
command.invoke("--help")
else
alert_error "Unknown command #{options[:help]}. Try 'gem help commands'"
end
end

end

4 changes: 1 addition & 3 deletions lib/ruby/shared/rubygems/commands/install_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/install_update_options'
require 'rubygems/dependency_installer'
@@ -186,7 +185,6 @@ def check_version # :nodoc:
end

def execute

if options.include? :gemdeps then
install_from_gemdeps
return # not reached
@@ -277,7 +275,7 @@ def install_gem_without_dependencies name, req # :nodoc:
gem = fetcher.download_to_cache dependency
end

inst = Gem::Installer.at gem, options
inst = Gem::Installer.new gem, options
inst.install

require 'rubygems/dependency_installer'
5 changes: 2 additions & 3 deletions lib/ruby/shared/rubygems/commands/list_command.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/commands/query_command'

##
# An alternate to Gem::Commands::QueryCommand that searches for gems starting
# with the supplied argument.
# with the the supplied argument.

class Gem::Commands::ListCommand < Gem::Commands::QueryCommand

@@ -34,7 +33,7 @@ def description # :nodoc:
end

def usage # :nodoc:
"#{program_name} [REGEXP ...]"
"#{program_name} [STRING ...]"
end

end
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/lock_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Commands::LockCommand < Gem::Command
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/mirror_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

unless defined? Gem::Commands::MirrorCommand
5 changes: 0 additions & 5 deletions lib/ruby/shared/rubygems/commands/open_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'English'
require 'rubygems/command'
require 'rubygems/version_option'
@@ -15,10 +14,6 @@ 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:
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/outdated_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/spec_fetcher'
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/owner_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/gemcutter_utilities'
13 changes: 1 addition & 12 deletions lib/ruby/shared/rubygems/commands/pristine_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/package'
require 'rubygems/installer'
@@ -22,11 +21,6 @@ def initialize
options[:all] = value
end

add_option('--skip=gem_name',
'used on --all, skip if name == gem_name') do |value, options|
options[:skip] = value
end

add_option('--[no-]extensions',
'Restore gems with extensions',
'in addition to regular gems') do |value, options|
@@ -115,11 +109,6 @@ def execute
next
end

if spec.name == options[:skip]
say "Skipped #{spec.full_name}, it was given through options"
next
end

if spec.bundled_gem_in_old_ruby?
say "Skipped #{spec.full_name}, it is bundled with old Ruby"
next
@@ -157,7 +146,7 @@ def execute
install_defaults.to_s['--env-shebang']
end

installer = Gem::Installer.at(gem,
installer = Gem::Installer.new(gem,
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
11 changes: 3 additions & 8 deletions lib/ruby/shared/rubygems/commands/push_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/gemcutter_utilities'
@@ -76,17 +75,13 @@ def send_gem name
@host = gem_data.spec.metadata['default_gem_server']
end

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

if gem_data.spec.metadata.has_key?('allowed_push_host')
push_host = gem_data.spec.metadata['allowed_push_host']
args << 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|
19 changes: 6 additions & 13 deletions lib/ruby/shared/rubygems/commands/query_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/spec_fetcher'
@@ -50,12 +49,6 @@ def initialize(name = 'query',
options[:all] = value
end

add_option('-e', '--exact',
'Name of gem(s) to query on matches the',
'provided STRING') do |value, options|
options[:exact] = value
end

add_option( '--[no-]prerelease',
'Display prerelease versions') do |value, options|
options[:prerelease] = value
@@ -85,8 +78,7 @@ def execute
elsif !options[:name].source.empty?
name = Array(options[:name])
else
args = options[:args].to_a
name = options[:exact] ? args : args.map{|arg| /#{arg}/i }
name = options[:args].to_a.map{|arg| /#{arg}/i }
end

prerelease = options[:prerelease]
@@ -169,7 +161,7 @@ def show_gems name, prerelease
:latest
end

if name.respond_to?(:source) && name.source.empty?
if name.source.empty?
spec_tuples = fetcher.detect(type) { true }
else
spec_tuples = fetcher.detect(type) do |name_tuple|
@@ -235,7 +227,7 @@ def entry_details entry, detail_tuple, specs, platforms

name_tuple, spec = detail_tuple

spec = spec.fetch_spec name_tuple if spec.respond_to? :fetch_spec
spec = spec.fetch_spec name_tuple unless Gem::Specification === spec

entry << "\n"

@@ -284,7 +276,7 @@ def make_entry entry_tuples, platforms
end

def spec_authors entry, spec
authors = "Author#{spec.authors.length > 1 ? 's' : ''}: ".dup
authors = "Author#{spec.authors.length > 1 ? 's' : ''}: "
authors << spec.authors.join(', ')
entry << format_text(authors, 68, 4)
end
@@ -298,7 +290,7 @@ def spec_homepage entry, spec
def spec_license entry, spec
return if spec.license.nil? or spec.license.empty?

licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: ".dup
licenses = "License#{spec.licenses.length > 1 ? 's' : ''}: "
licenses << spec.licenses.join(', ')
entry << "\n" << format_text(licenses, 68, 4)
end
@@ -348,3 +340,4 @@ def spec_summary entry, spec
end

end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/rdoc_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/rdoc'
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/search_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/commands/query_command'

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/server_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/server'

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/setup_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

##
3 changes: 1 addition & 2 deletions lib/ruby/shared/rubygems/commands/sources_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/remote_fetcher'
require 'rubygems/spec_fetcher'
@@ -103,7 +102,7 @@ def description # :nodoc:
RubyGems fetches gems from the sources you have configured (stored in your
~/.gemrc).
The default source is https://rubygems.org, but you may have other sources
The default source is https://rubygems.org, but you may have older sources
configured. This guide will help you update your sources or configure
yourself to use your own gem server.
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/specification_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/version_option'
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/stale_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Commands::StaleCommand < Gem::Command
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/uninstall_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/version_option'
require 'rubygems/uninstaller'
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/unpack_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/installer'
require 'rubygems/version_option'
6 changes: 2 additions & 4 deletions lib/ruby/shared/rubygems/commands/update_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/command_manager'
require 'rubygems/dependency_installer'
@@ -48,7 +47,7 @@ def initialize
end

def arguments # :nodoc:
"GEMNAME name of gem to update"
"REGEXP regexp to search for in gem name"
end

def defaults_str # :nodoc:
@@ -65,7 +64,7 @@ def description # :nodoc:
end

def usage # :nodoc:
"#{program_name} GEMNAME [GEMNAME ...]"
"#{program_name} REGEXP [REGEXP ...]"
end

def check_latest_rubygems version # :nodoc:
@@ -85,7 +84,6 @@ def check_update_arguments # :nodoc:
end

def execute

if options[:system] then
update_rubygems
return
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/commands/which_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Commands::WhichCommand < Gem::Command
26 changes: 15 additions & 11 deletions lib/ruby/shared/rubygems/commands/yank_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'
require 'rubygems/local_remote_options'
require 'rubygems/version_option'
@@ -32,7 +31,7 @@ def arguments # :nodoc:
end

def usage # :nodoc:
"#{program_name} GEM -v VERSION [-p PLATFORM] [--key KEY_NAME] [--host HOST]"
"#{program_name} GEM -v VERSION [-p PLATFORM] [--undo] [--key KEY_NAME]"
end

def initialize
@@ -41,25 +40,25 @@ def initialize
add_version_option("remove")
add_platform_option("remove")

add_option('--host HOST',
'Yank from another gemcutter-compatible host') do |value, options|
options[:host] = value
add_option('--undo') do |value, options|
options[:undo] = true
end

add_key_option
@host = nil
end

def execute
@host = options[:host]

sign_in @host
sign_in

version = get_version_from_requirements(options[:version])
platform = get_platform_from_requirements(options)

if version then
yank_gem(version, platform)
if options[:undo] then
unyank_gem(version, platform)
else
yank_gem(version, platform)
end
else
say "A version argument is required: #{usage}"
terminate_interaction
@@ -71,11 +70,16 @@ def yank_gem(version, platform)
yank_api_request(:delete, version, platform, "api/v1/gems/yank")
end

def unyank_gem(version, platform)
say "Unyanking gem from #{host}..."
yank_api_request(:put, version, platform, "api/v1/gems/unyank")
end

private

def yank_api_request(method, version, platform, api)
name = get_one_gem_name
response = rubygems_api_request(method, api, host) do |request|
response = rubygems_api_request(method, api) do |request|
request.add_field("Authorization", api_key)

data = {
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# :stopdoc:

#--
31 changes: 10 additions & 21 deletions lib/ruby/shared/rubygems/config_file.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -201,12 +200,11 @@ def initialize(args)
result.merge load_file file
end


@hash = operating_system_config.merge platform_config
unless arg_list.index '--norc'
@hash = @hash.merge system_config
@hash = @hash.merge user_config
@hash = @hash.merge environment_config
end
@hash = @hash.merge system_config
@hash = @hash.merge user_config
@hash = @hash.merge environment_config

# HACK these override command-line args, which is bad
@backtrace = @hash[:backtrace] if @hash.key? :backtrace
@@ -306,18 +304,9 @@ 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(host => api_key)
config = load_file(credentials_path).merge(:rubygems_api_key => api_key)

dirname = File.dirname credentials_path
Dir.mkdir(dirname) unless File.exist? dirname
@@ -329,15 +318,15 @@ def set_api_key host, api_key
f.write config.to_yaml
end

load_api_keys # reload
@rubygems_api_key = api_key
end

YAMLErrors = [ArgumentError]
YAMLErrors << Psych::SyntaxError if defined?(Psych::SyntaxError)

def load_file(filename)
Gem.load_yaml

yaml_errors = [ArgumentError]
yaml_errors << Psych::SyntaxError if defined?(Psych::SyntaxError)

return {} unless filename and File.exist? filename

begin
@@ -347,7 +336,7 @@ def load_file(filename)
return {}
end
return content
rescue *yaml_errors => e
rescue *YAMLErrors => e
warn "Failed to load #{filename}, #{e}"
rescue Errno::EACCES
warn "Failed to load #{filename} due to permissions problem."
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/core_ext/kernel_gem.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# 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
9 changes: 5 additions & 4 deletions lib/ruby/shared/rubygems/core_ext/kernel_require.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -61,11 +60,13 @@ def require path
#--
# TODO request access to the C implementation of this to speed up RubyGems

spec = Gem::Specification.find_active_stub_by_path path
spec = Gem::Specification.stubs.find { |s|
s.activated? and s.contains_requirable_file? path
}

begin
RUBYGEMS_ACTIVATION_MONITOR.exit
return gem_original_require(path)
return gem_original_require(spec.to_fullpath(path) || path)
end if spec

# Attempt to find +path+ in any unresolved gems...
@@ -104,7 +105,7 @@ def require path

# Ok, now find a gem that has no conflicts, starting
# at the highest version.
valid = found_specs.reject { |s| s.has_conflicts? }.last
valid = found_specs.select { |s| s.conflicts.empty? }.last

unless valid then
le = Gem::LoadError.new "unable to find a version of '#{names.first}' to activate"
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
module Gem
DEFAULT_HOST = "https://rubygems.org"

21 changes: 8 additions & 13 deletions lib/ruby/shared/rubygems/dependency.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# The Dependency class holds a Gem name and a Gem::Requirement.

@@ -165,10 +164,6 @@ def type
@type ||= :runtime
end

def runtime?
@type == :runtime || !@type
end

def == other # :nodoc:
Gem::Dependency === other &&
self.name == other.name &&
@@ -275,14 +270,14 @@ 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) && env_req.satisfied_by?(spec.version)
matches = Gem::Specification.stubs.find_all { |spec|
self.name === spec.name and # TODO: == instead of ===
requirement.satisfied_by? spec.version
}.map(&:to_spec)

if platform_only
matches.reject! { |spec|
spec.nil? || !Gem::Platform.match(spec.platform)
not Gem::Platform.match spec.platform
}
end

@@ -308,9 +303,9 @@ def to_specs

if specs.empty?
total = Gem::Specification.to_a.size
msg = "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n".dup
msg = "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n"
else
msg = "Could not find '#{name}' (#{requirement}) - did find: [#{specs.join ','}]\n".dup
msg = "Could not find '#{name}' (#{requirement}) - did find: [#{specs.join ','}]\n"
end
msg << "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}', execute `gem env` for more information"

@@ -328,11 +323,11 @@ def to_specs
def to_spec
matches = self.to_specs

active = matches.find { |spec| spec && spec.activated? }
active = matches.find { |spec| spec.activated? }

return active if active

matches.delete_if { |spec| spec.nil? || spec.version.prerelease? } unless prerelease?
matches.delete_if { |spec| spec.version.prerelease? } unless prerelease?

matches.last
end
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/dependency_installer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/dependency_list'
require 'rubygems/package'
4 changes: 0 additions & 4 deletions lib/ruby/shared/rubygems/dependency_list.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -142,9 +141,6 @@ def why_not_ok? quick = false
def ok_to_remove?(full_name, check_dev=true)
gem_to_remove = find_name full_name

# If the state is inconsistent, at least don't crash
return true unless gem_to_remove

siblings = @specs.find_all { |s|
s.name == gem_to_remove.name &&
s.full_name != gem_to_remove.full_name
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/deprecate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# Provides a single method +deprecate+ to be used to declare when
# something is going away.
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/doctor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/user_interaction'

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# This file contains all the various exceptions and other errors that are used
# inside of RubyGems.
4 changes: 2 additions & 2 deletions lib/ruby/shared/rubygems/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# TODO: the documentation in here is terrible.
#
# Each exception needs a brief description and the scenarios where it is
@@ -138,7 +137,7 @@ def build_message # :nodoc:
requester = requester ? requester.spec.full_name : 'The user'
dependency = @request.dependency

message = "#{requester} requires #{dependency} but it conflicted:\n".dup
message = "#{requester} requires #{dependency} but it conflicted:\n"

@conflicts.each do |_, conflict|
message << conflict.explanation
@@ -268,3 +267,4 @@ def version
# Backwards compatible typo'd exception class for early RubyGems 2.0.x

Gem::UnsatisfiableDepedencyError = Gem::UnsatisfiableDependencyError # :nodoc:

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/ext.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/ext/build_error.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# Raised when there is an error while building extensions.

3 changes: 0 additions & 3 deletions lib/ruby/shared/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -67,11 +66,9 @@ def self.run(command, results, command_name = nil)
# TODO use Process.spawn when ruby 1.8 support is dropped.
rubygems_gemdeps, ENV['RUBYGEMS_GEMDEPS'] = ENV['RUBYGEMS_GEMDEPS'], nil
if verbose
puts("current directory: #{Dir.pwd}")
puts(command)
system(command)
else
results << "current directory: #{Dir.pwd}"
results << command
results << `#{command} #{redirector}`
end
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/ext/cmake_builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/command'

class Gem::Ext::CmakeBuilder < Gem::Ext::Builder
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/ext/configure_builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
26 changes: 5 additions & 21 deletions lib/ruby/shared/rubygems/ext/ext_conf_builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -12,20 +11,9 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
FileEntry = FileUtils::Entry_ # :nodoc:

def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
tmp_dest = Dir.mktmpdir(".gem.", ".")

# Some versions of `mktmpdir` return absolute paths, which will break make
# if the paths contain spaces. However, on Ruby 1.9.x on Windows, relative
# paths cause all C extension builds to fail.
#
# As such, we convert to a relative path unless we are using Ruby 1.9.x on
# Windows. This means that when using Ruby 1.9.x on Windows, paths with
# spaces do not work.
#
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
#
# TODO: Make this unconditional when rubygems no longer supports Ruby 1.9.x.
tmp_dest = get_relative_path(tmp_dest) unless Gem.win_platform? && RUBY_VERSION <= '2.0'
# relative path required as some versions of mktmpdir return an absolute
# path which breaks make if it includes a space in the name
tmp_dest = get_relative_path(Dir.mktmpdir(".gem.", "."))

t = nil
Tempfile.open %w"siteconf .rb", "." do |siteconf|
@@ -47,12 +35,7 @@ def self.build(extension, directory, dest_path, results, args=[], lib_dir=nil)
begin
run cmd, results
ensure
if File.exist? 'mkmf.log'
results << "To see why this extension failed to compile, please check" \
" the mkmf.log which can be found here:\n"
results << " " + File.join(dest_path, 'mkmf.log') + "\n"
FileUtils.mv 'mkmf.log', dest_path
end
FileUtils.mv 'mkmf.log', dest_path if File.exist? 'mkmf.log'
siteconf.unlink
end

@@ -92,3 +75,4 @@ def self.get_relative_path(path)
end

end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/ext/rake_builder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/gem_runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
22 changes: 4 additions & 18 deletions lib/ruby/shared/rubygems/gemcutter_utilities.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/remote_fetcher'

##
@@ -69,14 +68,9 @@ def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &blo
terminate_interaction 1 # TODO: question this
end

if allowed_push_host
allowed_host_uri = URI.parse(allowed_push_host)
host_uri = URI.parse(self.host)

unless (host_uri.scheme == allowed_host_uri.scheme) && (host_uri.host == allowed_host_uri.host)
alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
terminate_interaction 1
end
if allowed_push_host and self.host != allowed_push_host
alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
terminate_interaction 1
end

uri = URI.parse "#{self.host}/#{path}"
@@ -115,7 +109,7 @@ def sign_in sign_in_host = nil

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

@@ -156,13 +150,5 @@ 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

118 changes: 91 additions & 27 deletions lib/ruby/shared/rubygems/indexer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/package'
require 'time'
@@ -94,30 +93,48 @@ def initialize(directory, options = {})
end

##
# Build various indices
# Abbreviate the spec for downloading. Abbreviated specs are only used for
# searching, downloading and related activities and do not need deployment
# specific information (e.g. list of files). So we abbreviate the spec,
# making it much smaller for quicker downloads.
#--
# TODO move to Gem::Specification

def abbreviate(spec)
spec.files = []
spec.test_files = []
spec.rdoc_options = []
spec.extra_rdoc_files = []
spec.cert_chain = []
spec
end

##
# Build various indicies

def build_indicies
Gem::Specification.dirs = []
Gem::Specification.add_specs(*map_gems_to_specs(gem_file_list))

def build_indices
specs = map_gems_to_specs gem_file_list
Gem::Specification._resort! specs
build_marshal_gemspecs specs
build_modern_indices specs if @build_modern
build_marshal_gemspecs
build_modern_indicies if @build_modern

compress_indices
compress_indicies
end

##
# Builds Marshal quick index gemspecs.

def build_marshal_gemspecs specs
count = specs.count
def build_marshal_gemspecs
count = Gem::Specification.count { |s| not s.default_gem? }
progress = ui.progress_reporter count,
"Generating Marshal quick index gemspecs for #{count} gems",
"Complete"

files = []

Gem.time 'Generated Marshal quick index gemspecs' do
specs.each do |spec|
Gem::Specification.each do |spec|
next if spec.default_gem?
spec_file_name = "#{spec.original_name}.gemspec.rz"
marshal_name = File.join @quick_marshal_dir, spec_file_name
@@ -169,14 +186,16 @@ def build_modern_index(index, file, name)
end

##
# Builds indices for RubyGems 1.2 and newer. Handles full, latest, prerelease
# Builds indicies for RubyGems 1.2 and newer. Handles full, latest, prerelease

def build_modern_indicies
specs = Gem::Specification.reject { |s| s.default_gem? }

def build_modern_indices specs
prerelease, released = specs.partition { |s|
s.version.prerelease?
}
latest_specs =
Gem::Specification._latest_specs specs
Gem::Specification.latest_specs.reject { |s| s.default_gem? }

build_modern_index(released.sort, @specs_index, 'specs')
build_modern_index(latest_specs.sort, @latest_specs_index, 'latest specs')
@@ -202,8 +221,18 @@ def map_gems_to_specs gems
spec = Gem::Package.new(gemfile).spec
spec.loaded_from = gemfile

spec.abbreviate
spec.sanitize
# HACK: fuck this shit - borks all tests that use pl1
# if File.basename(gemfile, ".gem") != spec.original_name then
# exp = spec.full_name
# exp << " (#{spec.original_name})" if
# spec.original_name != spec.full_name
# msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
# alert_warning msg
# next
# end

abbreviate spec
sanitize spec

spec
rescue SignalException
@@ -219,14 +248,14 @@ def map_gems_to_specs gems
end

##
# Compresses indices on disk
# Compresses indicies on disk
#--
# All future files should be compressed using gzip, not deflate

def compress_indices
say "Compressing indices"
def compress_indicies
say "Compressing indicies"

Gem.time 'Compressed indices' do
Gem.time 'Compressed indicies' do
if @build_modern then
gzip @specs_index
gzip @latest_specs_index
@@ -274,12 +303,12 @@ def gem_file_list
end

##
# Builds and installs indices.
# Builds and installs indicies.

def generate_index
make_temp_directories
build_indices
install_indices
build_indicies
install_indicies
rescue SignalException
ensure
FileUtils.rm_rf @directory
@@ -295,9 +324,9 @@ def gzip(filename)
end

##
# Install generated indices into the destination directory.
# Install generated indicies into the destination directory.

def install_indices
def install_indicies
verbose = Gem.configuration.really_verbose

say "Moving index into production dir #{@dest_directory}" if verbose
@@ -351,6 +380,38 @@ def paranoid(path, extension)
end
end

##
# Sanitize the descriptive fields in the spec. Sometimes non-ASCII
# characters will garble the site index. Non-ASCII characters will
# be replaced by their XML entity equivalent.

def sanitize(spec)
spec.summary = sanitize_string(spec.summary)
spec.description = sanitize_string(spec.description)
spec.post_install_message = sanitize_string(spec.post_install_message)
spec.authors = spec.authors.collect { |a| sanitize_string(a) }

spec
end

##
# Sanitize a single string.

def sanitize_string(string)
return string unless string

# HACK the #to_s is in here because RSpec has an Array of Arrays of
# Strings for authors. Need a way to disallow bad values on gemspec
# generation. (Probably won't happen.)
string = string.to_s

begin
Builder::XChar.encode string
rescue NameError, NoMethodError
string.to_xs
end
end

##
# Perform an in-place update of the repository from newly added gems.

@@ -374,7 +435,10 @@ def update_index
specs = map_gems_to_specs updated_gems
prerelease, released = specs.partition { |s| s.version.prerelease? }

files = build_marshal_gemspecs specs
Gem::Specification.dirs = []
Gem::Specification.add_specs(*specs)

files = build_marshal_gemspecs

Gem.time 'Updated indexes' do
update_specs_index released, @dest_specs_index, @specs_index
@@ -384,7 +448,7 @@ def update_index
@prerelease_specs_index)
end

compress_indices
compress_indicies

verbose = Gem.configuration.really_verbose

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/install_default_message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/user_interaction'

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/install_message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/user_interaction'

7 changes: 0 additions & 7 deletions lib/ruby/shared/rubygems/install_update_options.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -174,12 +173,6 @@ def add_install_update_options
"meet version requirements") do |value, options|
options[:minimal_deps] = true
end

add_option(:"Install/Update", "--[no-]post-install-message",
"Print post install message") do |value, options|
options[:post_install_message] = value
end

end

##
105 changes: 33 additions & 72 deletions lib/ruby/shared/rubygems/installer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -62,6 +61,11 @@ class Gem::Installer

attr_reader :options

##
# Sets the specification for .gem-less installs.

attr_writer :spec

@path_warning = false

@install_lock = Mutex.new
@@ -95,46 +99,6 @@ def exec_format

end

##
# Construct an installer object for the gem file located at +path+

def self.at path, options = {}
security_policy = options[:security_policy]
package = Gem::Package.new path, security_policy
new package, options
end

class FakePackage
attr_accessor :spec

def initialize(spec)
@spec = spec
end

def extract_files destination_dir, pattern = '*'
FileUtils.mkdir_p destination_dir

spec.files.each do |file|
file = File.join destination_dir, file
next if File.exist? file
FileUtils.mkdir_p File.dirname(file)
File.open file, 'w' do |fp| fp.puts "# #{file}" end
end
end

def copy_to path
end
end

##
# Construct an installer object for an ephemeral gem (one where we don't
# actually have a .gem file, just a spec)

def self.for_spec spec, options = {}
# FIXME: we should have a real Package class for this
new FakePackage.new(spec), options
end

##
# Constructs an Installer instance that will install the gem located at
# +gem+. +options+ is a Hash with the following keys:
@@ -158,22 +122,17 @@ def self.for_spec spec, options = {}
# :build_args:: An Array of arguments to pass to the extension builder
# process. If not set, then Gem::Command.build_args is used

def initialize(package, options={})
def initialize(gem, options={})
require 'fileutils'

@gem = gem
@options = options
if package.is_a? String
security_policy = options[:security_policy]
@package = Gem::Package.new package, security_policy
if $VERBOSE
warn "constructing an Installer object with a string is deprecated. Please use Gem::Installer.at (called from: #{caller.first})"
end
else
@package = package
end
@package = Gem::Package.new @gem

process_options

@package.security_policy = @security_policy

if options[:user_install] and not options[:unpack] then
@gem_home = Gem.user_dir
@bin_dir = Gem.bindir gem_home unless options[:bin_dir]
@@ -213,21 +172,15 @@ def check_executable_overwrite filename # :nodoc:
next unless io.gets =~ /This file was generated by RubyGems/

ruby_executable = true
existing = io.read.slice(%r{
^(
gem \s |
load \s Gem\.bin_path\(
)
(['"])(.*?)(\2),
}x, 3)
existing = io.read.slice(/^gem (['"])(.*?)(\1),/, 2)
end

return if spec.name == existing

# somebody has written to RubyGems' directory, overwrite, too bad
return if Gem.default_bindir != @bin_dir and not ruby_executable

question = "#{spec.name}'s executable \"#{filename}\" conflicts with ".dup
question = "#{spec.name}'s executable \"#{filename}\" conflicts with "

if ruby_executable then
question << existing
@@ -258,7 +211,7 @@ def gem_dir
# Lazy accessor for the installer's spec.

def spec
@package.spec
@spec ||= @package.spec
rescue Gem::Package::Error => e
raise Gem::InstallError, "invalid gem: #{e.message}"
end
@@ -277,7 +230,7 @@ def spec
def install
pre_install_checks

FileUtils.rm_f File.join gem_home, 'specifications', spec.spec_name
FileUtils.rm_f File.join gem_home, 'specifications', @spec.spec_name

run_pre_install_hooks

@@ -286,12 +239,12 @@ def install

FileUtils.mkdir_p gem_dir

spec.loaded_from = spec_file

if @options[:install_as_default]
spec.loaded_from = default_spec_file
extract_bin
write_default_spec
else
spec.loaded_from = spec_file
extract_files

build_extensions
@@ -303,9 +256,9 @@ def install
write_cache_file
end

say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
say spec.post_install_message unless spec.post_install_message.nil?

Gem::Installer.install_lock.synchronize { Gem::Specification.reset }
Gem::Installer.install_lock.synchronize { Gem::Specification.add_spec spec }

run_post_install_hooks

@@ -398,19 +351,19 @@ def unpack(directory)
end

##
# The location of the spec file that is installed.
# The location of of the spec file that is installed.
#

def spec_file
File.join gem_home, "specifications", "#{spec.full_name}.gemspec"
end

##
# The location of the default spec file for default gems.
# The location of of the default spec file for default gems.
#

def default_spec_file
File.join Gem::Specification.default_specifications_dir, "#{spec.full_name}.gemspec"
File.join gem_home, "specifications/default", "#{spec.full_name}.gemspec"
end

##
@@ -633,8 +586,7 @@ def process_options # :nodoc:
:bin_dir => nil,
:env_shebang => false,
:force => false,
:only_install_dir => false,
:post_install_message => true
:only_install_dir => false
}.merge options

@env_shebang = options[:env_shebang]
@@ -643,6 +595,7 @@ def process_options # :nodoc:
@gem_home = options[:install_dir] || Gem.dir
@ignore_dependencies = options[:ignore_dependencies]
@format_executable = options[:format_executable]
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@only_install_dir = options[:only_install_dir]

@@ -708,7 +661,7 @@ def app_script_text(bin_file_name)
require 'rubygems'
version = "#{Gem::Requirement.default}.a"
version = "#{Gem::Requirement.default}"
if ARGV.first
str = ARGV.first
@@ -719,6 +672,7 @@ def app_script_text(bin_file_name)
end
end
gem '#{spec.name}', version
load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version)
TEXT
end
@@ -810,6 +764,11 @@ def dir
def pre_install_checks
verify_gem_home options[:unpack]

# If we're forcing the install then disable security unless the security
# policy says that we only install signed gems.
@security_policy = nil if
@force and @security_policy and not @security_policy.only_signed

ensure_loadable_spec

if options[:install_as_default]
@@ -852,7 +811,9 @@ def write_build_info_file

def write_cache_file
cache_file = File.join gem_home, 'cache', spec.file_name
@package.copy_to cache_file

FileUtils.cp @gem, cache_file unless File.exist? cache_file
end

end

5 changes: 2 additions & 3 deletions lib/ruby/shared/rubygems/installer_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/test_case'
require 'rubygems/installer'

@@ -177,15 +176,15 @@ def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
end
end

@installer = Gem::Installer.at @gem
@installer = Gem::Installer.new @gem
end

##
# Creates an installer for +spec+ that will install into +gem_home+. If
# +user+ is true a user-install will be performed.

def util_installer(spec, gem_home, user=false)
Gem::Installer.at(spec.cache_file,
Gem::Installer.new(spec.cache_file,
:install_dir => gem_home,
:user_install => user)
end
3 changes: 1 addition & 2 deletions lib/ruby/shared/rubygems/local_remote_options.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -24,7 +23,7 @@ def accept_uri_http
raise OptionParser::InvalidArgument, value
end

unless ['http', 'https', 'file', 's3'].include?(uri.scheme)
unless ['http', 'https', 'file'].include?(uri.scheme)
raise OptionParser::InvalidArgument, value
end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/mock_gem_ui.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'stringio'
require 'rubygems/user_interaction'

3 changes: 1 addition & 2 deletions lib/ruby/shared/rubygems/name_tuple.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
#
# Represents a gem of name +name+ at +version+ of +platform+. These
@@ -54,7 +53,7 @@ def full_name
"#{@name}-#{@version}"
else
"#{@name}-#{@version}-#{@platform}"
end.dup.untaint
end.untaint
end

##
27 changes: 7 additions & 20 deletions lib/ruby/shared/rubygems/package.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
#--
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
# See LICENSE.txt for additional licensing information.
@@ -59,7 +58,7 @@ def initialize message, source = nil
if source
@path = source.path

message = message + " in #{path}" if path
message << " in #{path}" if path
end

super message
@@ -124,7 +123,7 @@ def self.build spec, skip_validation=false
# If +gem+ is an existing file in the old format a Gem::Package::Old will be
# returned.

def self.new gem, security_policy = nil
def self.new gem
gem = if gem.is_a?(Gem::Package::Source)
gem
elsif gem.respond_to? :read
@@ -133,7 +132,7 @@ def self.new gem, security_policy = nil
Gem::Package::FileSource.new gem
end

return super unless Gem::Package == self
return super(gem) unless Gem::Package == self
return super unless gem.present?

return super unless gem.start
@@ -145,27 +144,20 @@ def self.new gem, security_policy = nil
##
# Creates a new package that will read or write to the file +gem+.

def initialize gem, security_policy # :notnew:
def initialize gem # :notnew:
@gem = gem

@build_time = Time.now
@checksums = {}
@contents = nil
@digests = Hash.new { |h, algorithm| h[algorithm] = {} }
@files = nil
@security_policy = security_policy
@security_policy = nil
@signatures = {}
@signer = nil
@spec = nil
end

##
# Copies this package to +path+ (if possible)

def copy_to path
FileUtils.cp @gem.path, path unless File.exist? path
end

##
# Adds a checksum for each entry in the gem to checksums.yaml.gz.

@@ -208,11 +200,7 @@ def add_contents tar # :nodoc:

def add_files tar # :nodoc:
@spec.files.each do |file|
stat = File.lstat file

if stat.symlink?
tar.add_symlink file, File.readlink(file), stat.mode
end
stat = File.stat file

next unless stat.file?

@@ -383,8 +371,6 @@ def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
FileUtils.chmod entry.header.mode, destination
end if entry.file?

File.symlink(entry.header.linkname, destination) if entry.symlink?

verbose destination
end
end
@@ -625,3 +611,4 @@ def verify_gz entry # :nodoc:
require 'rubygems/package/tar_reader'
require 'rubygems/package/tar_reader/entry'
require 'rubygems/package/tar_writer'

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/package/digest_io.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# IO wrapper that creates digests of contents written to the IO it wraps.

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/package/file_source.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# The primary source of gems is a file on disk, including all usages
# internal to rubygems.
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/package/io_source.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# Supports reading and writing gems from/to a generic IO object. This is
# useful for other applications built on top of rubygems, such as
12 changes: 6 additions & 6 deletions lib/ruby/shared/rubygems/package/old.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
@@ -19,14 +18,14 @@ class Gem::Package::Old < Gem::Package
# Creates a new old-format package reader for +gem+. Old-format packages
# cannot be written.

def initialize gem, security_policy
def initialize gem
require 'fileutils'
require 'zlib'
Gem.load_yaml

@contents = nil
@gem = gem
@security_policy = security_policy
@security_policy = nil
@spec = nil
end

@@ -64,7 +63,7 @@ def extract_files destination_dir

destination = install_location full_name, destination_dir

file_data = String.new
file_data = ''

read_until_dashes io do |line|
file_data << line
@@ -95,7 +94,7 @@ def extract_files destination_dir
# Reads the file list section from the old-format gem +io+

def file_list io # :nodoc:
header = String.new
header = ''

read_until_dashes io do |line|
header << line
@@ -135,7 +134,7 @@ def spec

return @spec if @spec

yaml = String.new
yaml = ''

@gem.with_read_io do |io|
skip_ruby io
@@ -176,3 +175,4 @@ def verify
end

end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/package/source.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
class Gem::Package::Source # :nodoc:
end

2 changes: 1 addition & 1 deletion lib/ruby/shared/rubygems/package/tar_header.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
#--
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
# See LICENSE.txt for additional licensing information.
@@ -227,3 +226,4 @@ def oct(num, len)
end

end

2 changes: 1 addition & 1 deletion lib/ruby/shared/rubygems/package/tar_reader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
#--
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
# See LICENSE.txt for additional licensing information.
@@ -121,3 +120,4 @@ def seek name # :yields: entry
end

require 'rubygems/package/tar_reader/entry'

9 changes: 1 addition & 8 deletions lib/ruby/shared/rubygems/package/tar_reader/entry.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
#++
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
# See LICENSE.txt for additional licensing information.
@@ -103,13 +102,6 @@ def file?
@header.typeflag == "0"
end

##
# Is this tar entry a symlink?

def symlink?
@header.typeflag == "2"
end

##
# The position in the tar entry

@@ -152,3 +144,4 @@ def rewind
end

end

16 changes: 3 additions & 13 deletions lib/ruby/shared/rubygems/package/tar_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems/test_case'
require 'rubygems/package'

@@ -72,7 +71,7 @@ def calc_checksum(header)
SP(Z(to_oct(sum, 6)))
end

def header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "")
def header(type, fname, dname, length, mode, mtime, checksum = nil)
checksum ||= " " * 8

arr = [ # struct tarfile_entry_posix
@@ -84,7 +83,7 @@ def header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "
Z(to_oct(mtime, 11)), # char mtime[12]; 0 padded, octal, null
checksum, # char checksum[8]; 0 padded, octal, null, space
type, # char typeflag[1]; file: "0" dir: "5"
ASCIIZ(linkname, 100), # char linkname[100]; ASCII + (Z unless filled)
"\0" * 100, # char linkname[100]; ASCII + (Z unless filled)
"ustar\0", # char magic[6]; "ustar\0"
"00", # char version[2]; "00"
ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ
@@ -118,12 +117,6 @@ def tar_file_header(fname, dname, mode, length, mtime)
header("0", fname, dname, length, mode, mtime, checksum)
end

def tar_symlink_header(fname, prefix, mode, mtime, linkname)
h = header("2", fname, prefix, 0, mode, mtime, nil, linkname)
checksum = calc_checksum(h)
header("2", fname, prefix, 0, mode, mtime, checksum, linkname)
end

def to_oct(n, pad_size)
"%0#{pad_size}o" % n
end
@@ -140,8 +133,5 @@ def util_dir_entry
util_entry tar_dir_header("foo", "bar", 0, Time.now)
end

def util_symlink_entry
util_entry tar_symlink_header("foo", "bar", 0, Time.now, "link")
end

end

21 changes: 1 addition & 20 deletions lib/ruby/shared/rubygems/package/tar_writer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# frozen_string_literal: true
#--
# Copyright (C) 2004 Mauricio Julio Fernández Pradier
# See LICENSE.txt for additional licensing information.
@@ -234,25 +233,6 @@ def add_file_simple(name, mode, size) # :yields: io
self
end

##
# Adds symlink +name+ with permissions +mode+, linking to +target+.

def add_symlink(name, target, mode)
check_closed

name, prefix = split_name name

header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
:size => 0, :typeflag => "2",
:linkname => target,
:prefix => prefix,
:mtime => Time.now).to_s

@io.write header

self
end

##
# Raises IOError if the TarWriter is closed

@@ -343,3 +323,4 @@ def split_name(name) # :nodoc:
end

end

1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/package_task.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
#
# Permission is hereby granted, free of charge, to any person obtaining
50 changes: 25 additions & 25 deletions lib/ruby/shared/rubygems/path_support.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
#
# Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings
@@ -22,36 +21,43 @@ 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)
@home = env["GEM_HOME"] || Gem.default_dir
def initialize(env=ENV)
@env = env

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

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

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

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

@spec_cache_dir = @spec_cache_dir.dup.untaint
end

private

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

def split_gem_path gpaths, home
def path=(gpaths)
# 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
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
if gpaths.kind_of?(Array)
gem_path = gpaths.dup
else
gem_path = gpaths.split(Gem.path_separator)
end

if File::ALT_SEPARATOR then
@@ -60,21 +66,15 @@ def split_gem_path gpaths, home
end
end

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

gem_path.uniq
end

# Return the default Gem path
def default_path
gem_path = Gem.default_path + [@home]
gem_path = Gem.default_path + [@home]

if defined?(APPLE_GEM_HOME)
gem_path << APPLE_GEM_HOME
if defined?(APPLE_GEM_HOME)
gem_path << APPLE_GEM_HOME
end
end
gem_path

@path = gem_path.uniq
end
end
6 changes: 2 additions & 4 deletions lib/ruby/shared/rubygems/platform.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require "rubygems/deprecate"

##
@@ -96,7 +95,6 @@ def initialize(arch)
[os, version]
when /netbsdelf/ then [ 'netbsdelf', nil ]
when /openbsd(\d+\.\d+)?/ then [ 'openbsd', $1 ]
when /bitrig(\d+\.\d+)?/ then [ 'bitrig', $1 ]
when /solaris(\d+\.\d+)?/ then [ 'solaris', $1 ]
# test
when /^(\w+_platform)(\d+)?/ then [ $1, $2 ]
@@ -149,8 +147,8 @@ def ===(other)
return nil unless Gem::Platform === other

# cpu
([nil,'universal'].include?(@cpu) or [nil, 'universal'].include?(other.cpu) or @cpu == other.cpu or
(@cpu == 'arm' and other.cpu =~ /\Aarm/)) and
(@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu or
(@cpu == 'arm' and other.cpu =~ /\Aarm/)) and

# os
@os == other.os and
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/psych_additions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
# This exists just to satisfy bugs in marshal'd gemspecs that
# contain a reference to YAML::PrivateType. We prune these out
# in Specification._load, but if we don't have the constant, Marshal
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/psych_tree.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
module Gem
if defined? ::Psych::Visitors
class NoAliasYAMLTree < Psych::Visitors::YAMLTree
4 changes: 2 additions & 2 deletions lib/ruby/shared/rubygems/rdoc.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/user_interaction'
require 'fileutils'
@@ -21,7 +20,7 @@
require 'rdoc/rubygems_hook'
loaded_hook = true
module Gem
RDoc = ::RDoc::RubygemsHook
RDoc = RDoc::RubygemsHook
end
rescue LoadError
end
@@ -333,3 +332,4 @@ def setup
end unless loaded_hook

Gem.done_installing(&Gem::RDoc.method(:generation_hook))

32 changes: 6 additions & 26 deletions lib/ruby/shared/rubygems/remote_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'rubygems'
require 'rubygems/request'
require 'rubygems/uri_formatter'
@@ -52,8 +51,6 @@ def self.fetcher
@fetcher ||= self.new Gem.configuration[:http_proxy]
end

attr_accessor :headers

##
# Initialize a remote fetcher using the source URI and possible proxy
# information.
@@ -67,11 +64,8 @@ def self.fetcher
#
# +dns+: An object to use for DNS resolution of the API endpoint.
# By default, use Resolv::DNS.
#
# +headers+: A set of additional HTTP headers to be sent to the server when
# fetching the gem.

def initialize(proxy=nil, dns=Resolv::DNS.new, headers={})
def initialize(proxy=nil, dns=Resolv::DNS.new)
require 'net/http'
require 'stringio'
require 'time'
@@ -85,7 +79,6 @@ def initialize(proxy=nil, dns=Resolv::DNS.new, headers={})
@cert_files = Gem::Request.get_cert_files

@dns = dns
@headers = headers
end

##
@@ -98,8 +91,7 @@ def api_endpoint(uri)
begin
res = @dns.getresource "_rubygems._tcp.#{host}",
Resolv::DNS::Resource::IN::SRV
rescue Resolv::ResolvError => e
verbose "Getting SRV record failed: #{e}"
rescue Resolv::ResolvError
uri
else
target = res.target.to_s.strip
@@ -242,9 +234,7 @@ def fetch_file uri, *_

def fetch_http uri, last_modified = nil, head = false, depth = 0
fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get
response = request uri, fetch_type, last_modified do |req|
headers.each { |k,v| req.add_field(k,v) }
end
response = request uri, fetch_type, last_modified

case response
when Net::HTTPOK, Net::HTTPNotModified then
@@ -322,19 +312,9 @@ def cache_update_path uri, path = nil, update = true
end

if update and path
begin
open(path, 'wb') do |io|
io.flock(File::LOCK_EX)
io.write data
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
open(path, 'wb') do |io|
io.write data
end
end
open(path, 'wb') do |io|
io.flock(File::LOCK_EX)
io.write data
end
end

10 changes: 3 additions & 7 deletions lib/ruby/shared/rubygems/request.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'net/http'
require 'thread'
require 'time'
@@ -156,7 +155,7 @@ def perform_request request # :nodoc:
if Net::HTTPOK === incomplete_response
reporter.fetch(file_name, incomplete_response.content_length)
downloaded = 0
data = String.new
data = ''

incomplete_response.read_body do |segment|
data << segment
@@ -186,10 +185,6 @@ def perform_request request # :nodoc:

bad_response = true
retry
rescue Net::HTTPFatalError
verbose "fatal error"

raise Gem::RemoteFetcher::FetchError.new('fatal error', @uri)
# HACK work around EOFError bug in Net::HTTP
# NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
# to install gems.
@@ -223,7 +218,7 @@ def reset(connection)
end

def user_agent
ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}".dup
ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"

ruby_version = RUBY_VERSION
ruby_version += 'dev' if RUBY_PATCHLEVEL == -1
@@ -246,3 +241,4 @@ def user_agent
require 'rubygems/request/http_pool'
require 'rubygems/request/https_pool'
require 'rubygems/request/connection_pools'

13 changes: 4 additions & 9 deletions lib/ruby/shared/rubygems/request/connection_pools.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'thread'

class Gem::Request::ConnectionPools # :nodoc:
@@ -62,22 +61,18 @@ def no_proxy? host, env_no_proxy
end

def net_http_args uri, proxy_uri
# URI::Generic#hostname was added in ruby 1.9.3, use it if exists, otherwise
# don't support IPv6 literals and use host.
hostname = uri.respond_to?(:hostname) ? uri.hostname : uri.host
net_http_args = [hostname, uri.port]
net_http_args = [uri.host, uri.port]

no_proxy = get_no_proxy_from_env

if proxy_uri and not no_proxy?(hostname, no_proxy) then
proxy_hostname = proxy_uri.respond_to?(:hostname) ? proxy_uri.hostname : proxy_uri.host
if proxy_uri and not no_proxy?(uri.host, no_proxy) then
net_http_args + [
proxy_hostname,
proxy_uri.host,
proxy_uri.port,
Gem::UriFormatter.new(proxy_uri.user).unescape,
Gem::UriFormatter.new(proxy_uri.password).unescape,
]
elsif no_proxy? hostname, no_proxy then
elsif no_proxy? uri.host, no_proxy then
net_http_args + [nil, nil]
else
net_http_args
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/request/http_pool.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# A connection "pool" that only manages one connection for now. Provides
# thread safe `checkout` and `checkin` methods. The pool consists of one
1 change: 0 additions & 1 deletion lib/ruby/shared/rubygems/request/https_pool.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
class Gem::Request::HTTPSPool < Gem::Request::HTTPPool # :nodoc:
private

27 changes: 11 additions & 16 deletions lib/ruby/shared/rubygems/request_set.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
require 'tsort'

##
@@ -77,11 +76,6 @@ class Gem::RequestSet

attr_reader :vendor_set # :nodoc:

##
# The set of source gems imported via load_gemdeps.

attr_reader :source_set

##
# Creates a RequestSet for a list of Gem::Dependency objects, +deps+. You
# can then #resolve and #install the resolved list of dependencies.
@@ -111,7 +105,6 @@ def initialize *deps
@sorted = nil
@specs = nil
@vendor_set = nil
@source_set = nil

yield self if block_given?
end
@@ -149,6 +142,7 @@ def install options, &block # :yields: request, installer
return requests
end

cache_dir = options[:cache_dir] || Gem.dir
@prerelease = options[:prerelease]

requests = []
@@ -163,13 +157,18 @@ def install options, &block # :yields: request, installer
end
end

spec = req.spec.install options do |installer|
yield req, installer if block_given?
end
path = req.download cache_dir

inst = Gem::Installer.new path, options

requests << spec
yield req, inst if block_given?

requests << inst.install
end

requests
ensure
raise if $!
return requests if options[:gemdeps]

specs = requests.map do |request|
@@ -188,8 +187,6 @@ def install options, &block # :yields: request, installer
Gem.done_installing_hooks.each do |hook|
hook.call inst, specs
end unless Gem.done_installing_hooks.empty?

requests
end

##
@@ -275,11 +272,10 @@ def install_into dir, force = true, options = {}
def load_gemdeps path, without_groups = [], installing = false
@git_set = Gem::Resolver::GitSet.new
@vendor_set = Gem::Resolver::VendorSet.new
@source_set = Gem::Resolver::SourceSet.new

@git_set.root_dir = @install_dir

lock_file = "#{File.expand_path(path)}.lock".dup.untaint
lock_file = "#{File.expand_path(path)}.lock".untaint
begin
tokenizer = Gem::RequestSet::Lockfile::Tokenizer.from_file lock_file
parser = tokenizer.make_parser self, []
@@ -343,7 +339,6 @@ def resolve set = Gem::Resolver::BestSet.new
@sets << set
@sets << @git_set
@sets << @vendor_set
@sets << @source_set

set = Gem::Resolver.compose_sets(*@sets)
set.remote = @remote
64 changes: 8 additions & 56 deletions lib/ruby/shared/rubygems/request_set/gem_dependency_api.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# A semi-compatible DSL for the Bundler Gemfile and Isolate gem dependencies
# files.
@@ -175,7 +174,7 @@ class Gem::RequestSet::GemDependencyAPI
##
# A Hash containing gem names and files to require from those gems.

attr_reader :requires
attr_reader :requires # :nodoc:

##
# A set of gems that are loaded via the +:path+ option to #gem
@@ -205,7 +204,6 @@ def initialize set, path
@installing = false
@requires = Hash.new { |h, name| h[name] = [] }
@vendor_set = @set.vendor_set
@source_set = @set.source_set
@gem_sources = {}
@without_groups = []

@@ -364,7 +362,6 @@ def gem name, *requirements
source_set ||= gem_path name, options
source_set ||= gem_git name, options
source_set ||= gem_git_source name, options
source_set ||= gem_source name, options

duplicate = @dependencies.include? name

@@ -399,7 +396,7 @@ def gem name, *requirements
##
# Handles the git: option from +options+ for gem +name+.
#
# Returns +true+ if the gist or git option was handled.
# Returns +true+ if the path option was handled.

def gem_git name, options # :nodoc:
if gist = options.delete(:gist) then
@@ -410,7 +407,11 @@ def gem_git name, options # :nodoc:

pin_gem_source name, :git, repository

reference = gem_git_reference options
reference = nil
reference ||= options.delete :ref
reference ||= options.delete :branch
reference ||= options.delete :tag
reference ||= 'master'

submodules = options.delete :submodules

@@ -419,36 +420,6 @@ def gem_git name, options # :nodoc:
true
end

##
# Handles the git options from +options+ for git gem.
#
# Returns reference for the git gem.

def gem_git_reference options # :nodoc:
ref = options.delete :ref
branch = options.delete :branch
tag = options.delete :tag

reference = nil
reference ||= ref
reference ||= branch
reference ||= tag
reference ||= 'master'

if ref && branch
warn <<-WARNING
Gem dependencies file #{@path} includes git reference for both ref and branch but only ref is used.
WARNING
end
if (ref||branch) && tag
warn <<-WARNING
Gem dependencies file #{@path} includes git reference for both ref/branch and tag but only ref/branch is used.
WARNING
end

reference
end

private :gem_git

##
@@ -509,23 +480,6 @@ def gem_path name, options # :nodoc:

private :gem_path

##
# Handles the source: option from +options+ for gem +name+.
#
# Returns +true+ if the source option was handled.

def gem_source name, options # :nodoc:
return unless source = options.delete(:source)

pin_gem_source name, :source, source

@source_set.add_source_gem name, source

true
end

private :gem_source

##
# Handles the platforms: option from +options+. Returns true if the
# platform matches the current platform.
@@ -572,7 +526,6 @@ def gem_requires name, options # :nodoc:
else
@requires[name] << name
end
raise ArgumentError, "Unhandled gem options #{options.inspect}" unless options.empty?
end

private :gem_requires
@@ -658,7 +611,6 @@ def gemspec options = {}

add_dependencies groups, spec.development_dependencies

@vendor_set.add_vendor_gem spec.name, path
gem_requires spec.name, options
end

@@ -698,7 +650,6 @@ def pin_gem_source name, type = :default, source = nil
when :default then '(default)'
when :path then "path: #{source}"
when :git then "git: #{source}"
when :source then "source: #{source}"
else '(unknown)'
end

@@ -847,3 +798,4 @@ def source url
Gem::RequestSet::GemDepedencyAPI = self # :nodoc:

end

8 changes: 4 additions & 4 deletions lib/ruby/shared/rubygems/request_set/lockfile.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
##
# Parses a gem.deps.rb.lock file and constructs a LockSet containing the
# dependencies found inside. If the lock file is missing no LockSet is
@@ -130,8 +129,8 @@ def add_GIT out, git_requests
[source.repository, source.rev_parse]
end

out << "GIT"
by_repository_revision.each do |(repository, revision), requests|
out << "GIT"
out << " remote: #{repository}"
out << " revision: #{revision}"
out << " specs:"
@@ -144,8 +143,9 @@ def add_GIT out, git_requests
out << " #{dep.name}#{dep.requirement.for_lockfile}"
end
end
out << nil
end

out << nil
end

def relative_path_from dest, base # :nodoc:
@@ -185,7 +185,7 @@ def add_PLATFORMS out # :nodoc:

platforms = platforms.sort_by { |platform| platform.to_s }

platforms.each do |platform|
platforms.sort.each do |platform|
out << " #{platform}"
end

Loading

0 comments on commit 765042f

Please sign in to comment.