Skip to content

Commit

Permalink
Update to RubyGems 1.8.21.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius authored and enebo committed Apr 19, 2012
1 parent 3e82bc8 commit 904fd37
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 56 deletions.
56 changes: 39 additions & 17 deletions lib/ruby/site_ruby/1.8/rubygems.rb
Expand Up @@ -7,7 +7,9 @@

module Gem
QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/
GEM_PRELUDE_SUCKAGE = false

# Only MRI 1.9.2 has the custom prelude.
GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/ && RUBY_ENGINE == "ruby"
end

if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then
Expand Down Expand Up @@ -118,7 +120,7 @@ class << Gem
# -The RubyGems Team

module Gem
VERSION = '1.8.15'
VERSION = '1.8.21'

##
# Raised when RubyGems is unable to load or activate a gem. Contains the
Expand Down Expand Up @@ -256,7 +258,7 @@ def self.all_load_paths

Gem.path.each do |gemdir|
each_load_path all_partials(gemdir) do |load_path|
result << gemdir.add(load_path).expand_path
result << load_path
end
end

Expand Down Expand Up @@ -442,10 +444,10 @@ def self.each_load_path(partials)
# problem, then we will silently continue.

def self.ensure_gem_subdirectories dir = Gem.dir
require 'fileutils'

old_umask = File.umask
File.umask old_umask | 022
File.umask old_umask | 002

require 'fileutils'

%w[cache doc gems specifications].each do |name|
subdir = File.join dir, name
Expand Down Expand Up @@ -647,19 +649,39 @@ def self.load_path_insert_index
def self.load_yaml
return if @yaml_loaded

begin
gem 'psych', '~> 1.2', '>= 1.2.1' unless ENV['TEST_SYCK']
rescue Gem::LoadError
# It's OK if the user does not have the psych gem installed. We will
# attempt to require the stdlib version
test_syck = ENV['TEST_SYCK']

unless test_syck
begin
gem 'psych', '~> 1.2', '>= 1.2.1'
rescue Gem::LoadError
# It's OK if the user does not have the psych gem installed. We will
# attempt to require the stdlib version
end

begin
# Try requiring the gem version *or* stdlib version of psych.
require 'psych'
rescue ::LoadError
# If we can't load psych, thats fine, go on.
else
# If 'yaml' has already been required, then we have to
# be sure to switch it over to the newly loaded psych.
if defined?(YAML::ENGINE) && YAML::ENGINE.yamler != "psych"
YAML::ENGINE.yamler = "psych"
end

require 'rubygems/psych_additions'
require 'rubygems/psych_tree'
end
end

begin
# Try requiring the gem version *or* stdlib version of psych.
require 'psych' unless ENV['TEST_SYCK']
rescue ::LoadError
ensure
require 'yaml'
require 'yaml'

# If we're supposed to be using syck, then we may have to force
# activate it via the YAML::ENGINE API.
if test_syck and defined?(YAML::ENGINE)
YAML::ENGINE.yamler = "syck" unless YAML::ENGINE.syck?
end

# Now that we're sure some kind of yaml library is loaded, pull
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/builder.rb
Expand Up @@ -32,9 +32,9 @@ def initialize(spec)
# Builds the gem from the specification. Returns the name of the file
# written.

def build
def build(skip_validation=false)
@spec.mark_version
@spec.validate
@spec.validate unless skip_validation
@signer = sign
write_package
say success if Gem.configuration.verbose
Expand Down
8 changes: 6 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/commands/build_command.rb
Expand Up @@ -4,7 +4,11 @@
class Gem::Commands::BuildCommand < Gem::Command

def initialize
super('build', 'Build a gem from a gemspec')
super 'build', 'Build a gem from a gemspec'

add_option '--force', 'skip validation of the spec' do |value, options|
options[:force] = true
end
end

def arguments # :nodoc:
Expand All @@ -22,7 +26,7 @@ def execute
spec = load_gemspec gemspec

if spec then
Gem::Builder.new(spec).build
Gem::Builder.new(spec).build options[:force]
else
alert_error "Error loading gemspec. Aborting."
terminate_interaction 1
Expand Down
12 changes: 10 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/commands/fetch_command.rb
Expand Up @@ -58,8 +58,16 @@ def execute
next
end

path = Gem::RemoteFetcher.fetcher.download spec, source_uri
FileUtils.mv path, File.basename(spec.cache_file)
file = "#{spec.full_name}.gem"
remote_path = URI.parse(source_uri) + "gems/#{file}"

fetch = Gem::RemoteFetcher.fetcher

gem = fetch.fetch_path remote_path.to_s

File.open file, "wb" do |f|
f.write gem
end

say "Downloaded #{spec.full_name}"
end
Expand Down
6 changes: 4 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/commands/pristine_command.rb
Expand Up @@ -94,12 +94,14 @@ def execute
end

# TODO use installer options
# Modified for JRUBY-5031, to propagate --env-shebang if set
install_defaults = Gem::ConfigFile::PLATFORM_DEFAULTS['install']
installer_env_shebang = install_defaults.to_s['--env-shebang']

installer = Gem::Installer.new(gem,
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
:env_shebang => !Gem::ConfigFile::PLATFORM_DEFAULTS['install'].to_s['--env-shebang'].nil?)
:env_shebang => installer_env_shebang)
installer.install

say "Restored #{spec.full_name}"
Expand Down
26 changes: 24 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/commands/specification_command.rb
Expand Up @@ -62,7 +62,25 @@ def execute
"Please specify a gem name or file on the command line"
end

dep = Gem::Dependency.new gem, options[:version]
case options[:version]
when String
req = Gem::Requirement.parse options[:version]
when Gem::Requirement
req = options[:version]
else
raise Gem::CommandLineError, "Unsupported version type: #{options[:version]}"
end

if !req.none? and options[:all]
alert_error "Specify --all or -v, not both"
terminate_interaction 1
end

if options[:all]
dep = Gem::Dependency.new gem
else
dep = Gem::Dependency.new gem, options[:version]
end

field = get_one_optional_argument

Expand All @@ -80,7 +98,11 @@ def execute
end

if remote? then
found = Gem::SpecFetcher.fetcher.fetch dep
found = Gem::SpecFetcher.fetcher.fetch dep, true

if dep.prerelease? or options[:prerelease]
found += Gem::SpecFetcher.fetcher.fetch dep, false, true, true
end

specs.push(*found.map { |spec,| spec })
end
Expand Down
4 changes: 3 additions & 1 deletion lib/ruby/site_ruby/1.8/rubygems/config_file.rb
Expand Up @@ -25,6 +25,8 @@
# +:sources+:: Sets Gem::sources
# +:verbose+:: See #verbose

require 'rbconfig'

class Gem::ConfigFile

DEFAULT_BACKTRACE = false
Expand Down Expand Up @@ -68,7 +70,7 @@ class Gem::ConfigFile

path.strip
rescue LoadError
"/etc"
RbConfig::CONFIG["sysconfdir"] || "/etc"
end
end

Expand Down
3 changes: 2 additions & 1 deletion lib/ruby/site_ruby/1.8/rubygems/custom_require.rb
Expand Up @@ -55,7 +55,8 @@ def require path
return gem_original_require path
end
rescue LoadError => load_error
if load_error.message.end_with?(path) and Gem.try_activate(path) then
if load_error.message.start_with?("Could not find") or
(load_error.message.end_with?(path) and Gem.try_activate(path)) then
return gem_original_require(path)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/site_ruby/1.8/rubygems/installer.rb
Expand Up @@ -366,7 +366,7 @@ def shebang(bin_file_name)

if /\A#!/ =~ first_line then
# Preserve extra words on shebang line, like "-w". Thanks RPA.
shebang = first_line.sub(/\A\#!.*?ruby\S*(?=(\s+\S+))/, "#!#{Gem.ruby}")
shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}")
opts = $1
shebang.strip! # Avoid nasty ^M issues.
end
Expand Down
1 change: 1 addition & 0 deletions lib/ruby/site_ruby/1.8/rubygems/platform.rb
Expand Up @@ -68,6 +68,7 @@ def initialize(arch)
when /aix(\d+)/ then [ 'aix', $1 ]
when /cygwin/ then [ 'cygwin', nil ]
when /darwin(\d+)?/ then [ 'darwin', $1 ]
when /^macruby$/ then [ 'macruby', nil ]
when /freebsd(\d+)/ then [ 'freebsd', $1 ]
when /hpux(\d+)/ then [ 'hpux', $1 ]
when /^java$/, /^jruby$/ then [ 'java', nil ]
Expand Down
9 changes: 9 additions & 0 deletions lib/ruby/site_ruby/1.8/rubygems/psych_additions.rb
@@ -0,0 +1,9 @@
# This exists just to satify 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
# blows up.

module Psych
class PrivateType
end
end
27 changes: 27 additions & 0 deletions lib/ruby/site_ruby/1.8/rubygems/psych_tree.rb
@@ -0,0 +1,27 @@
module Gem
if defined? ::Psych::Visitors
class NoAliasYAMLTree < Psych::Visitors::YAMLTree
def visit_String(str)
return super unless str == '=' # or whatever you want

quote = Psych::Nodes::Scalar::SINGLE_QUOTED
@emitter.scalar str, nil, nil, false, true, quote
end

# Noop this out so there are no anchors
def register(target, obj)
end

# This is ported over from the yaml_tree in 1.9.3
def format_time time
if time.utc?
time.strftime("%Y-%m-%d %H:%M:%S.%9N Z")
else
time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
end
end

private :format_time
end
end
end
8 changes: 6 additions & 2 deletions lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb
Expand Up @@ -261,8 +261,12 @@ def load_specs(source_uri, file)
loaded = false

if File.exist? local_file then
spec_dump =
@fetcher.fetch_path(spec_path, File.mtime(local_file)) rescue nil
begin
spec_dump =
@fetcher.fetch_path(spec_path, File.mtime(local_file))
rescue Gem::RemoteFetcher::FetchError => e
alert_warning "Error fetching data: #{e.message}"
end

loaded = true if spec_dump

Expand Down
43 changes: 35 additions & 8 deletions lib/ruby/site_ruby/1.8/rubygems/specification.rb
Expand Up @@ -262,18 +262,19 @@ class Gem::Specification

def self._all # :nodoc:
unless defined?(@@all) && @@all then
specs = []
specs = {}

self.dirs.reverse_each { |dir|
self.dirs.each { |dir|
Dir[File.join(dir, "*.gemspec")].each { |path|
spec = Gem::Specification.load path.untaint
# #load returns nil if the spec is bad, so we just ignore
# it at this stage
specs << spec if spec
specs[spec.full_name] ||= spec if spec
}
}

@@all = specs
@@all = specs.values

_resort!
end
@@all
Expand Down Expand Up @@ -537,7 +538,7 @@ def self.load file
file = file.dup.untaint

code = if defined? Encoding
File.read file, :encoding => "UTF-8"
File.read file, :mode => 'r:UTF-8:-'
else
File.read file
end
Expand Down Expand Up @@ -665,11 +666,16 @@ def self._load(str)
raise TypeError, "invalid Gem::Specification format #{array.inspect}"
end

# Cleanup any YAML::PrivateType. They only show up for an old bug
# where nil => null, so just convert them to nil based on the type.

array.map! { |e| e.kind_of?(YAML::PrivateType) ? nil : e }

spec.instance_variable_set :@rubygems_version, array[0]
# spec version
spec.instance_variable_set :@name, array[2]
spec.instance_variable_set :@version, array[3]
spec.instance_variable_set :@date, array[4]
spec.date = array[4]
spec.instance_variable_set :@summary, array[5]
spec.instance_variable_set :@required_ruby_version, array[6]
spec.instance_variable_set :@required_rubygems_version, array[7]
Expand Down Expand Up @@ -1922,7 +1928,22 @@ def to_s # :nodoc:

def to_yaml(opts = {}) # :nodoc:
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck? then
super.gsub(/ !!null \n/, " \n")
# Because the user can switch the YAML engine behind our
# back, we have to check again here to make sure that our
# psych code was properly loaded, and load it if not.
unless Gem.const_defined?(:NoAliasYAMLTree)
require 'rubygems/psych_tree'
end

builder = Gem::NoAliasYAMLTree.new({})
builder << self
ast = builder.tree

io = StringIO.new

Psych::Visitors::Emitter.new(io).accept(ast)

io.string.gsub(/ !!null \n/, " \n")
else
YAML.quick_emit object_id, opts do |out|
out.map taguri, to_yaml_style do |map|
Expand Down Expand Up @@ -2107,7 +2128,13 @@ def version= version
# FIX: have this handle the platform/new_platform/original_platform bullshit
def yaml_initialize(tag, vals) # :nodoc:
vals.each do |ivar, val|
instance_variable_set "@#{ivar}", val
case ivar
when "date"
# Force Date to go through the extra coerce logic in date=
self.date = val.untaint
else
instance_variable_set "@#{ivar}", val.untaint
end
end

@original_platform = @platform # for backwards compatibility
Expand Down

0 comments on commit 904fd37

Please sign in to comment.