aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/request_set
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/request_set
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/request_set')
-rw-r--r--lib/rubygems/request_set/gem_dependency_api.rb149
-rw-r--r--lib/rubygems/request_set/lockfile.rb27
2 files changed, 159 insertions, 17 deletions
diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb
index e8f3138990..8e29eb87e5 100644
--- a/lib/rubygems/request_set/gem_dependency_api.rb
+++ b/lib/rubygems/request_set/gem_dependency_api.rb
@@ -108,6 +108,11 @@ class Gem::RequestSet::GemDependencyAPI
}
##
+ # A set of gems that are loaded via the +:git+ option to #gem
+
+ attr_reader :git_set # :nodoc:
+
+ ##
# A Hash containing gem names and files to require from those gems.
attr_reader :requires
@@ -130,13 +135,55 @@ class Gem::RequestSet::GemDependencyAPI
@set = set
@path = path
- @current_groups = nil
- @current_platform = nil
- @default_sources = true
- @requires = Hash.new { |h, name| h[name] = [] }
- @vendor_set = @set.vendor_set
- @gem_sources = {}
- @without_groups = []
+ @current_groups = nil
+ @current_platform = nil
+ @current_repository = nil
+ @default_sources = true
+ @git_set = @set.git_set
+ @requires = Hash.new { |h, name| h[name] = [] }
+ @vendor_set = @set.vendor_set
+ @gem_sources = {}
+ @without_groups = []
+ end
+
+ ##
+ # Adds +dependencies+ to the request set if any of the +groups+ are allowed.
+ # This is used for gemspec dependencies.
+
+ def add_dependencies groups, dependencies # :nodoc:
+ return unless (groups & @without_groups).empty?
+
+ dependencies.each do |dep|
+ @set.gem dep.name, *dep.requirement
+ end
+ end
+
+ private :add_dependencies
+
+ ##
+ # Finds a gemspec with the given +name+ that lives at +path+.
+
+ def find_gemspec name, path # :nodoc:
+ glob = File.join path, "#{name}.gemspec"
+
+ spec_files = Dir[glob]
+
+ case spec_files.length
+ when 1 then
+ spec_file = spec_files.first
+
+ spec = Gem::Specification.load spec_file
+
+ return spec if spec
+
+ raise ArgumentError, "invalid gemspec #{spec_file}"
+ when 0 then
+ raise ArgumentError, "no gemspecs found at #{Dir.pwd}"
+ else
+ raise ArgumentError,
+ "found multiple gemspecs at #{Dir.pwd}, " +
+ "use the name: option to specify the one you want"
+ end
end
##
@@ -160,7 +207,13 @@ class Gem::RequestSet::GemDependencyAPI
options = requirements.pop if requirements.last.kind_of?(Hash)
options ||= {}
- source_set = gem_path name, options
+ options[:git] = @current_repository if @current_repository
+
+ source_set = false
+
+ source_set ||= gem_path name, options
+ source_set ||= gem_git name, options
+ source_set ||= gem_github name, options
return unless gem_platforms options
@@ -182,6 +235,54 @@ class Gem::RequestSet::GemDependencyAPI
end
##
+ # Handles the git: option from +options+ for gem +name+.
+ #
+ # Returns +true+ if the path option was handled.
+
+ def gem_git name, options # :nodoc:
+ if gist = options.delete(:gist) then
+ options[:git] = "https://gist.github.com/#{gist}.git"
+ end
+
+ return unless repository = options.delete(:git)
+
+ raise ArgumentError,
+ "duplicate source git: #{repository} for gem #{name}" if
+ @gem_sources.include? name
+
+ reference = nil
+ reference ||= options.delete :ref
+ reference ||= options.delete :branch
+ reference ||= options.delete :tag
+ reference ||= 'master'
+
+ submodules = options.delete :submodules
+
+ @git_set.add_git_gem name, repository, reference, submodules
+
+ @gem_sources[name] = repository
+
+ true
+ end
+
+ private :gem_git
+
+ ##
+ # Handles the github: option from +options+ for gem +name+.
+ #
+ # Returns +true+ if the path option was handled.
+
+ def gem_github name, options # :nodoc:
+ return unless path = options.delete(:github)
+
+ options[:git] = "git://github.com/#{path}.git"
+
+ gem_git name, options
+
+ true
+ end
+
+ ##
# Handles the :group and :groups +options+ for the gem with the given
# +name+.
@@ -269,6 +370,15 @@ class Gem::RequestSet::GemDependencyAPI
private :gem_requires
+ def git repository
+ @current_repository = repository
+
+ yield
+
+ ensure
+ @current_repository = nil
+ end
+
##
# Returns the basename of the file the dependencies were loaded from
@@ -278,6 +388,29 @@ class Gem::RequestSet::GemDependencyAPI
##
# :category: Gem Dependencies DSL
+ #
+ # Loads dependencies from a gemspec file.
+
+ def gemspec options = {}
+ name = options.delete(:name) || '{,*}'
+ path = options.delete(:path) || '.'
+ development_group = options.delete(:development_group) || :development
+
+ spec = find_gemspec name, path
+
+ groups = gem_group spec.name, {}
+
+ add_dependencies groups, spec.runtime_dependencies
+
+ groups << development_group
+
+ add_dependencies groups, spec.development_dependencies
+
+ gem_requires spec.name, options
+ end
+
+ ##
+ # :category: Gem Dependencies DSL
# Block form for placing a dependency in the given +groups+.
def group *groups
diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb
index a9c419549d..0073bfdcc5 100644
--- a/lib/rubygems/request_set/lockfile.rb
+++ b/lib/rubygems/request_set/lockfile.rb
@@ -1,5 +1,3 @@
-require 'pathname'
-
class Gem::RequestSet::Lockfile
##
@@ -46,8 +44,8 @@ class Gem::RequestSet::Lockfile
def initialize request_set, gem_deps_file
@set = request_set
- @gem_deps_file = Pathname(gem_deps_file).expand_path
- @gem_deps_dir = @gem_deps_file.dirname
+ @gem_deps_file = File.expand_path(gem_deps_file)
+ @gem_deps_dir = File.dirname(@gem_deps_file)
@current_token = nil
@line = 0
@@ -62,7 +60,7 @@ class Gem::RequestSet::Lockfile
@set.dependencies.sort.map do |dependency|
source = @requests.find do |req|
req.name == dependency.name and
- req.spec.class == Gem::DependencyResolver::VendorSpecification
+ req.spec.class == Gem::Resolver::VendorSpecification
end
source_dep = '!' if source
@@ -102,15 +100,26 @@ class Gem::RequestSet::Lockfile
out << nil
end
+ def relative_path_from(dest, base)
+ dest = File.expand_path(dest)
+ base = File.expand_path(base)
+
+ if dest.index(base) == 0
+ return dest[base.size+1..-1]
+ else
+ dest
+ end
+ end
+
def add_PATH out # :nodoc:
return unless path_requests =
- @spec_groups.delete(Gem::DependencyResolver::VendorSpecification)
+ @spec_groups.delete(Gem::Resolver::VendorSpecification)
out << "PATH"
path_requests.each do |request|
- directory = Pathname(request.spec.source.uri).expand_path
+ directory = File.expand_path(request.spec.source.uri)
- out << " remote: #{directory.relative_path_from @gem_deps_dir}"
+ out << " remote: #{relative_path_from directory, @gem_deps_dir}"
out << " specs:"
out << " #{request.name} (#{request.version})"
end
@@ -208,7 +217,7 @@ class Gem::RequestSet::Lockfile
skip :newline
- set = Gem::DependencyResolver::LockSet.new source
+ set = Gem::Resolver::LockSet.new source
while not @tokens.empty? and :text == peek.first do
_, name, = get :text