ruby-changes:31860
From: drbrain <ko1@a...>
Date: Sun, 1 Dec 2013 08:28:06 +0900 (JST)
Subject: [ruby-changes:31860] drbrain:r43939 (trunk): * lib/rubygems: Update to RubyGems master 66e5c39. Notable changes:
drbrain 2013-12-01 08:27:52 +0900 (Sun, 01 Dec 2013) New Revision: 43939 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43939 Log: * lib/rubygems: Update to RubyGems master 66e5c39. Notable changes: Implement gem.deps.rb (Gemfile) .lock support Fixed `gem uninstall` for a relative directory in GEM_HOME. * test/rubygems: ditto. Added files: trunk/lib/rubygems/source/lock.rb trunk/test/rubygems/test_gem_source_lock.rb Modified files: trunk/ChangeLog trunk/lib/rubygems/basic_specification.rb trunk/lib/rubygems/ext/builder.rb trunk/lib/rubygems/ext/rake_builder.rb trunk/lib/rubygems/rdoc.rb trunk/lib/rubygems/request_set/lockfile.rb trunk/lib/rubygems/request_set.rb trunk/lib/rubygems/resolver/best_set.rb trunk/lib/rubygems/resolver/git_set.rb trunk/lib/rubygems/resolver/index_set.rb trunk/lib/rubygems/resolver/lock_set.rb trunk/lib/rubygems/resolver/vendor_set.rb trunk/lib/rubygems/source/git.rb trunk/lib/rubygems/source/installed.rb trunk/lib/rubygems/source/local.rb trunk/lib/rubygems/source/vendor.rb trunk/lib/rubygems/source.rb trunk/lib/rubygems/specification.rb trunk/lib/rubygems/test_utilities.rb trunk/lib/rubygems/validator.rb trunk/lib/rubygems.rb trunk/test/rubygems/test_gem_request_set.rb trunk/test/rubygems/test_gem_request_set_lockfile.rb trunk/test/rubygems/test_gem_resolver_git_set.rb trunk/test/rubygems/test_gem_resolver_git_specification.rb trunk/test/rubygems/test_gem_resolver_lock_set.rb trunk/test/rubygems/test_gem_source_git.rb trunk/test/rubygems/test_gem_specification.rb trunk/test/rubygems/test_gem_validator.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 43938) +++ ChangeLog (revision 43939) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Dec 1 08:27:28 2013 Eric Hodel <drbrain@s...> + + * lib/rubygems: Update to RubyGems master 66e5c39. Notable changes: + + Implement gem.deps.rb (Gemfile) .lock support + + Fixed `gem uninstall` for a relative directory in GEM_HOME. + + * test/rubygems: ditto. + Sun Dec 1 06:00:49 2013 Aman Gupta <ruby@t...> * test/ruby/test_gc.rb (test_gc_reason): Force minor GC by consuming Index: lib/rubygems/basic_specification.rb =================================================================== --- lib/rubygems/basic_specification.rb (revision 43938) +++ lib/rubygems/basic_specification.rb (revision 43939) @@ -5,6 +5,16 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/basic_specification.rb#L5 class Gem::BasicSpecification ## + # Allows installation of extensions for git: gems. + + attr_writer :base_dir # :nodoc: + + ## + # Sets the directory where extensions for this gem will be installed. + + attr_writer :extension_install_dir # :nodoc: + + ## # The path this gemspec was loaded from. This attribute is not persisted. attr_reader :loaded_from @@ -68,8 +78,9 @@ class Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/basic_specification.rb#L78 # end def extension_install_dir - File.join base_dir, 'extensions', Gem::Platform.local.to_s, - Gem.extension_api_version, full_name + @extension_install_dir ||= + File.join base_dir, 'extensions', Gem::Platform.local.to_s, + Gem.extension_api_version, full_name end def find_full_gem_path # :nodoc: @@ -141,9 +152,10 @@ class Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/basic_specification.rb#L152 def loaded_from= path @loaded_from = path && path.to_s - @full_gem_path = nil - @gems_dir = nil - @base_dir = nil + @extension_install_dir = nil + @full_gem_path = nil + @gems_dir = nil + @base_dir = nil end ## Index: lib/rubygems/validator.rb =================================================================== --- lib/rubygems/validator.rb (revision 43938) +++ lib/rubygems/validator.rb (revision 43939) @@ -86,6 +86,7 @@ class Gem::Validator https://github.com/ruby/ruby/blob/trunk/lib/rubygems/validator.rb#L86 Gem::Specification.each do |spec| next unless gems.include? spec.name unless gems.empty? + next if spec.default_gem? gem_name = spec.file_name gem_path = spec.cache_file Index: lib/rubygems/rdoc.rb =================================================================== --- lib/rubygems/rdoc.rb (revision 43938) +++ lib/rubygems/rdoc.rb (revision 43939) @@ -8,7 +8,7 @@ rescue Gem::LoadError https://github.com/ruby/ruby/blob/trunk/lib/rubygems/rdoc.rb#L8 # swallow else # This will force any deps that 'rdoc' might have - # (such as json) that are ambigious to be activated, which + # (such as json) that are ambiguous to be activated, which # is important because we end up using Specification.reset # and we don't want the warning it pops out. Gem.finish_resolve Index: lib/rubygems/ext/builder.rb =================================================================== --- lib/rubygems/ext/builder.rb (revision 43938) +++ lib/rubygems/ext/builder.rb (revision 43939) @@ -98,7 +98,7 @@ class Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/builder.rb#L98 def initialize spec, build_args = spec.build_args @spec = spec @build_args = build_args - @gem_dir = spec.gem_dir + @gem_dir = spec.full_gem_path @ran_rake = nil end Index: lib/rubygems/ext/rake_builder.rb =================================================================== --- lib/rubygems/ext/rake_builder.rb (revision 43938) +++ lib/rubygems/ext/rake_builder.rb (revision 43939) @@ -19,7 +19,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext:: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/rake_builder.rb#L19 rake = ENV['rake'] rake ||= begin - "\"#{Gem.ruby}\" -rubygems #{Gem.bin_path('rake', 'rake')}" + "#{Gem.ruby} -rubygems #{Gem.bin_path('rake', 'rake')}" rescue Gem::Exception end Index: lib/rubygems/request_set.rb =================================================================== --- lib/rubygems/request_set.rb (revision 43938) +++ lib/rubygems/request_set.rb (revision 43939) @@ -67,6 +67,7 @@ class Gem::RequestSet https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set.rb#L67 @dependency_names = {} @development = false @git_set = nil + @install_dir = Gem.dir @requests = [] @sets = [] @soft_missing = false @@ -143,7 +144,11 @@ class Gem::RequestSet https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set.rb#L144 # dependencies file are not used. See Gem::Installer for other +options+. def install_from_gemdeps options, &block - load_gemdeps options[:gemdeps], options[:without_groups] + gemdeps = options[:gemdeps] + + @install_dir = options[:install_dir] || Gem.dir + + load_gemdeps gemdeps, options[:without_groups] resolve @@ -154,7 +159,12 @@ class Gem::RequestSet https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set.rb#L159 puts " #{s}" end else - install options, &block + installed = install options, &block + + lockfile = Gem::RequestSet::Lockfile.new self, gemdeps + lockfile.write + + installed end end @@ -194,6 +204,11 @@ class Gem::RequestSet https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set.rb#L204 @git_set = Gem::Resolver::GitSet.new @vendor_set = Gem::Resolver::VendorSet.new + @git_set.root_dir = @install_dir + + lockfile = Gem::RequestSet::Lockfile.new self, path + lockfile.parse + gf = Gem::RequestSet::GemDependencyAPI.new self, path gf.without_groups = without_groups if without_groups gf.load @@ -264,3 +279,4 @@ class Gem::RequestSet https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set.rb#L279 end require 'rubygems/request_set/gem_dependency_api' +require 'rubygems/request_set/lockfile' Index: lib/rubygems/specification.rb =================================================================== --- lib/rubygems/specification.rb (revision 43938) +++ lib/rubygems/specification.rb (revision 43939) @@ -1031,7 +1031,7 @@ class Gem::Specification < Gem::BasicSpe https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1031 spec = eval code, binding, file if Gem::Specification === spec - spec.loaded_from = file.to_s + spec.loaded_from = File.expand_path file.to_s LOAD_CACHE[file] = spec return spec end Index: lib/rubygems/source/vendor.rb =================================================================== --- lib/rubygems/source/vendor.rb (revision 43938) +++ lib/rubygems/source/vendor.rb (revision 43939) @@ -12,6 +12,8 @@ class Gem::Source::Vendor < Gem::Source: https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/vendor.rb#L12 def <=> other case other + when Gem::Source::Lock then + -1 when Gem::Source::Vendor then 0 when Gem::Source then Index: lib/rubygems/source/installed.rb =================================================================== --- lib/rubygems/source/installed.rb (revision 43938) +++ lib/rubygems/source/installed.rb (revision 43939) @@ -12,7 +12,8 @@ class Gem::Source::Installed < Gem::Sour https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/installed.rb#L12 def <=> other case other - when Gem::Source::Vendor then + when Gem::Source::Lock, + Gem::Source::Vendor then -1 when Gem::Source::Installed then 0 Index: lib/rubygems/source/git.rb =================================================================== --- lib/rubygems/source/git.rb (revision 43938) +++ lib/rubygems/source/git.rb (revision 43939) @@ -31,6 +31,11 @@ class Gem::Source::Git < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/git.rb#L31 attr_reader :repository ## + # The directory for cache and git gem installation + + attr_accessor :root_dir + + ## # Does this repository need submodules checked out too? attr_reader :need_submodules @@ -50,14 +55,16 @@ class Gem::Source::Git < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/git.rb#L55 @reference = reference @need_submodules = submodules - @git = ENV['git'] || 'git' + @root_dir = Gem.dir + @git = ENV['git'] || 'git' end def <=> other case other when Gem::Source::Git then 0 - when Gem::Source::Installed then + when Gem::Source::Installed, + Gem::Source::Lock then -1 when Gem::Source then 1 @@ -114,6 +121,13 @@ class Gem::Source::Git < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/git.rb#L121 end ## + # Directory where git gems get unpacked and so-forth. + + def base_dir # :nodoc: + File.join @root_dir, 'bundler' + end + + ## # A short reference for use in git gem directories def dir_shortref # :nodoc: @@ -130,14 +144,14 @@ class Gem::Source::Git < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/git.rb#L144 # The directory where the git gem will be installed. def install_dir # :nodoc: - File.join Gem.dir, 'bundler', 'gems', "#{@name}-#{dir_shortref}" + File.join base_dir, 'gems', "#{@name}-#{dir_shortref}" end ## # The directory where the git gem's repository will be cached. def repo_cache_dir # :nodoc: - File.join Gem.dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}" + File.join @root_dir, 'cache', 'bundler', 'git', "#{@name}-#{uri_hash}" end ## @@ -162,7 +176,17 @@ class Gem::Source::Git < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/git.rb#L176 Dir.chdir directory do spec = Gem::Specification.load file - spec.full_gem_path = File.expand_path '.' if spec + if spec then + loaded_from = File.expand_path file + spec.loaded_from = loaded_from + spec.base_dir = base_dir + + spec.extension_install_dir = + File.join base_dir, 'extensions', Gem::Platform.local.to_s, + Gem.extension_api_version, "#{name}-#{dir_shortref}" + + spec.full_gem_path = File.dirname loaded_from if spec + end spec end end.compact Index: lib/rubygems/source/lock.rb =================================================================== --- lib/rubygems/source/lock.rb (revision 0) +++ lib/rubygems/source/lock.rb (revision 43939) @@ -0,0 +1,44 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/lock.rb#L1 +## +# A Lock source wraps an installed gem's source and sorts before other sources +# during dependency resolution. This allows RubyGems to prefer gems from +# dependency lock files. + +class Gem::Source::Lock < Gem::Source + + ## + # The wrapped Gem::Source + + attr_reader :wrapped + + ## + # Creates a new Lock source that wraps +source+ and moves it earlier in the + # sort list. + + def initialize source + @wrapped = source + end + + def <=> other # :nodoc: + case other + when Gem::Source::Lock then + @wrapped <=> other.wrapped + when Gem::Source then + 1 + else + nil + end + end + + def == other # :nodoc: + 0 == (self <=> other) + end + + ## + # Delegates to the wrapped source's fetch_spec method. + + def fetch_spec name_tuple + @wrapped.fetch_spec name_tuple + end + +end + Property changes on: lib/rubygems/source/lock.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: lib/rubygems/source/local.rb =================================================================== --- lib/rubygems/source/local.rb (revision 43938) +++ lib/rubygems/source/local.rb (revision 43939) @@ -15,7 +15,8 @@ class Gem::Source::Local < Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/local.rb#L15 def <=> other case other - when Gem::Source::Installed then + when Gem::Source::Installed, + Gem::Source::Lock then -1 when Gem::Source::Local then 0 Index: lib/rubygems/source.rb =================================================================== --- lib/rubygems/source.rb (revision 43938) +++ lib/rubygems/source.rb (revision 43939) @@ -49,6 +49,7 @@ class Gem::Source https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source.rb#L49 case other when Gem::Source::Installed, Gem::Source::Local, + Gem::Source::Lock, Gem::Source::SpecificFile, Gem::Source::Git, Gem::Source::Vendor then @@ -213,5 +214,6 @@ require 'rubygems/source/git' https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source.rb#L214 require 'rubygems/source/installed' require 'rubygems/source/specific_file' require 'rubygems/source/local' +require 'rubygems/source/lock' require 'rubygems/source/vendor' Index: lib/rubygems/request_set/lockfile.rb =================================================================== --- lib/rubygems/request_set/lockfile.rb (revision 43938) +++ lib/rubygems/request_set/lockfile.rb (revision 43939) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L1 +## +# 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 +# constructed. + class Gem::RequestSet::Lockfile ## @@ -100,7 +105,7 @@ class Gem::RequestSet::Lockfile https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L105 out << nil end - def relative_path_from(dest, base) + def relative_path_from dest, base # :nodoc: dest = File.expand_path(dest) base = File.expand_path(base) @@ -263,6 +268,9 @@ class Gem::RequestSet::Lockfile https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L268 get while not @tokens.empty? and peek.first == type end + ## + # The contents of the lock file. + def to_s @set.resolve @@ -293,6 +301,10 @@ class Gem::RequestSet::Lockfile https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L301 [byte_offset - @line_pos, @line] end + ## + # Converts a lock file into an Array of tokens. If the lock file is missing + # an empty Array is returned. + def tokenize # :nodoc: @line = 0 @line_pos = 0 @@ -343,6 +355,8 @@ class Gem::RequestSet::Lockfile https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L355 end @tokens + rescue Errno::ENOENT + @tokens end ## @@ -352,5 +366,14 @@ class Gem::RequestSet::Lockfile https://github.com/ruby/ruby/blob/trunk/lib/rubygems/request_set/lockfile.rb#L366 @tokens.unshift @current_token end + ## + # Writes the lock file alongside the gem dependencies file + + def write + open "#{@gem_deps_file}.lock", 'w' do |io| + io.write to_s + end + end + end Index: lib/rubygems/resolver/index_set.rb =================================================================== --- lib/rubygems/resolver/index_set.rb (revision 43938) +++ lib/rubygems/resolver/index_set.rb (revision 43939) @@ -46,5 +46,29 @@ class Gem::Resolver::IndexSet < Gem::Res https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/index_set.rb#L46 res end + def pretty_print q # :nodoc: + q.group 2, '[IndexSet', ']' do + q.breakable + q.text 'sources:' + q.breakable + q.pp @f.sources + + q.breakable + q.text 'specs:' + + q.breakable + + names = @all.values.map do |tuples| + tuples.map do |_, tuple| + tuple.full_name + end + end.flatten + + q.seplist names do |name| + q.text name + end + end + end + end Index: lib/rubygems/resolver/git_set.rb =================================================================== --- lib/rubygems/resolver/git_set.rb (revision 43938) +++ lib/rubygems/resolver/git_set.rb (revision 43939) @@ -11,6 +11,12 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/git_set.rb#L11 class Gem::Resolver::GitSet < Gem::Resolver::Set ## + # The root directory for git gems in this set. This is usually Gem.dir, the + # installation directory for regular gems. + + attr_accessor :root_dir + + ## # Contains repositories needing submodules attr_reader :need_submodules # :nodoc: @@ -30,6 +36,7 @@ class Gem::Resolver::GitSet < Gem::Resol https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/git_set.rb#L36 @git = ENV['git'] || 'git' @need_submodules = {} @repositories = {} + @root_dir = Gem.dir @specs = {} end @@ -57,6 +64,7 @@ class Gem::Resolver::GitSet < Gem::Resol https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/git_set.rb#L64 @repositories.each do |name, (repository, reference)| source = Gem::Source::Git.new name, repository, reference + source.root_dir = @root_dir source.specs.each do |spec| git_spec = Gem::Resolver::GitSpecification.new self, spec, source @@ -65,6 +73,21 @@ class Gem::Resolver::GitSet < Gem::Resol https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/git_set.rb#L73 end end end + + def pretty_print q # :nodoc: + q.group 2, '[GitSet', ']' do + next if @repositories.empty? + q.breakable + + repos = @repositories.map do |name, (repository, reference)| + "#{name}: #{repository}@#{reference}" + end + + q.seplist repos do |repo| + q.text repo + end + end + end end Index: lib/rubygems/resolver/lock_set.rb =================================================================== --- lib/rubygems/resolver/lock_set.rb (revision 43938) +++ lib/rubygems/resolver/lock_set.rb (revision 43939) @@ -9,7 +9,7 @@ class Gem::Resolver::LockSet < Gem::Reso https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/lock_set.rb#L9 # Creates a new LockSet from the given +source+ def initialize source - @source = source + @source = Gem::Source::Lock.new source @specs = [] end @@ -56,5 +56,21 @@ class Gem::Resolver::LockSet < Gem::Reso https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/lock_set.rb#L56 found.source.fetch_spec tuple end + def pretty_print q # :nodoc: + q.group 2, '[LockSet', ']' do + q.breakable + q.text 'source:' + + q.breakable + q.pp @source + + q.breakable + q.text 'specs:' + + q.breakable + q.pp @specs.map { |spec| spec.full_name } + end + end + end Index: lib/rubygems/resolver/best_set.rb =================================================================== --- lib/rubygems/resolver/best_set.rb (revision 43938) +++ lib/rubygems/resolver/best_set.rb (revision 43939) @@ -17,5 +17,15 @@ class Gem::Resolver::BestSet < Gem::Reso https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/best_set.rb#L17 end end + def pretty_print q # :nodoc: + q.group 2, '[BestSet', ']' do + q.breakable + q.text 'sets:' + + q.breakable + q.pp @sets + end + end + end Index: lib/rubygems/resolver/vendor_set.rb =================================================================== --- lib/rubygems/resolver/vendor_set.rb (revision 43938) +++ lib/rubygems/resolv (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/