Permalink
Browse files

Merge branch 'master' into deps

  • Loading branch information...
2 parents 4609712 + 068afbc commit cf891dcdbca91abaf3bf6a2156536377dff1be96 @jbarnette jbarnette committed Nov 14, 2010
View
@@ -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 2010. If you '\
+ 'RubyGems. It will be removed completely on or after January 2011. If you '\
'wish to rely on a datadir, please use Gem.datadir.'
View
@@ -111,7 +111,25 @@ class LoadError < ::LoadError
attr_accessor :name
# Version requirement of gem
- attr_accessor :version_requirement
+ attr_accessor :requirement
+
+ def version_requirement
+ warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+ "Gem::LoadError#version_requirement is deprecated " \
+ "and will be removed on or after January 2011. " \
+ "Use #requirement."
+
+ requirement
+ end
+
+ def version_requirement= requirement
+ warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+ "Gem::LoadError#version_requirement= is deprecated " \
+ "and will be removed on or after January 2011. " \
+ "Use #requirement."
+
+ self.requirement = requirement
+ end
end
RbConfigPriorities = %w[
@@ -168,7 +186,7 @@ class LoadError < ::LoadError
##
# Activates an installed gem matching +gem+. The gem must satisfy
- # +version_requirements+.
+ # +requirements+.
#
# Returns true if the gem is activated, false if it is already
# loaded, or an exception otherwise.
@@ -182,22 +200,22 @@ class LoadError < ::LoadError
# More information on version requirements can be found in the
# Gem::Requirement and Gem::Version documentation.
- def self.activate(gem, *version_requirements)
- if version_requirements.last.is_a?(Hash)
- options = version_requirements.pop
+ def self.activate(gem, *requirements)
+ if requirements.last.is_a?(Hash)
+ options = requirements.pop
else
options = {}
end
sources = options[:sources] || []
- if version_requirements.empty? then
- version_requirements = Gem::Requirement.default
+ if requirements.empty? then
+ requirements = Gem::Requirement.default
end
unless gem.respond_to?(:name) and
gem.respond_to?(:requirement) then
- gem = Gem::Dependency.new(gem, version_requirements)
+ gem = Gem::Dependency.new(gem, requirements)
end
matches = Gem.source_index.find_name(gem.name, gem.requirement)
@@ -218,7 +236,7 @@ def self.activate(gem, *version_requirements)
e = Gem::LoadError.new msg
e.name = gem.name
- e.version_requirement = gem.requirement
+ e.requirement = gem.requirement
raise e
end
@@ -302,23 +320,23 @@ def self.available?(gem, *requirements)
##
# Find the full path to the executable for gem +name+. If the +exec_name+
# is not given, the gem's default_executable is chosen, otherwise the
- # specified executable's path is returned. +version_requirements+ allows
+ # specified executable's path is returned. +requirements+ allows
# you to specify specific gem versions.
- def self.bin_path(name, exec_name = nil, *version_requirements)
- version_requirements = Gem::Requirement.default if
- version_requirements.empty?
- specs = Gem.source_index.find_name(name, version_requirements)
+ def self.bin_path(name, exec_name = nil, *requirements)
+ requirements = Gem::Requirement.default if
+ requirements.empty?
+ specs = Gem.source_index.find_name(name, requirements)
raise Gem::GemNotFoundException,
- "can't find gem #{name} (#{version_requirements})" if specs.empty?
+ "can't find gem #{name} (#{requirements})" if specs.empty?
specs = specs.find_all do |spec|
spec.executables.include?(exec_name)
end if exec_name
unless spec = specs.last
- msg = "can't find gem #{name} (#{version_requirements}) with executable #{exec_name}"
+ msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
raise Gem::GemNotFoundException, msg
end
@@ -511,7 +529,8 @@ def self.find_home
File.expand_path "~"
rescue
if File::ALT_SEPARATOR then
- "#{ENV['HOMEDRIVE']}/" # C:/ or /
+ drive = ENV['HOMEDRIVE'] || ENV['SystemDrive']
+ File.join(drive.to_s, '/')
else
"/"
end
@@ -774,7 +793,7 @@ def self.report_activate_error(gem)
end
error.name = gem.name
- error.version_requirement = gem.requirement
+ error.requirement = gem.requirement
raise error
end
@@ -1083,7 +1102,7 @@ module Kernel
##
# Use Kernel#gem to activate a specific version of +gem_name+.
#
- # +version_requirements+ is a list of version requirements that the
+ # +requirements+ is a list of version requirements that the
# specified gem must match, most commonly "= example.version.number". See
# Gem::Requirement for how to specify a version requirement.
#
@@ -1106,10 +1125,10 @@ module Kernel
#
# GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
- def gem(gem_name, *version_requirements) # :doc:
+ def gem(gem_name, *requirements) # :doc:
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
- Gem.activate(gem_name, *version_requirements)
+ Gem.activate(gem_name, *requirements)
end
private :gem
View
@@ -5,6 +5,9 @@
#++
require 'rubygems/user_interaction'
+require "yaml"
+require "rubygems/package"
+require "rubygems/security"
##
# The Builder class processes RubyGem specification files
@@ -20,10 +23,6 @@ class Gem::Builder
# spec:: [Gem::Specification] The specification instance
def initialize(spec)
- require "yaml"
- require "rubygems/package"
- require "rubygems/security"
-
@spec = spec
end
@@ -22,7 +22,6 @@ def initialize
:generate_rdoc => true,
:generate_ri => true,
:format_executable => false,
- :test => false,
:version => Gem::Requirement.default,
})
@@ -41,7 +40,7 @@ def arguments # :nodoc:
def defaults_str # :nodoc:
"--both --version '#{Gem::Requirement.default}' --rdoc --ri --no-force\n" \
- "--no-test --install-dir #{Gem.dir}"
+ "--install-dir #{Gem.dir}"
end
def description # :nodoc:
@@ -156,19 +155,6 @@ def execute
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
end
end
-
- if options[:test] then
- installed_gems.each do |spec|
- gem_spec = Gem::SourceIndex.from_installed_gems.find_name(spec.name, spec.version.version).first
- result = Gem::Validator.new.unit_test(gem_spec)
- if result and not result.passed?
- unless ask_yes_no("...keep Gem?", true)
- require 'rubygems/uninstaller'
- Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
- end
- end
- end
- end
end
raise Gem::SystemExitException, exit_code
@@ -33,50 +33,23 @@ def execute
found = false
options[:args].each do |arg|
- dirs = $LOAD_PATH
- spec = searcher.find arg
-
- if spec then
- if options[:search_gems_first] then
- dirs = gem_paths(spec) + $LOAD_PATH
- else
- dirs = $LOAD_PATH + gem_paths(spec)
- end
- end
+ paths = Gem.find_files(arg, false)
- paths = find_paths arg, dirs
+ if options[:search_gems_first]
+ paths |= Gem.find_files(arg, true)
+ end
if paths.empty? then
alert_error "Can't find ruby library file or shared library #{arg}"
else
- say paths
+ say options[:show_all] ? paths : paths.first
found = true
end
end
terminate_interaction 1 unless found
end
- def find_paths(package_name, dirs)
- result = []
-
- dirs.each do |dir|
- EXT.each do |ext|
- full_path = File.join dir, "#{package_name}#{ext}"
- if File.exist? full_path then
- result << full_path
- return result unless options[:show_all]
- end
- end
- end
-
- result
- end
-
- def gem_paths(spec)
- spec.require_paths.collect { |d| File.join spec.full_gem_path, d }
- end
-
def usage # :nodoc:
"#{program_name} FILE [FILE ...]"
end
@@ -54,7 +54,7 @@ def initialize name, *requirements
unless TYPES.include? type
raise ArgumentError, "Valid types are #{TYPES.inspect}, "
- + "not #{@type.inspect}"
+ + "not #{type.inspect}"
end
@name = name
@@ -228,5 +228,12 @@ def match?(spec_name, spec_version)
requirement.satisfied_by? Gem::Version.new(spec_version)
end
+ def matches_spec?(spec)
+ return false unless name === spec.name # name can be a Regexp, so use ===
+ return true if requirement.none?
+
+ requirement.satisfied_by?(spec.version)
+ end
+
end
@@ -19,7 +19,7 @@ def self.build(extension, directory, dest_path, results)
# Deal with possible spaces in the path, e.g. C:/Program Files
dest_path = '"' + dest_path + '"' if dest_path.include?(' ')
- cmd = ENV['rake'] || "#{Gem.ruby} -rubygems #{Gem.bin_path('rake')}" rescue Gem.default_exec_format % 'rake'
+ cmd = ENV['rake'] || "\"#{Gem.ruby}\" -rubygems #{Gem.bin_path('rake')}" rescue Gem.default_exec_format % 'rake'
cmd += " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen
run cmd, results
@@ -269,8 +269,8 @@ def size
##
# Find a gem by an exact match on the short name.
- def find_name(gem_name, version_requirement = Gem::Requirement.default)
- dep = Gem::Dependency.new gem_name, version_requirement
+ def find_name(gem_name, requirement = Gem::Requirement.default)
+ dep = Gem::Dependency.new gem_name, requirement
search dep
end
@@ -284,7 +284,7 @@ def find_name(gem_name, version_requirement = Gem::Requirement.default)
# behavior is deprecated and will be removed.
def search(gem_pattern, platform_only = false)
- version_requirement = nil
+ requirement = nil
only_platform = false
# TODO - Remove support and warning for legacy arguments after 2008/11
@@ -294,10 +294,10 @@ def search(gem_pattern, platform_only = false)
case gem_pattern
when Regexp then
- version_requirement = platform_only || Gem::Requirement.default
+ requirement = platform_only || Gem::Requirement.default
when Gem::Dependency then
only_platform = platform_only
- version_requirement = gem_pattern.requirement
+ requirement = gem_pattern.requirement
gem_pattern = if Regexp === gem_pattern.name then
gem_pattern.name
elsif gem_pattern.name.empty? then
@@ -306,17 +306,17 @@ def search(gem_pattern, platform_only = false)
/^#{Regexp.escape gem_pattern.name}$/
end
else
- version_requirement = platform_only || Gem::Requirement.default
+ requirement = platform_only || Gem::Requirement.default
gem_pattern = /#{gem_pattern}/i
end
- unless Gem::Requirement === version_requirement then
- version_requirement = Gem::Requirement.create version_requirement
+ unless Gem::Requirement === requirement then
+ requirement = Gem::Requirement.create requirement
end
specs = all_gems.values.select do |spec|
spec.name =~ gem_pattern and
- version_requirement.satisfied_by? spec.version
+ requirement.satisfied_by? spec.version
end
if only_platform then
View
@@ -241,7 +241,7 @@ def marshal_load array
# A version is considered a prerelease if it contains a letter.
def prerelease?
- @prerelease ||= segments.any? { |s| String === s }
+ @prerelease ||= @version =~ /[a-zA-Z]/
end
def pretty_print q # :nodoc:
@@ -301,8 +301,11 @@ def <=> other
rhsize = rhsegments.size
limit = (lhsize > rhsize ? lhsize : rhsize) - 1
- 0.upto(limit) do |i|
+ i = 0
+
+ while i <= limit
lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
+ i += 1
next if lhs == rhs
return -1 if String === lhs && Numeric === rhs
View
@@ -15,6 +15,8 @@
require 'rubygems/test_utilities'
require 'pp'
require 'yaml'
+require 'zlib'
+
begin
YAML::ENGINE.yamler = 'psych'
rescue LoadError
Oops, something went wrong.

0 comments on commit cf891dc

Please sign in to comment.