lib/rubygems/request_set.rb in rubygems-update-2.7.11 vs lib/rubygems/request_set.rb in rubygems-update-3.0.0

- old
+ new

@@ -89,11 +89,11 @@ # nokogiri = Gem::Dependency.new 'nokogiri', '~> 1.6' # pg = Gem::Dependency.new 'pg', '~> 0.14' # # set = Gem::RequestSet.new nokogiri, pg - def initialize *deps + def initialize(*deps) @dependencies = deps @always_install = [] @conservative = false @dependency_names = {} @@ -117,12 +117,12 @@ end ## # Declare that a gem of name +name+ with +reqs+ requirements is needed. - def gem name, *reqs - if dep = @dependency_names[name] then + def gem(name, *reqs) + if dep = @dependency_names[name] dep.requirement.concat reqs else dep = Gem::Dependency.new name, *reqs @dependency_names[name] = dep @dependencies << dep @@ -130,36 +130,63 @@ end ## # Add +deps+ Gem::Dependency objects to the set. - def import deps + def import(deps) @dependencies.concat deps end ## # Installs gems for this RequestSet using the Gem::Installer +options+. # # If a +block+ is given an activation +request+ and +installer+ are yielded. # The +installer+ will be +nil+ if a gem matching the request was already # installed. - def install options, &block # :yields: request, installer + def install(options, &block) # :yields: request, installer if dir = options[:install_dir] requests = install_into dir, false, options, &block return requests end @prerelease = options[:prerelease] requests = [] + download_queue = Queue.new + # Create a thread-safe list of gems to download sorted_requests.each do |req| - if req.installed? then + download_queue << req + end + + # Create N threads in a pool, have them download all the gems + threads = Gem.configuration.concurrent_downloads.times.map do + # When a thread pops this item, it knows to stop running. The symbol + # is queued here so that there will be one symbol per thread. + download_queue << :stop + + Thread.new do + # The pop method will block waiting for items, so the only way + # to stop a thread from running is to provide a final item that + # means the thread should stop. + while req = download_queue.pop + break if req == :stop + req.spec.download options unless req.installed? + end + end + end + + # Wait for all the downloads to finish before continuing + threads.each(&:value) + + # Install requested gems after they have been downloaded + sorted_requests.each do |req| + if req.installed? req.spec.spec.build_extensions - if @always_install.none? { |spec| spec == req.spec.spec } then + if @always_install.none? { |spec| spec == req.spec.spec } yield req, nil if block_given? next end end @@ -201,11 +228,11 @@ # +options+, yielding to the +block+ as in #install. # # If +:without_groups+ is given in the +options+, those groups in the gem # dependencies file are not used. See Gem::Installer for other +options+. - def install_from_gemdeps options, &block + def install_from_gemdeps(options, &block) gemdeps = options[:gemdeps] @install_dir = options[:install_dir] || Gem.dir @prerelease = options[:prerelease] @remote = options[:domain] != :local @@ -226,21 +253,21 @@ @resolver.stats.display end else installed = install options, &block - if options.fetch :lock, true then + if options.fetch :lock, true lockfile = Gem::RequestSet::Lockfile.build self, gemdeps, gem_deps_api.dependencies lockfile.write end installed end end - def install_into dir, force = true, options = {} + def install_into(dir, force = true, options = {}) gem_home, ENV['GEM_HOME'] = ENV['GEM_HOME'], dir existing = force ? [] : specs_in(dir) existing.delete_if { |s| @always_install.include? s } @@ -254,11 +281,11 @@ @prerelease = options[:prerelease] sorted_requests.each do |request| spec = request.spec - if existing.find { |s| s.full_name == spec.full_name } then + if existing.find { |s| s.full_name == spec.full_name } yield request, nil if block_given? next end spec.install options do |installer| @@ -276,11 +303,11 @@ end ## # Call hooks on installed gems - def install_hooks requests, options + def install_hooks(requests, options) specs = requests.map do |request| case request when Gem::Resolver::ActivationRequest then request.spec.spec else @@ -298,11 +325,11 @@ end ## # Load a dependency management file. - def load_gemdeps path, without_groups = [], installing = false + def load_gemdeps(path, without_groups = [], installing = false) @git_set = Gem::Resolver::GitSet.new @vendor_set = Gem::Resolver::VendorSet.new @source_set = Gem::Resolver::SourceSet.new @git_set.root_dir = @install_dir @@ -319,33 +346,33 @@ gf.installing = installing gf.without_groups = without_groups if without_groups gf.load end - def pretty_print q # :nodoc: + def pretty_print(q) # :nodoc: q.group 2, '[RequestSet:', ']' do q.breakable - if @remote then + if @remote q.text 'remote' q.breakable end - if @prerelease then + if @prerelease q.text 'prerelease' q.breakable end - if @development_shallow then + if @development_shallow q.text 'shallow development' q.breakable - elsif @development then + elsif @development q.text 'development' q.breakable end - if @soft_missing then + if @soft_missing q.text 'soft missing' end q.group 2, '[dependencies:', ']' do q.breakable @@ -365,11 +392,11 @@ ## # Resolve the requested dependencies and return an Array of Specification # objects to be activated. - def resolve set = Gem::Resolver::BestSet.new + def resolve(set = Gem::Resolver::BestSet.new) @sets << set @sets << @git_set @sets << @vendor_set @sets << @source_set @@ -414,28 +441,28 @@ def specs @specs ||= @requests.map { |r| r.full_spec } end - def specs_in dir - Dir["#{dir}/specifications/*.gemspec"].map do |g| + def specs_in(dir) + Gem::Util.glob_files_in_dir("*.gemspec", File.join(dir, "specifications")).map do |g| Gem::Specification.load g end end - def tsort_each_node &block # :nodoc: + def tsort_each_node(&block) # :nodoc: @requests.each(&block) end - def tsort_each_child node # :nodoc: + def tsort_each_child(node) # :nodoc: node.spec.dependencies.each do |dep| next if dep.type == :development and not @development match = @requests.find { |r| dep.match? r.spec.name, r.spec.version, @prerelease } - unless match then + unless match next if dep.type == :development and @development_shallow next if @soft_missing raise Gem::DependencyError, "Unresolved dependency found during sorting - #{dep} (requested by #{node.spec.full_name})" end