aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/source
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-19 00:34:13 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-11-19 00:34:13 +0000
commita7fa4d5d9aab150ad4b0c3f3217fe444df69f527 (patch)
tree88ab96d22f7228b556337aa7c34042d4fd279394 /lib/rubygems/source
parente7ec3dad907f2c77f17faddb40a98b2ef4523222 (diff)
downloadruby-a7fa4d5d9aab150ad4b0c3f3217fe444df69f527.tar.gz
* lib/rubygems: Update to RubyGems master 6a3d9f9. Changes include:
Compatibly renamed Gem::DependencyResolver to Gem::Resolver. Added support for git gems in gem.deps.rb and Gemfile. Fixed resolver bugs. * test/rubygems: ditto. * lib/rubygems/LICENSE.txt: Updated to license from RubyGems trunk. [ruby-trunk - Bug #9086] * lib/rubygems/commands/which_command.rb: RubyGems now indicates failure when any file is missing. [ruby-trunk - Bug #9004] * lib/rubygems/ext/builder: Extensions are now installed into the extension install directory and the first directory in the require path from the gem. This allows backwards compatibility with msgpack and other gems that calculate full require paths. [ruby-trunk - Bug #9106] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43714 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/source')
-rw-r--r--lib/rubygems/source/git.rb189
-rw-r--r--lib/rubygems/source/installed.rb7
-rw-r--r--lib/rubygems/source/local.rb17
-rw-r--r--lib/rubygems/source/specific_file.rb17
-rw-r--r--lib/rubygems/source/vendor.rb18
5 files changed, 236 insertions, 12 deletions
diff --git a/lib/rubygems/source/git.rb b/lib/rubygems/source/git.rb
new file mode 100644
index 0000000000..8453aa5fd7
--- /dev/null
+++ b/lib/rubygems/source/git.rb
@@ -0,0 +1,189 @@
+require 'digest'
+require 'rubygems/util'
+
+##
+# A git gem for use in a gem dependencies file.
+#
+# Example:
+#
+# source =
+# Gem::Source::Git.new 'rake', 'git@example:rake.git', 'rake-10.1.0', false
+#
+# spec = source.load_spec 'rake'
+#
+# source.checkout
+
+class Gem::Source::Git < Gem::Source
+
+ ##
+ # The name of the gem created by this git gem.
+
+ attr_reader :name
+
+ ##
+ # The commit reference used for checking out this git gem.
+
+ attr_reader :reference
+
+ ##
+ # The git repository this gem is sourced from.
+
+ attr_reader :repository
+
+ ##
+ # Does this repository need submodules checked out too?
+
+ attr_reader :need_submodules
+
+ ##
+ # Creates a new git gem source for a gem with the given +name+ that will be
+ # loaded from +reference+ in +repository+. If +submodules+ is true,
+ # submodules will be checked out when the gem is installed.
+
+ def initialize name, repository, reference, submodules = false
+ super(nil)
+
+ @name = name
+ @repository = repository
+ @reference = reference
+ @need_submodules = submodules
+
+ @git = ENV['git'] || 'git'
+ end
+
+ def <=> other
+ case other
+ when Gem::Source::Git then
+ 0
+ when Gem::Source::Installed then
+ -1
+ when Gem::Source then
+ 1
+ else
+ nil
+ end
+ end
+
+ def == other # :nodoc:
+ super and
+ @name == other.name and
+ @repository == other.repository and
+ @reference == other.reference and
+ @need_submodules == other.need_submodules
+ end
+
+ ##
+ # Checks out the files for the repository into the install_dir.
+
+ def checkout # :nodoc:
+ cache
+
+ unless File.exist? install_dir then
+ system @git, 'clone', '--quiet', '--no-checkout',
+ repo_cache_dir, install_dir
+ end
+
+ Dir.chdir install_dir do
+ system @git, 'fetch', '--quiet', '--force', '--tags', install_dir
+
+ success = system @git, 'reset', '--quiet', '--hard', @reference
+
+ success &&=
+ system @git, 'submodule', 'update',
+ '--quiet', '--init', '--recursive' if @need_submodules
+
+ success
+ end
+ end
+
+ ##
+ # Creates a local cache repository for the git gem.
+
+ def cache # :nodoc:
+ if File.exist? repo_cache_dir then
+ Dir.chdir repo_cache_dir do
+ system @git, 'fetch', '--quiet', '--force', '--tags',
+ @repository, 'refs/heads/*:refs/heads/*'
+ end
+ else
+ system @git, 'clone', '--quiet', '--bare', '--no-hardlinks',
+ @repository, repo_cache_dir
+ end
+ end
+
+ ##
+ # A short reference for use in git gem directories
+
+ def dir_shortref # :nodoc:
+ rev_parse[0..11]
+ end
+
+ ##
+ # The directory where the git gem will be installed.
+
+ def install_dir # :nodoc:
+ File.join Gem.dir, 'bundler', 'gems', "#{@name}-#{dir_shortref}"
+ end
+
+ ##
+ # Loads a Gem::Specification for +name+ from this git repository.
+
+ def load_spec name
+ cache
+
+ gemspec_reference = "#{@reference}:#{name}.gemspec"
+
+ Dir.chdir repo_cache_dir do
+ source = Gem::Util.popen @git, 'show', gemspec_reference
+
+ source.force_encoding Encoding::UTF_8 if Object.const_defined? :Encoding
+ source.untaint
+
+ begin
+ spec = eval source, binding, gemspec_reference
+
+ return spec if Gem::Specification === spec
+
+ warn "git gem specification for #{@repository} #{gemspec_reference} is not a Gem::Specification (#{spec.class} instead)."
+ rescue SignalException, SystemExit
+ raise
+ rescue SyntaxError, Exception
+ warn "invalid git gem specification for #{@repository} #{gemspec_reference}"
+ end
+ end
+ 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}"
+ end
+
+ ##
+ # Converts the git reference for the repository into a commit hash.
+
+ def rev_parse # :nodoc:
+ # HACK no safe equivalent of ` exists on 1.8.7
+ Dir.chdir repo_cache_dir do
+ Gem::Util.popen(@git, 'rev-parse', @reference).strip
+ end
+ end
+
+ ##
+ # A hash for the git gem based on the git repository URI.
+
+ def uri_hash # :nodoc:
+ normalized =
+ if @repository =~ %r%^\w+://(\w+@)?% then
+ uri = URI(@repository).normalize.to_s.sub %r%/$%,''
+ uri.sub(/\A(\w+)/) { $1.downcase }
+ else
+ @repository
+ end
+
+ Digest::SHA1.hexdigest normalized
+ end
+
+end
+
diff --git a/lib/rubygems/source/installed.rb b/lib/rubygems/source/installed.rb
index 8e3a3560bf..2661dd6844 100644
--- a/lib/rubygems/source/installed.rb
+++ b/lib/rubygems/source/installed.rb
@@ -1,6 +1,9 @@
+##
+# Represents an installed gem. This is used for dependency resolution.
+
class Gem::Source::Installed < Gem::Source
- def initialize
+ def initialize # :nodoc:
@uri = nil
end
@@ -9,6 +12,8 @@ class Gem::Source::Installed < Gem::Source
def <=> other
case other
+ when Gem::Source::Vendor then
+ -1
when Gem::Source::Installed then
0
when Gem::Source then
diff --git a/lib/rubygems/source/local.rb b/lib/rubygems/source/local.rb
index 16a028b2f3..3aae20c8ed 100644
--- a/lib/rubygems/source/local.rb
+++ b/lib/rubygems/source/local.rb
@@ -1,5 +1,10 @@
+##
+# The local source finds gems in the current directory for fulfilling
+# dependencies.
+
class Gem::Source::Local < Gem::Source
- def initialize
+
+ def initialize # :nodoc:
@specs = nil
@api_uri = nil
@uri = nil
@@ -26,7 +31,7 @@ class Gem::Source::Local < Gem::Source
"#<%s specs: %p>" % [self.class, keys]
end
- def load_specs(type)
+ def load_specs type # :nodoc:
names = []
@specs = {}
@@ -68,8 +73,8 @@ class Gem::Source::Local < Gem::Source
names
end
- def find_gem(gem_name, version=Gem::Requirement.default,
- prerelease=false)
+ def find_gem gem_name, version = Gem::Requirement.default, # :nodoc:
+ prerelease = false
load_specs :complete
found = []
@@ -91,7 +96,7 @@ class Gem::Source::Local < Gem::Source
found.max_by { |s| s.version }
end
- def fetch_spec(name)
+ def fetch_spec name # :nodoc:
load_specs :complete
if data = @specs[name]
@@ -101,7 +106,7 @@ class Gem::Source::Local < Gem::Source
end
end
- def download(spec, cache_dir=nil)
+ def download spec, cache_dir = nil # :nodoc:
load_specs :complete
@specs.each do |name, data|
diff --git a/lib/rubygems/source/specific_file.rb b/lib/rubygems/source/specific_file.rb
index 8d328b38c2..a7b6c53542 100644
--- a/lib/rubygems/source/specific_file.rb
+++ b/lib/rubygems/source/specific_file.rb
@@ -1,4 +1,12 @@
+##
+# A source representing a single .gem file. This is used for installation of
+# local gems.
+
class Gem::Source::SpecificFile < Gem::Source
+
+ ##
+ # Creates a new SpecificFile for the gem in +file+
+
def initialize(file)
@uri = nil
@path = ::File.expand_path(file)
@@ -8,19 +16,22 @@ class Gem::Source::SpecificFile < Gem::Source
@name = @spec.name_tuple
end
+ ##
+ # The Gem::Specification extracted from this .gem.
+
attr_reader :spec
- def load_specs(*a)
+ def load_specs *a # :nodoc:
[@name]
end
- def fetch_spec(name)
+ def fetch_spec name # :nodoc:
return @spec if name == @name
raise Gem::Exception, "Unable to find '#{name}'"
@spec
end
- def download(spec, dir=nil)
+ def download spec, dir = nil # :nodoc:
return @path if spec == @spec
raise Gem::Exception, "Unable to download '#{spec.full_name}'"
end
diff --git a/lib/rubygems/source/vendor.rb b/lib/rubygems/source/vendor.rb
index f2cf540c8d..244c4201d8 100644
--- a/lib/rubygems/source/vendor.rb
+++ b/lib/rubygems/source/vendor.rb
@@ -3,8 +3,22 @@
class Gem::Source::Vendor < Gem::Source::Installed
- def initialize uri
- @uri = uri
+ ##
+ # Creates a new Vendor source for a gem that was unpacked at +path+.
+
+ def initialize path
+ @uri = path
+ end
+
+ def <=> other
+ case other
+ when Gem::Source::Vendor then
+ 0
+ when Gem::Source then
+ 1
+ else
+ nil
+ end
end
end