diff options
Diffstat (limited to 'lib/rubygems/source')
-rw-r--r-- | lib/rubygems/source/git.rb | 34 | ||||
-rw-r--r-- | lib/rubygems/source/installed.rb | 3 | ||||
-rw-r--r-- | lib/rubygems/source/local.rb | 3 | ||||
-rw-r--r-- | lib/rubygems/source/lock.rb | 44 | ||||
-rw-r--r-- | lib/rubygems/source/vendor.rb | 2 |
5 files changed, 79 insertions, 7 deletions
diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb index 2794735c96..e8b03165c1 100644 --- a/lib/rubygems/source/git.rb +++ b/lib/rubygems/source/git.rb @@ -31,6 +31,11 @@ class Gem::Source::Git < Gem::Source 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 @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 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 # 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 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 diff --git a/lib/rubygems/source/installed.rb b/lib/rubygems/source/installed.rb index 2661dd6844..6d343c2439 100644 --- a/lib/rubygems/source/installed.rb +++ b/lib/rubygems/source/installed.rb @@ -12,7 +12,8 @@ class Gem::Source::Installed < Gem::Source def <=> other case other - when Gem::Source::Vendor then + when Gem::Source::Lock, + Gem::Source::Vendor then -1 when Gem::Source::Installed then 0 diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb index 3aae20c8ed..8057921163 100644 --- a/lib/rubygems/source/local.rb +++ b/lib/rubygems/source/local.rb @@ -15,7 +15,8 @@ class Gem::Source::Local < Gem::Source def <=> other case other - when Gem::Source::Installed then + when Gem::Source::Installed, + Gem::Source::Lock then -1 when Gem::Source::Local then 0 diff --git a/lib/rubygems/source/lock.rb b/lib/rubygems/source/lock.rb new file mode 100644 index 0000000000..d8a46d8d10 --- /dev/null +++ b/lib/rubygems/source/lock.rb @@ -0,0 +1,44 @@ +## +# 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 + diff --git a/lib/rubygems/source/vendor.rb b/lib/rubygems/source/vendor.rb index 244c4201d8..2d936231c1 100644 --- a/lib/rubygems/source/vendor.rb +++ b/lib/rubygems/source/vendor.rb @@ -12,6 +12,8 @@ class Gem::Source::Vendor < Gem::Source::Installed def <=> other case other + when Gem::Source::Lock then + -1 when Gem::Source::Vendor then 0 when Gem::Source then |