Skip to content

Commit

Permalink
Merged 1.3.7/ruby-core changes to master
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Jan 15, 2011
1 parent 124dfbc commit 36e6aff
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 109 deletions.
2 changes: 1 addition & 1 deletion lib/rbconfig/datadir.rb
Expand Up @@ -9,5 +9,5 @@
# once.

warn 'rbconfig/datadir.rb and {Rb}Config.datadir is being deprecated from '\
'RubyGems. It will be removed completely on or after January 2011. If you '\
'RubyGems. It will be removed completely on or after June 2011. If you '\
'wish to rely on a datadir, please use Gem.datadir.'
58 changes: 38 additions & 20 deletions lib/rubygems.rb
Expand Up @@ -5,21 +5,18 @@
# See LICENSE.txt for permissions.
#++

gem_preluded = defined? Gem
# TODO: remove when 1.9.1 no longer supported
QUICKLOADER_SUCKAGE = RUBY_VERSION >= "1.9.1" and RUBY_VERSION < "1.9.2"
# TODO: remove when 1.9.2 no longer supported
GEM_PRELUDE_SUCKAGE = RUBY_VERSION >= "1.9.2" and RUBY_VERSION < "1.9.3"

if defined?(Gem::QuickLoader) then
gem_preluded = GEM_PRELUDE_SUCKAGE and defined? Gem

if GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then
Gem::QuickLoader.load_full_rubygems_library

class << Gem
remove_method :try_activate if Gem.respond_to?(:try_activate, true)

def try_activate(path)
spec = Gem.searcher.find(path)
return false unless spec

Gem.activate(spec.name, "= #{spec.version}")
return true
end
end
end

Expand Down Expand Up @@ -201,6 +198,19 @@ def version_requirement= requirement
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []

##
# Try to activate a gem containing +path+. Returns true if
# activation succeeded or wasn't needed because it was already
# activated. Returns false if it can't find the path in a gem.

def self.try_activate path
spec = Gem.searcher.find path
return false unless spec

Gem.activate spec.name, "= #{spec.version}"
return true
end

##
# Activates an installed gem matching +gem+. The gem must satisfy
# +requirements+.
Expand Down Expand Up @@ -644,11 +654,13 @@ def self.latest_partials(gemdir)
def self.load_path_insert_index
index = $LOAD_PATH.index ConfigMap[:sitelibdir]

$LOAD_PATH.each_with_index do |path, i|
if path.instance_variables.include?(:@gem_prelude_index) or
path.instance_variables.include?('@gem_prelude_index') then
index = i
break
if QUICKLOADER_SUCKAGE then
$LOAD_PATH.each_with_index do |path, i|
if path.instance_variables.include?(:@gem_prelude_index) or
path.instance_variables.include?('@gem_prelude_index') then
index = i
break
end
end
end

Expand Down Expand Up @@ -974,7 +986,13 @@ def self.suffix_pattern
# Suffixes for require-able paths.

def self.suffixes
['', '.rb', '.rbw', '.so', '.bundle', '.dll', '.sl', '.jar']
@suffixes ||= ['',
'.rb',
*%w(DLEXT DLEXT2).map { |key|
val = RbConfig::CONFIG[key]
".#{val}" unless val.empty?
}
].compact.uniq
end

##
Expand Down Expand Up @@ -1131,7 +1149,7 @@ class << self

module Kernel

undef gem if respond_to? :gem # defined in gem_prelude.rb on 1.9
remove_method :gem if respond_to? :gem # defined in gem_prelude.rb on 1.9

##
# Use Kernel#gem to activate a specific version of +gem_name+.
Expand Down Expand Up @@ -1176,14 +1194,14 @@ def gem(gem_name, *requirements) # :doc:
# "#{ConfigMap[:datadir]}/#{package_name}".

def RbConfig.datadir(package_name)
require 'rbconfig/datadir' # TODO Deprecate after January 2010.
require 'rbconfig/datadir' # TODO Deprecate after June 2010.
Gem.datadir(package_name) ||
File.join(Gem::ConfigMap[:datadir], package_name)
end

require 'rubygems/exceptions'

unless gem_preluded then
unless gem_preluded then # TODO: remove guard after 1.9.2 dropped
begin
##
# Defaults the operating system (or packager) wants to provide for RubyGems.
Expand All @@ -1209,7 +1227,7 @@ def RbConfig.datadir(package_name)
# Ruby 1.9 allows --disable-gems, so we require it when we didn't detect a Gem
# constant at rubygems.rb load time.

require 'rubygems/custom_require' unless gem_preluded and RUBY_VERSION > '1.9'
require 'rubygems/custom_require' unless RUBY_VERSION > '1.9'

Gem.clear_paths

38 changes: 22 additions & 16 deletions lib/rubygems/config_file.rb
Expand Up @@ -47,23 +47,29 @@ class Gem::ConfigFile

system_config_path =
begin
require 'Win32API'

CSIDL_COMMON_APPDATA = 0x0023
path = 0.chr * 260
if RUBY_VERSION > '1.9' then
SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'PLPLP',
'L', :stdcall
SHGetFolderPath.call nil, CSIDL_COMMON_APPDATA, nil, 1, path
else
SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP',
'L'
SHGetFolderPath.call 0, CSIDL_COMMON_APPDATA, 0, 1, path
require "etc"
Etc.sysconfdir
rescue LoadError, NoMethodError
begin
# TODO: remove after we drop 1.8.7 and 1.9.1
require 'Win32API'

CSIDL_COMMON_APPDATA = 0x0023
path = 0.chr * 260
if RUBY_VERSION > '1.9' then
SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'PLPLP',
'L', :stdcall
SHGetFolderPath.call nil, CSIDL_COMMON_APPDATA, nil, 1, path
else
SHGetFolderPath = Win32API.new 'shell32', 'SHGetFolderPath', 'LLLLP',
'L'
SHGetFolderPath.call 0, CSIDL_COMMON_APPDATA, 0, 1, path
end

path.strip
rescue LoadError
"/etc"
end

path.strip
rescue LoadError
'/etc'
end

SYSTEM_WIDE_CONFIG_FILE = File.join system_config_path, 'gemrc'
Expand Down
10 changes: 4 additions & 6 deletions lib/rubygems/custom_require.rb
Expand Up @@ -28,13 +28,11 @@ module Kernel
def require(path) # :doc:
gem_original_require path
rescue LoadError => load_error
if load_error.message =~ /#{Regexp.escape path}\z/ and
spec = Gem.searcher.find(path) then
Gem.activate(spec.name, "= #{spec.version}")
gem_original_require path
else
raise load_error
if load_error.message.end_with?(path) and Gem.try_activate(path) then
return gem_original_require(path)
end

raise load_error
end

private :require
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/installer.rb
Expand Up @@ -38,7 +38,7 @@ class ExtensionBuildError < Gem::InstallError; end

include Gem::UserInteraction

include Gem::RequirePathsBuilder
include Gem::RequirePathsBuilder if QUICKLOADER_SUCKAGE

##
# The directory a gem's executables will be installed into
Expand Down Expand Up @@ -198,7 +198,7 @@ def install
build_extensions
write_spec

write_require_paths_file_if_needed
write_require_paths_file_if_needed if QUICKLOADER_SUCKAGE

# HACK remove? Isn't this done in multiple places?
cached_gem = File.join @gem_home, "cache", @gem.split(/\//).pop
Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/require_paths_builder.rb
@@ -1,5 +1,6 @@
require 'rubygems'

# TODO: remove after 1.9.1 dropped
module Gem::RequirePathsBuilder
def write_require_paths_file_if_needed(spec = @spec, gem_home = @gem_home)
return if spec.require_paths == ["lib"] &&
Expand All @@ -13,5 +14,5 @@ def write_require_paths_file_if_needed(spec = @spec, gem_home = @gem_home)
file.puts spec.bindir if spec.bindir
end
end
end
end if QUICKLOADER_SUCKAGE

27 changes: 7 additions & 20 deletions lib/rubygems/test_utilities.rb
Expand Up @@ -131,30 +131,17 @@ def self.fetcher=(fetcher)
#--
# This class was added to flush out problems in Rubinius' IO implementation.

class TempIO

@@count = 0

class TempIO < Tempfile
def initialize(string = '')
@tempfile = Tempfile.new "TempIO-#{@@count += 1}"
@tempfile.binmode
@tempfile.write string
@tempfile.rewind
end

def method_missing(meth, *args, &block)
@tempfile.send(meth, *args, &block)
end

def respond_to?(meth)
@tempfile.respond_to? meth
super "TempIO"
binmode
write string
rewind
end

def string
@tempfile.flush

Gem.read_binary @tempfile.path
flush
Gem.read_binary path
end

end

84 changes: 51 additions & 33 deletions lib/rubygems/user_interaction.rb
Expand Up @@ -218,48 +218,66 @@ def ask(question)
result
end

##
# Ask for a password. Does not echo response to terminal.
if RUBY_VERSION >= "1.9" then
##
# Ask for a password. Does not echo response to terminal.

def ask_for_password(question)
return nil if not @ins.tty?
def ask_for_password(question)
return nil if not @ins.tty?

@outs.print(question + " ")
@outs.flush
require 'io/console'

Gem.win_platform? ? ask_for_password_on_windows : ask_for_password_on_unix
end
@outs.print(question + " ")
@outs.flush

##
# Asks for a password that works on windows. Ripped from the Heroku gem.
password = @ins.noecho {@ins.gets}
password.chomp! if password
password
end
else
##
# Ask for a password. Does not echo response to terminal.

def ask_for_password_on_windows
require "Win32API"
char = nil
password = ''
def ask_for_password(question)
return nil if not @ins.tty?

while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
break if char == 10 || char == 13 # received carriage return or newline
if char == 127 || char == 8 # backspace and delete
password.slice!(-1, 1)
else
password << char.chr
end
@outs.print(question + " ")
@outs.flush

Gem.win_platform? ? ask_for_password_on_windows : ask_for_password_on_unix
end

puts
password
end
##
# Asks for a password that works on windows. Ripped from the Heroku gem.

def ask_for_password_on_windows
require "Win32API"
char = nil
password = ''

while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
break if char == 10 || char == 13 # received carriage return or newline
if char == 127 || char == 8 # backspace and delete
password.slice!(-1, 1)
else
password << char.chr
end
end

##
# Asks for a password that works on unix

def ask_for_password_on_unix
system "stty -echo"
password = @ins.gets
password.chomp! if password
system "stty echo"
password
puts
password
end

##
# Asks for a password that works on unix

def ask_for_password_on_unix
system "stty -echo"
password = @ins.gets
password.chomp! if password
system "stty echo"
password
end
end

##
Expand Down
4 changes: 2 additions & 2 deletions test/gemutilities.rb
Expand Up @@ -502,15 +502,15 @@ def vc_windows?
# other platforms, including Cygwin, it will return 'make'.
#
def self.make_command
vc_windows? ? 'nmake' : 'make'
ENV["make"] || (vc_windows? ? 'nmake' : 'make')
end

# Returns the make command for the current platform. For versions of Ruby
# built on MS Windows with VC++ or Borland it will return 'nmake'. On all
# other platforms, including Cygwin, it will return 'make'.
#
def make_command
vc_windows? ? 'nmake' : 'make'
ENV["make"] || (vc_windows? ? 'nmake' : 'make')
end

# Returns whether or not the nmake command could be found.
Expand Down
3 changes: 3 additions & 0 deletions test/mockgemui.rb
Expand Up @@ -13,6 +13,9 @@ def tty?()
@tty
end

def noecho
yield self
end
end

def initialize(input = "")
Expand Down
1 change: 1 addition & 0 deletions test/test_gem.rb
Expand Up @@ -301,6 +301,7 @@ def test_self_find_files
]

assert_equal expected, Gem.find_files('sff/discover')
assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]'
ensure
assert_equal cwd, $LOAD_PATH.shift
end
Expand Down

0 comments on commit 36e6aff

Please sign in to comment.