Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gemified set #4297

Merged
merged 9 commits into from
Jan 28, 2021
24 changes: 10 additions & 14 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,16 @@ RDoc::Task.new :rdoc => 'docs', :clobber_rdoc => 'clobber_docs' do |doc|
doc.rdoc_dir = 'doc'
end

begin
require "automatiek"

Automatiek::RakeTask.new("molinillo") do |lib|
lib.version = "0.7.0"
lib.download = { :github => "https://github.com/CocoaPods/Molinillo" }
lib.namespace = "Molinillo"
lib.prefix = "Gem::Resolver"
lib.vendor_lib = "lib/rubygems/resolver/molinillo"
end
rescue LoadError
namespace :vendor do
task(:molinillo) { abort "Install the automatiek gem to be able to vendor gems." }
end
load "util/automatiek.rake"

# We currently ship Molinillo master branch as of
# https://github.com/CocoaPods/Molinillo/commit/7cc27a355e861bdf593e2cde7bf1bca3daae4303
Automatiek::RakeTask.new("molinillo") do |lib|
lib.version = "master"
lib.download = { :github => "https://github.com/CocoaPods/Molinillo" }
lib.namespace = "Molinillo"
lib.prefix = "Gem::Resolver"
lib.vendor_lib = "lib/rubygems/resolver/molinillo"
end

namespace :rubocop do
Expand Down
9 changes: 3 additions & 6 deletions bundler/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@ namespace :man do
end
end

load "task/automatiek.rake"
load "../util/automatiek.rake"

# We currently ship Molinillo master branch as of
# https://github.com/CocoaPods/Molinillo/commit/0f3d33d004214f5e3a426c3382c4af37bc3f27e5,
# plus the following changes:
# * Properly print requirements (https://github.com/CocoaPods/Molinillo/pull/149).
# * Allow custom comparison of dependencies (https://github.com/CocoaPods/Molinillo/pull/150).
# https://github.com/CocoaPods/Molinillo/commit/7cc27a355e861bdf593e2cde7bf1bca3daae4303
desc "Vendor a specific version of molinillo"
Automatiek::RakeTask.new("molinillo") do |lib|
lib.version = "master"
Expand All @@ -166,7 +163,7 @@ end

desc "Vendor a specific version of thor"
Automatiek::RakeTask.new("thor") do |lib|
lib.version = "v1.0.1"
lib.version = "v1.1.0"
lib.download = { :github => "https://github.com/erikhuda/thor" }
lib.namespace = "Thor"
lib.prefix = "Bundler"
Expand Down
3 changes: 1 addition & 2 deletions bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require_relative "lockfile_parser"
require "set"

module Bundler
class Definition
Expand Down Expand Up @@ -611,7 +610,7 @@ def dependencies_for_source_changed?(source, locked_source = source)
deps_for_source = @dependencies.select {|s| s.source == source }
locked_deps_for_source = @locked_deps.values.select {|dep| dep.source == locked_source }

Set.new(deps_for_source) != Set.new(locked_deps_for_source)
deps_for_source.sort != locked_deps_for_source.sort
end

def specs_for_source_changed?(source)
Expand Down
11 changes: 6 additions & 5 deletions bundler/lib/bundler/index.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "set"

module Bundler
class Index
include Enumerable
Expand Down Expand Up @@ -65,11 +63,14 @@ def search(query, base = nil)
def unsorted_search(query, base)
results = local_search(query, base)

seen = results.map(&:full_name).to_set unless @sources.empty?
seen = results.map(&:full_name).uniq unless @sources.empty?

@sources.each do |source|
source.unsorted_search(query, base).each do |spec|
results << spec if seen.add?(spec.full_name)
next if seen.include?(spec.full_name)

seen << spec.full_name
results << spec
end
end

Expand Down Expand Up @@ -170,7 +171,7 @@ def ==(other)
def dependencies_eql?(spec, other_spec)
deps = spec.dependencies.select {|d| d.type != :development }
other_deps = other_spec.dependencies.select {|d| d.type != :development }
Set.new(deps) == Set.new(other_deps)
deps.sort == other_deps.sort
end

def add_source(index)
Expand Down
1 change: 0 additions & 1 deletion bundler/lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Resolver
# <GemBundle>,nil:: If the list of dependencies can be resolved, a
# collection of gemspecs is returned. Otherwise, nil is returned.
def self.resolve(requirements, index, source_requirements = {}, base = [], gem_version_promoter = GemVersionPromoter.new, additional_base_requirements = [], platforms = nil)
platforms = Set.new(platforms) if platforms
base = SpecSet.new(base) unless base.is_a?(SpecSet)
resolver = new(index, source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
result = resolver.start(requirements)
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def md5_available?
return @md5_available if defined?(@md5_available)
@md5_available = begin
require "openssl"
OpenSSL::Digest.digest("MD5", "")
::OpenSSL::Digest.digest("MD5", "")
true
rescue LoadError
true
rescue OpenSSL::Digest::DigestError
rescue ::OpenSSL::Digest::DigestError
false
end
end
Expand Down
6 changes: 2 additions & 4 deletions bundler/lib/bundler/source_list.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "set"

module Bundler
class SourceList
attr_reader :path_sources,
Expand Down Expand Up @@ -99,7 +97,7 @@ def replace_sources!(replacement_sources)
@rubygems_aggregate = replacement_rubygems if replacement_rubygems

return true if !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources)
return true if replacement_rubygems && rubygems_remotes.to_set != replacement_rubygems.remotes.to_set
return true if replacement_rubygems && rubygems_remotes.sort_by(&:to_s) != replacement_rubygems.remotes.sort_by(&:to_s)

false
end
Expand Down Expand Up @@ -153,7 +151,7 @@ def warn_on_git_protocol(source)
end

def equal_sources?(lock_sources, replacement_sources)
lock_sources.to_set == replacement_sources.to_set
lock_sources.sort_by(&:to_s) == replacement_sources.sort_by(&:to_s)
end

def equal_source?(source, other_source)
Expand Down
7 changes: 4 additions & 3 deletions bundler/lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "tsort"
require "set"

module Bundler
class SpecSet
Expand All @@ -13,14 +12,16 @@ def initialize(specs)
end

def for(dependencies, skip = [], check = false, match_current_platform = false, raise_on_missing = true)
handled = Set.new
handled = []
deps = dependencies.dup
specs = []
skip += ["bundler"]

loop do
break unless dep = deps.shift
next if !handled.add?(dep) || skip.include?(dep.name)
next if handled.include?(dep) || skip.include?(dep.name)

handled << dep

specs_for_dep = spec_for_dependency(dep, match_current_platform)
if specs_for_dep.any?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'set'
require 'tsort'

require_relative 'dependency_graph/log'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def recursive_predecessors
# @param [Set<Vertex>] vertices the set to add the predecessors to
# @return [Set<Vertex>] the vertices of {#graph} where `self` is a
# {#descendent?}
def _recursive_predecessors(vertices = Set.new)
def _recursive_predecessors(vertices = new_vertex_set)
incoming_edges.each do |edge|
vertex = edge.origin
next unless vertices.add?(vertex)
Expand All @@ -85,7 +85,7 @@ def recursive_successors
# @param [Set<Vertex>] vertices the set to add the successors to
# @return [Set<Vertex>] the vertices of {#graph} where `self` is an
# {#ancestor?}
def _recursive_successors(vertices = Set.new)
def _recursive_successors(vertices = new_vertex_set)
outgoing_edges.each do |edge|
vertex = edge.destination
next unless vertices.add?(vertex)
Expand Down Expand Up @@ -128,7 +128,7 @@ def hash

# Is there a path from `self` to `other` following edges in the
# dependency graph?
# @return true iff there is a path following edges within this {#graph}
# @return whether there is a path following edges within this {#graph}
def path_to?(other)
_path_to?(other)
end
Expand All @@ -138,7 +138,7 @@ def path_to?(other)
# @param [Vertex] other the vertex to check if there's a path to
# @param [Set<Vertex>] visited the vertices of {#graph} that have been visited
# @return [Boolean] whether there is a path to `other` from `self`
def _path_to?(other, visited = Set.new)
def _path_to?(other, visited = new_vertex_set)
return false unless visited.add?(self)
return true if equal?(other)
successors.any? { |v| v._path_to?(other, visited) }
Expand All @@ -147,12 +147,18 @@ def _path_to?(other, visited = Set.new)

# Is there a path from `other` to `self` following edges in the
# dependency graph?
# @return true iff there is a path following edges within this {#graph}
# @return whether there is a path following edges within this {#graph}
def ancestor?(other)
other.path_to?(self)
end

alias is_reachable_from? ancestor?

def new_vertex_set
require 'set'
Set.new
end
private :new_vertex_set
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def message

# An error caused by attempting to fulfil a dependency that was circular
#
# @note This exception will be thrown iff a {Vertex} is added to a
# @note This exception will be thrown if and only if a {Vertex} is added to a
# {DependencyGraph} that has a {DependencyGraph::Vertex#path_to?} an
# existing {DependencyGraph::Vertex}
class CircularDependencyError < ResolverError
Expand Down
11 changes: 5 additions & 6 deletions bundler/lib/bundler/vendor/thor/lib/thor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "set"
require_relative "thor/base"

class Bundler::Thor
$thor_runner ||= false
class << self
# Allows for custom "Command" package naming.
#
Expand Down Expand Up @@ -323,7 +323,7 @@ def check_unknown_options?(config) #:nodoc:
# ==== Parameters
# Symbol ...:: A list of commands that should be affected.
def stop_on_unknown_option!(*command_names)
stop_on_unknown_option.merge(command_names)
@stop_on_unknown_option = stop_on_unknown_option | command_names
end

def stop_on_unknown_option?(command) #:nodoc:
Expand All @@ -337,7 +337,7 @@ def stop_on_unknown_option?(command) #:nodoc:
# ==== Parameters
# Symbol ...:: A list of commands that should be affected.
def disable_required_check!(*command_names)
disable_required_check.merge(command_names)
@disable_required_check = disable_required_check | command_names
end

def disable_required_check?(command) #:nodoc:
Expand All @@ -347,12 +347,12 @@ def disable_required_check?(command) #:nodoc:
protected

def stop_on_unknown_option #:nodoc:
@stop_on_unknown_option ||= Set.new
@stop_on_unknown_option ||= []
end

# help command has the required check disabled by default.
def disable_required_check #:nodoc:
@disable_required_check ||= Set.new([:help])
@disable_required_check ||= [:help]
end

# The method responsible for dispatching given the args.
Expand Down Expand Up @@ -398,7 +398,6 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
# the namespace should be displayed as arguments.
#
def banner(command, namespace = nil, subcommand = false)
$thor_runner ||= false
command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
"#{basename} #{formatted_usage}"
end.join("\n")
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/vendor/thor/lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def apply(path, config = {})

contents = if is_uri
require "open-uri"
open(path, "Accept" => "application/x-thor-template", &:read)
URI.open(path, "Accept" => "application/x-thor-template", &:read)
else
open(path, &:read)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def inject_into_module(path, module_name, *args, &block)
# path<String>:: path of the file to be changed
# flag<Regexp|String>:: the regexp or string to be replaced
# replacement<String>:: the replacement, can be also given as a block
# config<Hash>:: give :verbose => false to not log the status.
# config<Hash>:: give :verbose => false to not log the status, and
# :force => true, to force the replacement regardles of runner behavior.
#
# ==== Example
#
Expand All @@ -262,9 +263,10 @@ def inject_into_module(path, module_name, *args, &block)
# end
#
def gsub_file(path, flag, *args, &block)
return unless behavior == :invoke
config = args.last.is_a?(Hash) ? args.pop : {}

return unless behavior == :invoke || config.fetch(:force, false)

path = File.expand_path(path, destination_root)
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)

Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/vendor/thor/lib/thor/error.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Bundler::Thor
Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable)
Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName
# In order to support versions of Ruby that don't have keyword
# arguments, we need our own spell checker class that doesn't take key
# words. Even though this code wouldn't be hit because of the check
Expand Down
6 changes: 5 additions & 1 deletion bundler/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def initialize(arguments = [])

arguments.each do |argument|
if !argument.default.nil?
@assigns[argument.human_name] = argument.default
begin
@assigns[argument.human_name] = argument.default.dup
rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4
@assigns[argument.human_name] = argument.default
end
elsif argument.required?
@non_assigned_required << argument
end
Expand Down
17 changes: 9 additions & 8 deletions bundler/lib/bundler/vendor/thor/lib/thor/parser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ def check_unknown!

protected

def assign_result!(option, result)
if option.repeatable && option.type == :hash
(@assigns[option.human_name] ||= {}).merge!(result)
elsif option.repeatable
(@assigns[option.human_name] ||= []) << result
else
@assigns[option.human_name] = result
def assign_result!(option, result)
if option.repeatable && option.type == :hash
(@assigns[option.human_name] ||= {}).merge!(result)
elsif option.repeatable
(@assigns[option.human_name] ||= []) << result
else
@assigns[option.human_name] = result
end
end
end

# Check if the current value in peek is a registered switch.
#
# Two booleans are returned. The first is true if the current value
Expand Down
Loading