[前][次][番号順一覧][スレッド一覧]

ruby-changes:30072

From: drbrain <ko1@a...>
Date: Tue, 23 Jul 2013 07:47:06 +0900 (JST)
Subject: [ruby-changes:30072] drbrain:r42124 (trunk): * lib/rubygems: Import RubyGems from master as of commit b165260

drbrain	2013-07-23 07:46:50 +0900 (Tue, 23 Jul 2013)

  New Revision: 42124

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42124

  Log:
    * lib/rubygems:  Import RubyGems from master as of commit b165260
    * test/rubygems:  ditto.

  Added files:
    trunk/test/rubygems/test_gem_commands_search_command.rb
    trunk/test/rubygems/test_gem_ext_builder.rb
  Modified files:
    trunk/ChangeLog
    trunk/lib/rubygems/command_manager.rb
    trunk/lib/rubygems/commands/cert_command.rb
    trunk/lib/rubygems/commands/contents_command.rb
    trunk/lib/rubygems/commands/dependency_command.rb
    trunk/lib/rubygems/commands/environment_command.rb
    trunk/lib/rubygems/commands/help_command.rb
    trunk/lib/rubygems/commands/install_command.rb
    trunk/lib/rubygems/commands/query_command.rb
    trunk/lib/rubygems/commands/search_command.rb
    trunk/lib/rubygems/commands/sources_command.rb
    trunk/lib/rubygems/commands/uninstall_command.rb
    trunk/lib/rubygems/commands/update_command.rb
    trunk/lib/rubygems/exceptions.rb
    trunk/lib/rubygems/ext/builder.rb
    trunk/lib/rubygems/ext/ext_conf_builder.rb
    trunk/lib/rubygems/path_support.rb
    trunk/lib/rubygems/remote_fetcher.rb
    trunk/lib/rubygems/request.rb
    trunk/lib/rubygems/spec_fetcher.rb
    trunk/lib/rubygems/specification.rb
    trunk/lib/rubygems/stub_specification.rb
    trunk/lib/rubygems.rb
    trunk/test/rubygems/test_gem.rb
    trunk/test/rubygems/test_gem_command_manager.rb
    trunk/test/rubygems/test_gem_commands_contents_command.rb
    trunk/test/rubygems/test_gem_commands_help_command.rb
    trunk/test/rubygems/test_gem_commands_pristine_command.rb
    trunk/test/rubygems/test_gem_commands_query_command.rb
    trunk/test/rubygems/test_gem_commands_uninstall_command.rb
    trunk/test/rubygems/test_gem_ext_ext_conf_builder.rb
    trunk/test/rubygems/test_gem_remote_fetcher.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42123)
+++ ChangeLog	(revision 42124)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jul 23 07:44:59 2013  Eric Hodel  <drbrain@s...>
+
+	* lib/rubygems:  Import RubyGems from master as of commit b165260
+	* test/rubygems:  ditto.
+
 Tue Jul 23 07:14:31 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (bary_mulsub_1xN): New function.
Index: lib/rubygems/path_support.rb
===================================================================
--- lib/rubygems/path_support.rb	(revision 42123)
+++ lib/rubygems/path_support.rb	(revision 42124)
@@ -36,6 +36,8 @@ class Gem::PathSupport https://github.com/ruby/ruby/blob/trunk/lib/rubygems/path_support.rb#L36
     @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
Index: lib/rubygems/spec_fetcher.rb
===================================================================
--- lib/rubygems/spec_fetcher.rb	(revision 42123)
+++ lib/rubygems/spec_fetcher.rb	(revision 42124)
@@ -74,6 +74,12 @@ class Gem::SpecFetcher https://github.com/ruby/ruby/blob/trunk/lib/rubygems/spec_fetcher.rb#L74
 
     list, errors = available_specs(type)
     list.each do |source, specs|
+      if dependency.name.is_a?(String) && specs.respond_to?(:bsearch)
+        start_index = (0 ... specs.length).bsearch{ |i| specs[i].name >= dependency.name }
+        end_index   = (0 ... specs.length).bsearch{ |i| specs[i].name > dependency.name }
+        specs = specs[start_index ... end_index] if start_index && end_index
+      end
+
       found[source] = specs.select do |tup|
         if dependency.match?(tup)
           if matching_platform and !Gem::Platform.match(tup.platform)
@@ -214,15 +220,15 @@ class Gem::SpecFetcher https://github.com/ruby/ruby/blob/trunk/lib/rubygems/spec_fetcher.rb#L220
   def tuples_for(source, type, gracefully_ignore=false)
     cache = @caches[type]
 
-    if gracefully_ignore
+    tuples =
       begin
         cache[source.uri] ||= source.load_specs(type)
       rescue Gem::RemoteFetcher::FetchError
+        raise unless gracefully_ignore
         []
       end
-    else
-      cache[source.uri] ||= source.load_specs(type)
-    end
+
+    tuples.sort_by { |tup| tup.name }
   end
 
 end
Index: lib/rubygems/ext/builder.rb
===================================================================
--- lib/rubygems/ext/builder.rb	(revision 42123)
+++ lib/rubygems/ext/builder.rb	(revision 42124)
@@ -23,11 +23,13 @@ class Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/builder.rb#L23
       make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
     end
 
+    destdir = '"DESTDIR=%s"' % ENV['DESTDIR'] if RUBY_VERSION > '2.0'
+
     ['', 'install'].each do |target|
       # Pass DESTDIR via command line to override what's in MAKEFLAGS
       cmd = [
         make_program,
-        '"DESTDIR=%s"' % ENV['DESTDIR'],
+        destdir,
         target
       ].join(' ').rstrip
       run(cmd, results, "make #{target}".rstrip)
Index: lib/rubygems/ext/ext_conf_builder.rb
===================================================================
--- lib/rubygems/ext/ext_conf_builder.rb	(revision 42123)
+++ lib/rubygems/ext/ext_conf_builder.rb	(revision 42124)
@@ -39,6 +39,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ex https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L39
         run cmd, results
 
         ENV["DESTDIR"] = nil
+        ENV["RUBYOPT"] = rubyopt
         siteconf.unlink
 
         make dest_path, results
@@ -49,14 +50,14 @@ class Gem::Ext::ExtConfBuilder < Gem::Ex https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L50
             destent.exist? or File.rename(ent.path, destent.path)
           end
         end
-
-        results
       ensure
         ENV["RUBYOPT"] = rubyopt
         ENV["DESTDIR"] = destdir
       end
     end
-    t.unlink if t
+    t.unlink if t and t.path
+
+    results
   ensure
     FileUtils.rm_rf tmp_dest if tmp_dest
   end
Index: lib/rubygems/specification.rb
===================================================================
--- lib/rubygems/specification.rb	(revision 42123)
+++ lib/rubygems/specification.rb	(revision 42124)
@@ -954,7 +954,7 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L954
     result.map(&:last).map(&:values).flatten.reject { |spec|
       minimum = native[spec.name]
       minimum && spec.version < minimum
-    }
+    }.sort_by{ |tup| tup.name }
   end
 
   ##
@@ -1853,11 +1853,6 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1853
     end
   end
 
-  # Prevent ruby hitting spec.method_missing when [[spec]].flatten is called
-  def to_ary # :nodoc:
-    nil
-  end
-
   ##
   # Normalize the list of files so that:
   # * All file lists have redundancies removed.
@@ -2008,6 +2003,10 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2003
     @requirements = Array req
   end
 
+  def respond_to_missing? m, include_private = false # :nodoc:
+    false
+  end
+
   ##
   # Returns the full path to this spec's ri directory.
 
Index: lib/rubygems/exceptions.rb
===================================================================
--- lib/rubygems/exceptions.rb	(revision 42123)
+++ lib/rubygems/exceptions.rb	(revision 42124)
@@ -7,7 +7,13 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/exceptions.rb#L7
 # Base exception class for RubyGems.  All exception raised by RubyGems are a
 # subclass of this one.
 class Gem::Exception < RuntimeError
-  attr_accessor :source_exception
+
+  ##
+  #--
+  # TODO: remove in RubyGems 3, nobody sets this
+
+  attr_accessor :source_exception # :nodoc:
+
 end
 
 class Gem::CommandLineError < Gem::Exception; end
Index: lib/rubygems/commands/update_command.rb
===================================================================
--- lib/rubygems/commands/update_command.rb	(revision 42123)
+++ lib/rubygems/commands/update_command.rb	(revision 42124)
@@ -56,23 +56,33 @@ class Gem::Commands::UpdateCommand < Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L56
     "#{program_name} GEMNAME [GEMNAME ...]"
   end
 
+  def check_latest_rubygems version # :nodoc:
+    if Gem.rubygems_version == version then
+      say "Latest version currently installed. Aborting."
+      terminate_interaction
+    end
+
+    options[:user_install] = false
+  end
+
+  def check_update_arguments # :nodoc:
+    unless options[:args].empty? then
+      alert_error "Gem names are not allowed with the --system option"
+      terminate_interaction 1
+    end
+  end
+
   def execute
     hig = {}
 
     if options[:system] then
       update_rubygems
       return
-    else
-      say "Updating installed gems"
+    end
 
-      hig = {} # highest installed gems
+    say "Updating installed gems"
 
-      Gem::Specification.each do |spec|
-        if hig[spec.name].nil? or hig[spec.name].version < spec.version then
-          hig[spec.name] = spec
-        end
-      end
-    end
+    hig = highest_installed_gems
 
     gems_to_update = which_to_update hig, options[:args].uniq
 
@@ -85,51 +95,65 @@ class Gem::Commands::UpdateCommand < Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L95
     end
   end
 
-  def update_gem name, version = Gem::Requirement.default
-    return if @updated.any? { |spec| spec.name == name }
+  def fetch_remote_gems spec # :nodoc:
+    dependency = Gem::Dependency.new spec.name, "> #{spec.version}"
+    dependency.prerelease = options[:prerelease]
 
-    @installer ||= Gem::DependencyInstaller.new options
+    fetcher = Gem::SpecFetcher.fetcher
 
-    success = false
+    spec_tuples, _ = fetcher.search_for_dependency dependency
 
-    say "Updating #{name}"
-    begin
-      @installer.install name, Gem::Requirement.new(version)
-      success = true
-    rescue Gem::InstallError => e
-      alert_error "Error installing #{name}:\n\t#{e.message}"
-      success = false
-    end
+    spec_tuples
+  end
 
-    @installer.installed_gems.each do |spec|
-      @updated << spec
+  def highest_installed_gems # :nodoc:
+    hig = {} # highest installed gems
+
+    Gem::Specification.each do |spec|
+      if hig[spec.name].nil? or hig[spec.name].version < spec.version then
+        hig[spec.name] = spec
+      end
     end
+
+    hig
   end
 
-  def update_gems gems_to_update
-    gems_to_update.uniq.sort.each do |(name, version)|
-      update_gem name, version
+  def highest_remote_version spec # :nodoc:
+    spec_tuples = fetch_remote_gems spec
+
+    matching_gems = spec_tuples.select do |g,_|
+      g.name == spec.name and g.match_platform?
     end
 
-    @updated
+    highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
+
+    highest_remote_gem ||= [Gem::NameTuple.null]
+
+    highest_remote_gem.first.version
   end
 
-  ##
-  # Update RubyGems software to the latest version.
+  def install_rubygems version # :nodoc:
+    args = update_rubygems_arguments
 
-  def update_rubygems
-    unless options[:args].empty? then
-      alert_error "Gem names are not allowed with the --system option"
-      terminate_interaction 1
-    end
+    update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
 
-    options[:user_install] = false
+    Dir.chdir update_dir do
+      say "Installing RubyGems #{version}"
 
-    # TODO: rename version and other variable name conflicts
-    # TODO: get rid of all this indirection on name and other BS
+      # Make sure old rubygems isn't loaded
+      old = ENV["RUBYOPT"]
+      ENV.delete("RUBYOPT") if old
+      installed = system Gem.ruby, 'setup.rb', *args
+      say "RubyGems system software updated" if installed
+      ENV["RUBYOPT"] = old if old
+    end
+  end
 
+  def rubygems_target_version
     version = options[:system]
-    if version == true then
+    update_latest = version == true
+
+    if update_latest then
       version     = Gem::Version.new     Gem::VERSION
       requirement = Gem::Requirement.new ">= #{Gem::VERSION}"
     else
@@ -146,46 +170,72 @@ class Gem::Commands::UpdateCommand < Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L170
     }
 
     gems_to_update = which_to_update hig, options[:args], :system
-    name, up_ver   = gems_to_update.first
-    current_ver    = Gem.rubygems_version
+    _, up_ver   = gems_to_update.first
 
-    target = if options[:system] == true then
+    target = if update_latest then
                up_ver
              else
                version
              end
 
-    if current_ver == target then
-      # if options[:system] != true and version == current_ver then
-      say "Latest version currently installed. Aborting."
-      terminate_interaction
+    return target, requirement
+  end
+
+  def update_gem name, version = Gem::Requirement.default
+    return if @updated.any? { |spec| spec.name == name }
+
+    @installer ||= Gem::DependencyInstaller.new options
+
+    success = false
+
+    say "Updating #{name}"
+    begin
+      @installer.install name, Gem::Requirement.new(version)
+      success = true
+    rescue Gem::InstallError => e
+      alert_error "Error installing #{name}:\n\t#{e.message}"
+      success = false
     end
 
-    update_gem name, target
+    @installer.installed_gems.each do |spec|
+      @updated << spec
+    end
+  end
+
+  def update_gems gems_to_update
+    gems_to_update.uniq.sort.each do |(name, version)|
+      update_gem name, version
+    end
+
+    @updated
+  end
+
+  ##
+  # Update RubyGems software to the latest version.
+
+  def update_rubygems
+    check_update_arguments
+
+    version, requirement = rubygems_target_version
+
+    check_latest_rubygems version
+
+    update_gem 'rubygems-update', version
 
     installed_gems = Gem::Specification.find_all_by_name 'rubygems-update', requirement
     version        = installed_gems.last.version
 
+    install_rubygems version
+  end
+
+  def update_rubygems_arguments # :nodoc:
     args = []
     args << '--prefix' << Gem.prefix if Gem.prefix
     # TODO use --document for >= 1.9 , --no-rdoc --no-ri < 1.9
     args << '--no-rdoc' unless options[:document].include? 'rdoc'
     args << '--no-ri'   unless options[:document].include? 'ri'
     args << '--no-format-executable' if options[:no_format_executable]
-
-    update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
-
-    Dir.chdir update_dir do
-      say "Installing RubyGems #{version}"
-      setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
-
-      # Make sure old rubygems isn't loaded
-      old = ENV["RUBYOPT"]
-      ENV.delete("RUBYOPT") if old
-      installed = system setup_cmd
-      say "RubyGems system software updated" if installed
-      ENV["RUBYOPT"] = old if old
-    end
+    args
   end
 
   def which_to_update highest_installed_gems, gem_names, system = false
@@ -195,21 +245,7 @@ class Gem::Commands::UpdateCommand < Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/update_command.rb#L245
       next if not gem_names.empty? and
               gem_names.all? { |name| /#{name}/ !~ l_spec.name }
 
-      dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
-      dependency.prerelease = options[:prerelease]
-
-      fetcher = Gem::SpecFetcher.fetcher
-
-      spec_tuples, _ = fetcher.search_for_dependency dependency
-
-      matching_gems = spec_tuples.select do |g,_|
-        g.name == l_name and g.match_platform?
-      end
-
-      highest_remote_gem = matching_gems.sort_by { |g,_| g.version }.last
-
-      highest_remote_gem ||= [Gem::NameTuple.null]
-      highest_remote_ver = highest_remote_gem.first.version
+      highest_remote_ver = highest_remote_version l_spec
 
       if system or (l_spec.version < highest_remote_ver) then
         result << [l_spec.name, [l_spec.version, highest_remote_ver].max]
Index: lib/rubygems/commands/sources_command.rb
===================================================================
--- lib/rubygems/commands/sources_command.rb	(revision 42123)
+++ lib/rubygems/commands/sources_command.rb	(revision 42124)
@@ -37,103 +37,118 @@ class Gem::Commands::SourcesCommand < Ge https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/sources_command.rb#L37
     add_proxy_option
   end
 
-  def defaults_str
-    '--list'
-  end
+  def add_source source_uri # :nodoc:
+    check_rubygems_https source_uri
 
-  def execute
-    options[:list] = !(options[:add] ||
-                       options[:clear_all] ||
-                       options[:remove] ||
-                       options[:update])
-
-    if options[:clear_all] then
-      path = Gem.spec_cache_dir
-      FileUtils.rm_rf path
+    source = Gem::Source.new source_uri
 
-      unless File.exist? path then
-        say "*** Removed specs cache ***"
+    begin
+      if Gem.sources.include? source_uri then
+        say "source #{source_uri} already present in the cache"
       else
-        unless File.writable? path then
-          say "*** Unable to remove source cache (write protected) ***"
-        else
-          say "*** Unable to remove source cache ***"
-        end
+        source.load_specs :released
+        Gem.sources << source
+        Gem.configuration.write
 
-        terminate_interaction 1
+        say "#{source_uri} added to sources"
       end
+    rescue URI::Error, ArgumentError
+      say "#{source_uri} is not a URI"
+      terminate_interaction 1
+    rescue Gem::RemoteFetcher::FetchError => e
+      say "Error fetching #{source_uri}:\n\t#{e.message}"
+      terminate_interaction 1
     end
+  end
 
-    if source_uri = options[:add] then
-      uri = URI source_uri
+  def check_rubygems_https source_uri # :nodoc:
+    uri = URI source_uri
 
-      if uri.scheme and uri.scheme.downcase == 'http' and
-         uri.host.downcase == 'rubygems.org' then
-        question = <<-QUESTION.chomp
+    if uri.scheme and uri.scheme.downcase == 'http' and
+       uri.host.downcase == 'rubygems.org' then
+      question = <<-QUESTION.chomp
 https://rubygems.org is recommended for security over #{uri}
 
 Do you want to add this insecure source?
-        QUESTION
+      QUESTION
 
-        terminate_interaction 1 unless ask_yes_no question
-      end
+      terminate_interaction 1 unless ask_yes_no question
+    end
+  end
 
-      source = Gem::Source.new source_uri
+  def clear_all # :nodoc:
+    path = Gem.spec_cache_dir
+    FileUtils.rm_rf path
 
-      begin
-        if Gem.sources.include? source_uri then
-          say "source #{source_uri} already present in the cache"
-        else
-          source.load_specs :released
-          Gem.sources << source
-          Gem.configuration.write
-
-          say "#{source_uri} added to sources"
-        end
-      rescue URI::Error, ArgumentError
-        say "#{source_uri} is not a URI"
-        terminate_interaction 1
-      rescue Gem::RemoteFetcher::FetchError => e
-        say "Error fetching #{source_uri}:\n\t#{e.message}"
-        terminate_interaction 1
+    unless File.exist? path then
+      say "*** Removed specs cache ***"
+    else
+      unless File.writable? path then
+        say "*** Unable to remove source cache (write protected) ***"
+      else
+        say "*** Unable to remove source cache ***"
       end
+
+      terminate_interaction 1
     end
+  end
 
-    if options[:remove] then
-      source_uri = options[:remove]
+  def defaults_str # :nodoc:
+    '--list'
+  end
 
-      unless Gem.sources.include? source_uri then
-        say "source #{source_uri} not present in cache"
-      else
-        Gem.sources.delete source_uri
-        Gem.configuration.write
+  def list # :nodoc:
+    say "*** CURRENT SOURCES ***"
+    say
 
-        say "#{source_uri} removed from sources"
-      end
+    Gem.sources.each do |src|
+      say src
     end
+  end
 
-    if options[:update] then
-      Gem.sources.each_source do |src|
-        src.load_specs :released
-        src.load_specs :latest
-      end
+  def list? # :nodoc:
+    !(options[:list] ||
+      options[:add] ||
+      options[:clear_all] ||
+      options[:remove] ||
+      options[:update])
+  end
 
-      say "source cache successfully updated"
-    end
+  def execute
+    clear_all if options[:clear_all]
 
-    if options[:list] then
-      say "*** CURRENT SOURCES ***"
-      say
+    source_uri = options[:add]
+    add_source source_uri if source_uri
 
-      Gem.sources.each do |src|
-        say src
-      end
+    source_uri = options[:remove]
+    remove_source source_uri if source_uri
+
+    update if options[:update]
+
+    list if list?
+  end
+
+  def remove_source source_uri # :nodoc:
+    unless Gem.sources.include? source_uri then
+      say "source #{source_uri} not present in cache"
+    else
+      Gem.sources.delete source_uri
+      Gem.configuration.write
+
+      say "#{source_uri} removed from sources"
     end
   end
 
-  private
+  def update # :nodoc:
+    Gem.sources.each_source do |src|
+      src.load_specs :released
+      src.load_specs :latest
+    end
+
+    say "source cache successfully updated"
+  end
 
-  def remove_cache_file(desc, path)
+  def remove_cache_file desc, path # :nodoc:
     FileUtils.rm_rf path
 
     if not File.exist?(path) then
Index: lib/rubygems/commands/help_command.rb
===================================================================
--- lib/rubygems/commands/help_command.rb	(revision 42123)
+++ lib/rubygems/commands/help_command.rb	(revision 42124)
@@ -94,6 +94,8 @@ platform. https://github.com/ruby/ruby/blob/trunk/lib/rubygems/commands/help_command.rb#L94
 
   def initialize (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]