bundler 2.3.12 → 2.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +367 -1
  3. data/README.md +2 -2
  4. data/bundler.gemspec +8 -10
  5. data/exe/bundle +1 -4
  6. data/lib/bundler/build_metadata.rb +2 -2
  7. data/lib/bundler/cli/add.rb +1 -1
  8. data/lib/bundler/cli/binstubs.rb +5 -1
  9. data/lib/bundler/cli/check.rb +1 -1
  10. data/lib/bundler/cli/common.rb +3 -1
  11. data/lib/bundler/cli/console.rb +2 -2
  12. data/lib/bundler/cli/doctor.rb +4 -6
  13. data/lib/bundler/cli/gem.rb +62 -40
  14. data/lib/bundler/cli/init.rb +5 -1
  15. data/lib/bundler/cli/install.rb +7 -5
  16. data/lib/bundler/cli/lock.rb +8 -5
  17. data/lib/bundler/cli/open.rb +6 -4
  18. data/lib/bundler/cli/outdated.rb +13 -6
  19. data/lib/bundler/cli/platform.rb +1 -1
  20. data/lib/bundler/cli/viz.rb +1 -1
  21. data/lib/bundler/cli.rb +52 -7
  22. data/lib/bundler/compact_index_client/cache.rb +1 -1
  23. data/lib/bundler/compact_index_client/updater.rb +53 -39
  24. data/lib/bundler/constants.rb +1 -1
  25. data/lib/bundler/current_ruby.rb +15 -6
  26. data/lib/bundler/definition.rb +203 -110
  27. data/lib/bundler/dependency.rb +21 -84
  28. data/lib/bundler/digest.rb +1 -1
  29. data/lib/bundler/dsl.rb +13 -18
  30. data/lib/bundler/endpoint_specification.rb +6 -10
  31. data/lib/bundler/env.rb +1 -1
  32. data/lib/bundler/environment_preserver.rb +1 -0
  33. data/lib/bundler/errors.rb +15 -15
  34. data/lib/bundler/feature_flag.rb +0 -1
  35. data/lib/bundler/fetcher/base.rb +6 -8
  36. data/lib/bundler/fetcher/compact_index.rb +9 -11
  37. data/lib/bundler/fetcher/dependency.rb +1 -1
  38. data/lib/bundler/fetcher/downloader.rb +2 -5
  39. data/lib/bundler/fetcher.rb +12 -12
  40. data/lib/bundler/force_platform.rb +18 -0
  41. data/lib/bundler/friendly_errors.rb +21 -7
  42. data/lib/bundler/gem_helpers.rb +9 -2
  43. data/lib/bundler/gem_version_promoter.rb +53 -98
  44. data/lib/bundler/graph.rb +3 -3
  45. data/lib/bundler/index.rb +11 -49
  46. data/lib/bundler/injector.rb +8 -3
  47. data/lib/bundler/inline.rb +9 -21
  48. data/lib/bundler/installer/gem_installer.rb +14 -1
  49. data/lib/bundler/installer/parallel_installer.rb +0 -31
  50. data/lib/bundler/installer/standalone.rb +41 -10
  51. data/lib/bundler/installer.rb +18 -39
  52. data/lib/bundler/lazy_specification.rb +53 -48
  53. data/lib/bundler/lockfile_generator.rb +1 -1
  54. data/lib/bundler/lockfile_parser.rb +9 -5
  55. data/lib/bundler/man/bundle-add.1 +13 -5
  56. data/lib/bundler/man/bundle-add.1.ronn +10 -4
  57. data/lib/bundler/man/bundle-binstubs.1 +1 -1
  58. data/lib/bundler/man/bundle-cache.1 +7 -1
  59. data/lib/bundler/man/bundle-cache.1.ronn +7 -0
  60. data/lib/bundler/man/bundle-check.1 +1 -1
  61. data/lib/bundler/man/bundle-clean.1 +2 -2
  62. data/lib/bundler/man/bundle-clean.1.ronn +1 -1
  63. data/lib/bundler/man/bundle-config.1 +26 -7
  64. data/lib/bundler/man/bundle-config.1.ronn +17 -7
  65. data/lib/bundler/man/bundle-console.1 +53 -0
  66. data/lib/bundler/man/bundle-console.1.ronn +44 -0
  67. data/lib/bundler/man/bundle-doctor.1 +1 -1
  68. data/lib/bundler/man/bundle-exec.1 +6 -6
  69. data/lib/bundler/man/bundle-exec.1.ronn +6 -6
  70. data/lib/bundler/man/bundle-gem.1 +27 -37
  71. data/lib/bundler/man/bundle-gem.1.ronn +5 -5
  72. data/lib/bundler/man/bundle-help.1 +13 -0
  73. data/lib/bundler/man/bundle-help.1.ronn +12 -0
  74. data/lib/bundler/man/bundle-info.1 +1 -1
  75. data/lib/bundler/man/bundle-init.1 +1 -1
  76. data/lib/bundler/man/bundle-inject.1 +5 -2
  77. data/lib/bundler/man/bundle-inject.1.ronn +3 -1
  78. data/lib/bundler/man/bundle-install.1 +5 -30
  79. data/lib/bundler/man/bundle-install.1.ronn +6 -29
  80. data/lib/bundler/man/bundle-list.1 +1 -1
  81. data/lib/bundler/man/bundle-lock.1 +1 -1
  82. data/lib/bundler/man/bundle-open.1 +22 -2
  83. data/lib/bundler/man/bundle-open.1.ronn +9 -1
  84. data/lib/bundler/man/bundle-outdated.1 +1 -1
  85. data/lib/bundler/man/bundle-platform.1 +16 -6
  86. data/lib/bundler/man/bundle-platform.1.ronn +14 -7
  87. data/lib/bundler/man/bundle-plugin.1 +81 -0
  88. data/lib/bundler/man/bundle-plugin.1.ronn +59 -0
  89. data/lib/bundler/man/bundle-pristine.1 +1 -1
  90. data/lib/bundler/man/bundle-remove.1 +1 -1
  91. data/lib/bundler/man/bundle-show.1 +1 -1
  92. data/lib/bundler/man/bundle-update.1 +1 -1
  93. data/lib/bundler/man/bundle-version.1 +35 -0
  94. data/lib/bundler/man/bundle-version.1.ronn +24 -0
  95. data/lib/bundler/man/bundle-viz.1 +4 -1
  96. data/lib/bundler/man/bundle-viz.1.ronn +2 -0
  97. data/lib/bundler/man/bundle.1 +15 -10
  98. data/lib/bundler/man/bundle.1.ronn +12 -7
  99. data/lib/bundler/man/gemfile.5 +92 -81
  100. data/lib/bundler/man/gemfile.5.ronn +98 -85
  101. data/lib/bundler/man/index.txt +4 -0
  102. data/lib/bundler/match_metadata.rb +13 -0
  103. data/lib/bundler/match_platform.rb +0 -1
  104. data/lib/bundler/match_remote_metadata.rb +29 -0
  105. data/lib/bundler/mirror.rb +5 -7
  106. data/lib/bundler/plugin/api/source.rb +3 -3
  107. data/lib/bundler/plugin/index.rb +4 -4
  108. data/lib/bundler/plugin/installer/git.rb +0 -4
  109. data/lib/bundler/plugin/installer/rubygems.rb +0 -8
  110. data/lib/bundler/plugin.rb +2 -0
  111. data/lib/bundler/process_lock.rb +1 -1
  112. data/lib/bundler/remote_specification.rb +8 -9
  113. data/lib/bundler/resolver/base.rb +77 -0
  114. data/lib/bundler/resolver/candidate.rb +94 -0
  115. data/lib/bundler/resolver/incompatibility.rb +15 -0
  116. data/lib/bundler/resolver/package.rb +72 -0
  117. data/lib/bundler/resolver/root.rb +25 -0
  118. data/lib/bundler/resolver/spec_group.rb +42 -70
  119. data/lib/bundler/resolver.rb +322 -326
  120. data/lib/bundler/ruby_dsl.rb +1 -1
  121. data/lib/bundler/ruby_version.rb +5 -5
  122. data/lib/bundler/rubygems_ext.rb +102 -12
  123. data/lib/bundler/rubygems_gem_installer.rb +32 -20
  124. data/lib/bundler/rubygems_integration.rb +12 -34
  125. data/lib/bundler/runtime.rb +1 -6
  126. data/lib/bundler/settings.rb +2 -8
  127. data/lib/bundler/shared_helpers.rb +7 -7
  128. data/lib/bundler/source/git/git_proxy.rb +193 -67
  129. data/lib/bundler/source/git.rb +21 -25
  130. data/lib/bundler/source/metadata.rb +1 -2
  131. data/lib/bundler/source/path/installer.rb +1 -22
  132. data/lib/bundler/source/path.rb +6 -6
  133. data/lib/bundler/source/rubygems.rb +75 -117
  134. data/lib/bundler/source.rb +3 -4
  135. data/lib/bundler/source_list.rb +12 -2
  136. data/lib/bundler/spec_set.rb +52 -34
  137. data/lib/bundler/stub_specification.rb +5 -3
  138. data/lib/bundler/templates/Executable +1 -1
  139. data/lib/bundler/templates/Executable.bundler +4 -9
  140. data/lib/bundler/templates/Executable.standalone +2 -0
  141. data/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
  142. data/lib/bundler/templates/newgem/Gemfile.tt +3 -0
  143. data/lib/bundler/templates/newgem/README.md.tt +6 -4
  144. data/lib/bundler/templates/newgem/Rakefile.tt +2 -1
  145. data/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
  146. data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
  147. data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
  148. data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
  149. data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +10 -0
  150. data/lib/bundler/templates/newgem/gitignore.tt +3 -0
  151. data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +13 -4
  152. data/lib/bundler/templates/newgem/newgem.gemspec.tt +8 -2
  153. data/lib/bundler/ui/shell.rb +35 -12
  154. data/lib/bundler/ui/silent.rb +21 -5
  155. data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +3 -3
  156. data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +0 -1
  157. data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +3 -1
  158. data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1350 -408
  159. data/lib/bundler/vendor/net-http-persistent/README.rdoc +1 -1
  160. data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
  161. data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
  162. data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
  163. data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
  164. data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
  165. data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +151 -0
  166. data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
  167. data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
  168. data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
  169. data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
  170. data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +53 -0
  171. data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
  172. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
  173. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +128 -0
  174. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +409 -0
  175. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +240 -0
  176. data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
  177. data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
  178. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +1 -1
  179. data/lib/bundler/vendor/uri/lib/uri/common.rb +64 -16
  180. data/lib/bundler/vendor/uri/lib/uri/file.rb +7 -1
  181. data/lib/bundler/vendor/uri/lib/uri/ftp.rb +2 -1
  182. data/lib/bundler/vendor/uri/lib/uri/generic.rb +27 -7
  183. data/lib/bundler/vendor/uri/lib/uri/http.rb +40 -2
  184. data/lib/bundler/vendor/uri/lib/uri/https.rb +2 -1
  185. data/lib/bundler/vendor/uri/lib/uri/ldap.rb +1 -1
  186. data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
  187. data/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -2
  188. data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +13 -7
  189. data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +10 -5
  190. data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
  191. data/lib/bundler/vendor/uri/lib/uri/ws.rb +1 -2
  192. data/lib/bundler/vendor/uri/lib/uri/wss.rb +2 -1
  193. data/lib/bundler/vendor/uri/lib/uri.rb +3 -2
  194. data/lib/bundler/vendored_persistent.rb +1 -33
  195. data/lib/bundler/{vendored_tmpdir.rb → vendored_pub_grub.rb} +1 -1
  196. data/lib/bundler/version.rb +5 -1
  197. data/lib/bundler/worker.rb +5 -7
  198. data/lib/bundler.rb +35 -69
  199. metadata +45 -34
  200. data/lib/bundler/dep_proxy.rb +0 -55
  201. data/lib/bundler/templates/newgem/travis.yml.tt +0 -6
  202. data/lib/bundler/vendor/molinillo/LICENSE +0 -9
  203. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  204. data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
  205. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
  206. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
  207. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
  208. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
  209. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
  210. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
  211. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
  212. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
  213. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
  214. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -255
  215. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -149
  216. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  217. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
  218. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
  219. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -839
  220. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
  221. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
  222. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -11
  223. data/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
  224. data/lib/bundler/vendored_molinillo.rb +0 -4
  225. data/lib/bundler/version_ranges.rb +0 -122
  226. /data/lib/bundler/templates/newgem/ext/newgem/{extconf.rb.tt → extconf-c.rb.tt} +0 -0
@@ -1,420 +1,416 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bundler
4
+ #
5
+ # This class implements the interface needed by PubGrub for resolution. It is
6
+ # equivalent to the `PubGrub::BasicPackageSource` class provided by PubGrub by
7
+ # default and used by the most simple PubGrub consumers.
8
+ #
4
9
  class Resolver
5
- require_relative "vendored_molinillo"
6
- require_relative "resolver/spec_group"
10
+ require_relative "vendored_pub_grub"
11
+ require_relative "resolver/base"
12
+ require_relative "resolver/candidate"
13
+ require_relative "resolver/incompatibility"
14
+ require_relative "resolver/root"
7
15
 
8
16
  include GemHelpers
9
17
 
10
- # Figures out the best possible configuration of gems that satisfies
11
- # the list of passed dependencies and any child dependencies without
12
- # causing any gem activation errors.
13
- #
14
- # ==== Parameters
15
- # *dependencies<Gem::Dependency>:: The list of dependencies to resolve
16
- #
17
- # ==== Returns
18
- # <GemBundle>,nil:: If the list of dependencies can be resolved, a
19
- # collection of gemspecs is returned. Otherwise, nil is returned.
20
- def self.resolve(requirements, source_requirements = {}, base = [], gem_version_promoter = GemVersionPromoter.new, additional_base_requirements = [], platforms = nil)
21
- base = SpecSet.new(base) unless base.is_a?(SpecSet)
22
- resolver = new(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
23
- result = resolver.start(requirements)
24
- SpecSet.new(SpecSet.new(result).for(requirements.reject{|dep| dep.name.end_with?("\0") }))
25
- end
26
-
27
- def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
28
- @source_requirements = source_requirements
18
+ def initialize(base, gem_version_promoter)
19
+ @source_requirements = base.source_requirements
29
20
  @base = base
30
- @resolver = Molinillo::Resolver.new(self, self)
31
- @search_for = {}
32
- @base_dg = Molinillo::DependencyGraph.new
33
- @base.each do |ls|
34
- dep = Dependency.new(ls.name, ls.version)
35
- @base_dg.add_vertex(ls.name, DepProxy.get_proxy(dep, ls.platform), true)
36
- end
37
- additional_base_requirements.each {|d| @base_dg.add_vertex(d.name, d) }
38
- @platforms = platforms.reject {|p| p != Gem::Platform::RUBY && (platforms - [p]).any? {|pl| generic(pl) == p } }
39
- @resolving_only_for_ruby = platforms == [Gem::Platform::RUBY]
40
21
  @gem_version_promoter = gem_version_promoter
41
- @use_gvp = Bundler.feature_flag.use_gem_version_promoter_for_major_updates? || !@gem_version_promoter.major?
42
22
  end
43
23
 
44
- def start(requirements)
45
- @gem_version_promoter.prerelease_specified = @prerelease_specified = {}
46
- requirements.each {|dep| @prerelease_specified[dep.name] ||= dep.prerelease? }
47
-
48
- verify_gemfile_dependencies_are_found!(requirements)
49
- dg = @resolver.resolve(requirements, @base_dg)
50
- dg.
51
- map(&:payload).
52
- reject {|sg| sg.name.end_with?("\0") }.
53
- map(&:to_specs).
54
- flatten
55
- rescue Molinillo::VersionConflict => e
56
- message = version_conflict_message(e)
57
- raise VersionConflict.new(e.conflicts.keys.uniq, message)
58
- rescue Molinillo::CircularDependencyError => e
59
- names = e.dependencies.sort_by(&:name).map {|d| "gem '#{d.name}'" }
60
- raise CyclicDependencyError, "Your bundle requires gems that depend" \
61
- " on each other, creating an infinite loop. Please remove" \
62
- " #{names.count > 1 ? "either " : ""}#{names.join(" or ")}" \
63
- " and try again."
64
- end
24
+ def start
25
+ @requirements = @base.requirements
26
+ @packages = @base.packages
65
27
 
66
- include Molinillo::UI
67
-
68
- # Conveys debug information to the user.
69
- #
70
- # @param [Integer] depth the current depth of the resolution process.
71
- # @return [void]
72
- def debug(depth = 0)
73
- return unless debug?
74
- debug_info = yield
75
- debug_info = debug_info.inspect unless debug_info.is_a?(String)
76
- puts debug_info.split("\n").map {|s| depth == 0 ? "BUNDLER: #{s}" : "BUNDLER(#{depth}): #{s}" }
77
- end
28
+ root, logger = setup_solver
78
29
 
79
- def debug?
80
- return @debug_mode if defined?(@debug_mode)
81
- @debug_mode =
82
- ENV["BUNDLER_DEBUG_RESOLVER"] ||
83
- ENV["BUNDLER_DEBUG_RESOLVER_TREE"] ||
84
- ENV["DEBUG_RESOLVER"] ||
85
- ENV["DEBUG_RESOLVER_TREE"] ||
86
- false
87
- end
30
+ Bundler.ui.info "Resolving dependencies...", true
88
31
 
89
- def before_resolution
90
- Bundler.ui.info "Resolving dependencies...", debug?
32
+ solve_versions(:root => root, :logger => logger)
91
33
  end
92
34
 
93
- def after_resolution
94
- Bundler.ui.info ""
95
- end
35
+ def setup_solver
36
+ root = Resolver::Root.new(name_for_explicit_dependency_source)
37
+ root_version = Resolver::Candidate.new(0)
96
38
 
97
- def indicate_progress
98
- Bundler.ui.info ".", false unless debug?
99
- end
39
+ @all_specs = Hash.new do |specs, name|
40
+ specs[name] = source_for(name).specs.search(name).sort_by {|s| [s.version, s.platform.to_s] }
41
+ end
42
+
43
+ @sorted_versions = Hash.new do |candidates, package|
44
+ candidates[package] = if package.root?
45
+ [root_version]
46
+ else
47
+ all_versions_for(package).sort
48
+ end
49
+ end
100
50
 
101
- include Molinillo::SpecificationProvider
51
+ root_dependencies = prepare_dependencies(@requirements, @packages)
102
52
 
103
- def dependencies_for(specification)
104
- specification.dependencies_for_activated_platforms
53
+ @cached_dependencies = Hash.new do |dependencies, package|
54
+ dependencies[package] = if package.root?
55
+ { root_version => root_dependencies }
56
+ else
57
+ Hash.new do |versions, version|
58
+ versions[version] = to_dependency_hash(version.dependencies, @packages)
59
+ end
60
+ end
61
+ end
62
+
63
+ logger = Bundler::UI::Shell.new
64
+ logger.level = debug? ? "debug" : "warn"
65
+
66
+ [root, logger]
105
67
  end
106
68
 
107
- def search_for(dependency_proxy)
108
- platform = dependency_proxy.__platform
109
- dependency = dependency_proxy.dep
110
- name = dependency.name
111
- @search_for[dependency_proxy] ||= begin
112
- results = results_for(dependency, @base[name])
69
+ def solve_versions(root:, logger:)
70
+ solver = PubGrub::VersionSolver.new(:source => self, :root => root, :logger => logger)
71
+ result = solver.solve
72
+ result.map {|package, version| version.to_specs(package) }.flatten.uniq
73
+ rescue PubGrub::SolveFailure => e
74
+ incompatibility = e.incompatibility
75
+
76
+ names_to_unlock, names_to_allow_prereleases_for, extended_explanation = find_names_to_relax(incompatibility)
77
+
78
+ names_to_relax = names_to_unlock + names_to_allow_prereleases_for
113
79
 
114
- if vertex = @base_dg.vertex_named(name)
115
- locked_requirement = vertex.payload.requirement
80
+ if names_to_relax.any?
81
+ if names_to_unlock.any?
82
+ Bundler.ui.debug "Found conflicts with locked dependencies. Will retry with #{names_to_unlock.join(", ")} unlocked...", true
83
+
84
+ @base.unlock_names(names_to_unlock)
116
85
  end
117
86
 
118
- if !@prerelease_specified[name] && (!@use_gvp || locked_requirement.nil?)
119
- # Move prereleases to the beginning of the list, so they're considered
120
- # last during resolution.
121
- pre, results = results.partition {|spec| spec.version.prerelease? }
122
- results = pre + results
87
+ if names_to_allow_prereleases_for.any?
88
+ Bundler.ui.debug "Found conflicts with dependencies with prereleases. Will retrying considering prereleases for #{names_to_allow_prereleases_for.join(", ")}...", true
89
+
90
+ @base.include_prereleases(names_to_allow_prereleases_for)
123
91
  end
124
92
 
125
- spec_groups = if results.any?
126
- nested = []
127
- results.each do |spec|
128
- version, specs = nested.last
129
- if version == spec.version
130
- specs << spec
131
- else
132
- nested << [spec.version, [spec]]
133
- end
134
- end
135
- nested.reduce([]) do |groups, (version, specs)|
136
- next groups if locked_requirement && !locked_requirement.satisfied_by?(version)
137
- next groups unless specs.any? {|spec| spec.match_platform(platform) }
93
+ root, logger = setup_solver
94
+
95
+ Bundler.ui.debug "Retrying resolution...", true
96
+ retry
97
+ end
98
+
99
+ explanation = e.message
138
100
 
139
- specs_by_platform = Hash.new do |current_specs, current_platform|
140
- current_specs[current_platform] = select_best_platform_match(specs, current_platform)
141
- end
101
+ if extended_explanation
102
+ explanation << "\n\n"
103
+ explanation << extended_explanation
104
+ end
142
105
 
143
- spec_group_ruby = SpecGroup.create_for(specs_by_platform, [Gem::Platform::RUBY], Gem::Platform::RUBY)
144
- groups << spec_group_ruby if spec_group_ruby
106
+ raise SolveFailure.new(explanation)
107
+ end
145
108
 
146
- next groups if @resolving_only_for_ruby
109
+ def find_names_to_relax(incompatibility)
110
+ names_to_unlock = []
111
+ names_to_allow_prereleases_for = []
112
+ extended_explanation = nil
147
113
 
148
- spec_group = SpecGroup.create_for(specs_by_platform, @platforms, platform)
149
- groups << spec_group
114
+ while incompatibility.conflict?
115
+ cause = incompatibility.cause
116
+ incompatibility = cause.incompatibility
150
117
 
151
- groups
118
+ incompatibility.terms.each do |term|
119
+ package = term.package
120
+ name = package.name
121
+
122
+ if base_requirements[name]
123
+ names_to_unlock << name
124
+ elsif package.ignores_prereleases?
125
+ names_to_allow_prereleases_for << name
152
126
  end
153
- else
154
- []
155
- end
156
- # GVP handles major itself, but it's still a bit risky to trust it with it
157
- # until we get it settled with new behavior. For 2.x it can take over all cases.
158
- if !@use_gvp
159
- spec_groups
160
- else
161
- @gem_version_promoter.sort_versions(dependency, spec_groups)
127
+
128
+ no_versions_incompat = [cause.incompatibility, cause.satisfier].find {|incompat| incompat.cause.is_a?(PubGrub::Incompatibility::NoVersions) }
129
+ next unless no_versions_incompat
130
+
131
+ extended_explanation = no_versions_incompat.extended_explanation
162
132
  end
163
133
  end
164
- end
165
134
 
166
- def index_for(dependency)
167
- source_for(dependency.name).specs
135
+ [names_to_unlock.uniq, names_to_allow_prereleases_for.uniq, extended_explanation]
168
136
  end
169
137
 
170
- def source_for(name)
171
- @source_requirements[name] || @source_requirements[:default]
172
- end
138
+ def parse_dependency(package, dependency)
139
+ range = if repository_for(package).is_a?(Source::Gemspec)
140
+ PubGrub::VersionRange.any
141
+ else
142
+ requirement_to_range(dependency)
143
+ end
173
144
 
174
- def results_for(dependency, base)
175
- index_for(dependency).search(dependency, base)
145
+ PubGrub::VersionConstraint.new(package, :range => range)
176
146
  end
177
147
 
178
- def name_for(dependency)
179
- dependency.name
180
- end
148
+ def versions_for(package, range=VersionRange.any)
149
+ versions = range.select_versions(@sorted_versions[package])
181
150
 
182
- def name_for_explicit_dependency_source
183
- Bundler.default_gemfile.basename.to_s
184
- rescue StandardError
185
- "Gemfile"
151
+ sort_versions(package, versions)
186
152
  end
187
153
 
188
- def name_for_locking_dependency_source
189
- Bundler.default_lockfile.basename.to_s
190
- rescue StandardError
191
- "Gemfile.lock"
192
- end
154
+ def no_versions_incompatibility_for(package, unsatisfied_term)
155
+ cause = PubGrub::Incompatibility::NoVersions.new(unsatisfied_term)
156
+ name = package.name
157
+ constraint = unsatisfied_term.constraint
158
+ constraint_string = constraint.constraint_string
159
+ requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) }
193
160
 
194
- def requirement_satisfied_by?(requirement, activated, spec)
195
- requirement.matches_spec?(spec) || spec.source.is_a?(Source::Gemspec)
196
- end
161
+ if name == "bundler"
162
+ custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}"
163
+ extended_explanation = bundler_not_found_message(requirements)
164
+ else
165
+ specs_matching_other_platforms = filter_matching_specs(@all_specs[name], requirements)
197
166
 
198
- def dependencies_equal?(dependencies, other_dependencies)
199
- dependencies.map(&:dep) == other_dependencies.map(&:dep)
200
- end
167
+ platforms_explanation = specs_matching_other_platforms.any? ? " for any resolution platforms (#{package.platforms.join(", ")})" : ""
168
+ custom_explanation = "#{constraint} could not be found in #{repository_for(package)}#{platforms_explanation}"
201
169
 
202
- def sort_dependencies(dependencies, activated, conflicts)
203
- dependencies.sort_by do |dependency|
204
- name = name_for(dependency)
205
- vertex = activated.vertex_named(name)
206
- [
207
- @base_dg.vertex_named(name) ? 0 : 1,
208
- vertex.payload ? 0 : 1,
209
- vertex.root? ? 0 : 1,
210
- amount_constrained(dependency),
211
- conflicts[name] ? 0 : 1,
212
- vertex.payload ? 0 : search_for(dependency).count,
213
- self.class.platform_sort_key(dependency.__platform),
214
- ]
170
+ label = "#{name} (#{constraint_string})"
171
+ extended_explanation = other_specs_matching_message(specs_matching_other_platforms, label) if specs_matching_other_platforms.any?
215
172
  end
173
+
174
+ Incompatibility.new([unsatisfied_term], :cause => cause, :custom_explanation => custom_explanation, :extended_explanation => extended_explanation)
216
175
  end
217
176
 
218
- def self.platform_sort_key(platform)
219
- # Prefer specific platform to not specific platform
220
- return ["99-LAST", "", "", ""] if Gem::Platform::RUBY == platform
221
- ["00", *platform.to_a.map {|part| part || "" }]
177
+ def debug?
178
+ ENV["BUNDLER_DEBUG_RESOLVER"] ||
179
+ ENV["BUNDLER_DEBUG_RESOLVER_TREE"] ||
180
+ ENV["DEBUG_RESOLVER"] ||
181
+ ENV["DEBUG_RESOLVER_TREE"] ||
182
+ false
222
183
  end
223
184
 
224
- private
185
+ def incompatibilities_for(package, version)
186
+ package_deps = @cached_dependencies[package]
187
+ sorted_versions = @sorted_versions[package]
188
+ package_deps[version].map do |dep_package, dep_constraint|
189
+ if package == dep_package
190
+ cause = PubGrub::Incompatibility::CircularDependency.new(dep_package, dep_constraint.constraint_string)
191
+ return [PubGrub::Incompatibility.new([PubGrub::Term.new(dep_constraint, true)], :cause => cause)]
192
+ end
225
193
 
226
- # returns an integer \in (-\infty, 0]
227
- # a number closer to 0 means the dependency is less constraining
228
- #
229
- # dependencies w/ 0 or 1 possibilities (ignoring version requirements)
230
- # are given very negative values, so they _always_ sort first,
231
- # before dependencies that are unconstrained
232
- def amount_constrained(dependency)
233
- @amount_constrained ||= {}
234
- @amount_constrained[dependency.name] ||= begin
235
- if (base = @base[dependency.name]) && !base.empty?
236
- dependency.requirement.satisfied_by?(base.first.version) ? 0 : 1
237
- else
238
- all = index_for(dependency).search(dependency.name).size
194
+ low = high = sorted_versions.index(version)
195
+
196
+ # find version low such that all >= low share the same dep
197
+ while low > 0 && package_deps[sorted_versions[low - 1]][dep_package] == dep_constraint
198
+ low -= 1
199
+ end
200
+ low =
201
+ if low == 0
202
+ nil
203
+ else
204
+ sorted_versions[low]
205
+ end
239
206
 
240
- if all <= 1
241
- all - 1_000_000
207
+ # find version high such that all < high share the same dep
208
+ while high < sorted_versions.length && package_deps[sorted_versions[high]][dep_package] == dep_constraint
209
+ high += 1
210
+ end
211
+ high =
212
+ if high == sorted_versions.length
213
+ nil
242
214
  else
243
- search = search_for(dependency)
244
- search = @prerelease_specified[dependency.name] ? search.count : search.count {|s| !s.version.prerelease? }
245
- search - all
215
+ sorted_versions[high]
246
216
  end
217
+
218
+ range = PubGrub::VersionRange.new(:min => low, :max => high, :include_min => true)
219
+
220
+ self_constraint = PubGrub::VersionConstraint.new(package, :range => range)
221
+
222
+ dep_term = PubGrub::Term.new(dep_constraint, false)
223
+ self_term = PubGrub::Term.new(self_constraint, true)
224
+
225
+ custom_explanation = if dep_package.meta? && package.root?
226
+ "current #{dep_package} version is #{dep_constraint.constraint_string}"
247
227
  end
228
+
229
+ PubGrub::Incompatibility.new([self_term, dep_term], :cause => :dependency, :custom_explanation => custom_explanation)
248
230
  end
249
231
  end
250
232
 
251
- def verify_gemfile_dependencies_are_found!(requirements)
252
- requirements.map! do |requirement|
253
- name = requirement.name
254
- next requirement if name == "bundler"
255
- next requirement unless search_for(requirement).empty?
256
- next unless requirement.current_platform?
257
-
258
- if (base = @base[name]) && !base.empty?
259
- version = base.first.version
260
- message = "You have requested:\n" \
261
- " #{name} #{requirement.requirement}\n\n" \
262
- "The bundle currently has #{name} locked at #{version}.\n" \
263
- "Try running `bundle update #{name}`\n\n" \
264
- "If you are updating multiple gems in your Gemfile at once,\n" \
265
- "try passing them all to `bundle update`"
266
- else
267
- message = gem_not_found_message(name, requirement, source_for(name))
268
- end
269
- raise GemNotFound, message
270
- end.compact!
233
+ def all_versions_for(package)
234
+ name = package.name
235
+ results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] }
236
+ locked_requirement = base_requirements[name]
237
+ results = filter_matching_specs(results, locked_requirement) if locked_requirement
238
+
239
+ versions = results.group_by(&:version).reduce([]) do |groups, (version, specs)|
240
+ platform_specs = package.platforms.flat_map {|platform| select_best_platform_match(specs, platform) }
241
+ next groups if platform_specs.empty?
242
+
243
+ ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY)
244
+ groups << Resolver::Candidate.new(version, :specs => ruby_specs) if ruby_specs.any?
245
+
246
+ next groups if platform_specs == ruby_specs
247
+
248
+ groups << Resolver::Candidate.new(version, :specs => platform_specs)
249
+
250
+ groups
251
+ end
252
+
253
+ sort_versions(package, versions)
271
254
  end
272
255
 
273
- def gem_not_found_message(name, requirement, source, extra_message = "")
274
- specs = source.specs.search(name)
256
+ def source_for(name)
257
+ @source_requirements[name] || @source_requirements[:default]
258
+ end
259
+
260
+ def name_for_explicit_dependency_source
261
+ Bundler.default_gemfile.basename.to_s
262
+ rescue StandardError
263
+ "Gemfile"
264
+ end
265
+
266
+ def raise_not_found!(package)
267
+ name = package.name
268
+ source = source_for(name)
269
+ specs = @all_specs[name]
275
270
  matching_part = name
276
- requirement_label = SharedHelpers.pretty_dependency(requirement)
271
+ requirement_label = SharedHelpers.pretty_dependency(package.dependency)
277
272
  cache_message = begin
278
273
  " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
279
274
  rescue GemfileNotFound
280
275
  nil
281
276
  end
282
- specs_matching_requirement = specs.select {| spec| requirement.matches_spec?(spec) }
277
+ specs_matching_requirement = filter_matching_specs(specs, package.dependency.requirement)
283
278
 
284
279
  if specs_matching_requirement.any?
285
280
  specs = specs_matching_requirement
286
281
  matching_part = requirement_label
287
- requirement_label = "#{requirement_label} #{requirement.__platform}"
282
+ platforms = package.platforms
283
+ platform_label = platforms.size == 1 ? "platform '#{platforms.first}" : "platforms '#{platforms.join("', '")}"
284
+ requirement_label = "#{requirement_label}' with #{platform_label}"
288
285
  end
289
286
 
290
- message = String.new("Could not find gem '#{requirement_label}'#{extra_message} in #{source}#{cache_message}.\n")
287
+ message = String.new("Could not find gem '#{requirement_label}' in #{source}#{cache_message}.\n")
291
288
 
292
289
  if specs.any?
293
- message << "\nThe source contains the following gems matching '#{matching_part}':\n"
294
- message << specs.map {|s| " * #{s.full_name}" }.join("\n")
290
+ message << "\n#{other_specs_matching_message(specs, matching_part)}"
295
291
  end
296
292
 
297
- message
293
+ raise GemNotFound, message
294
+ end
295
+
296
+ private
297
+
298
+ def filter_matching_specs(specs, requirements)
299
+ Array(requirements).flat_map do |requirement|
300
+ specs.select {| spec| requirement_satisfied_by?(requirement, spec) }
301
+ end
298
302
  end
299
303
 
300
- def version_conflict_message(e)
301
- # only show essential conflicts, if possible
302
- conflicts = e.conflicts.dup
304
+ def filter_prereleases(specs, package)
305
+ return specs unless package.ignores_prereleases?
303
306
 
304
- if conflicts["bundler"]
305
- conflicts.replace("bundler" => conflicts["bundler"])
307
+ specs.reject {|s| s.version.prerelease? }
308
+ end
309
+
310
+ def requirement_satisfied_by?(requirement, spec)
311
+ requirement.satisfied_by?(spec.version) || spec.source.is_a?(Source::Gemspec)
312
+ end
313
+
314
+ def sort_versions(package, versions)
315
+ if versions.size > 1
316
+ @gem_version_promoter.sort_versions(package, versions).reverse
306
317
  else
307
- conflicts.delete_if do |_name, conflict|
308
- deps = conflict.requirement_trees.map(&:last).flatten(1)
309
- !Bundler::VersionRanges.empty?(*Bundler::VersionRanges.for_many(deps.map(&:requirement)))
310
- end
318
+ versions
311
319
  end
320
+ end
312
321
 
313
- e = Molinillo::VersionConflict.new(conflicts, e.specification_provider) unless conflicts.empty?
322
+ def repository_for(package)
323
+ source_for(package.name)
324
+ end
314
325
 
315
- e.message_with_trees(
316
- :full_message_for_conflict => lambda do |name, conflict|
317
- o = if name.end_with?("\0")
318
- String.new("Bundler found conflicting requirements for the #{name} version:")
319
- else
320
- String.new("Bundler could not find compatible versions for gem \"#{name}\":")
321
- end
322
- o << %(\n)
323
- if conflict.locked_requirement
324
- o << %( In snapshot (#{name_for_locking_dependency_source}):\n)
325
- o << %( #{SharedHelpers.pretty_dependency(conflict.locked_requirement)}\n)
326
- o << %(\n)
327
- end
328
- o << %( In #{name_for_explicit_dependency_source}:\n)
329
- trees = conflict.requirement_trees
326
+ def base_requirements
327
+ @base.base_requirements
328
+ end
330
329
 
331
- # called first, because we want to reduce the amount of work required to find maximal empty sets
332
- trees = trees.uniq {|t| t.flatten.map {|dep| [dep.name, dep.requirement] } }
330
+ def prepare_dependencies(requirements, packages)
331
+ to_dependency_hash(requirements, packages).map do |dep_package, dep_constraint|
332
+ name = dep_package.name
333
333
 
334
- # bail out if tree size is too big for Array#combination to make any sense
335
- if trees.size <= 15
336
- maximal = 1.upto(trees.size).map do |size|
337
- trees.map(&:last).flatten(1).combination(size).to_a
338
- end.flatten(1).select do |deps|
339
- Bundler::VersionRanges.empty?(*Bundler::VersionRanges.for_many(deps.map(&:requirement)))
340
- end.min_by(&:size)
334
+ next [dep_package, dep_constraint] if name == "bundler"
341
335
 
342
- trees.reject! {|t| !maximal.include?(t.last) } if maximal
336
+ versions = versions_for(dep_package, dep_constraint.range)
337
+ if versions.empty? && dep_package.ignores_prereleases?
338
+ @sorted_versions.delete(dep_package)
339
+ dep_package.consider_prereleases!
340
+ versions = versions_for(dep_package, dep_constraint.range)
341
+ end
342
+ next [dep_package, dep_constraint] unless versions.empty?
343
343
 
344
- trees.sort_by! {|t| t.reverse.map(&:name) }
345
- end
344
+ next unless dep_package.current_platform?
346
345
 
347
- metadata_requirements = {}
348
-
349
- o << trees.map do |tree|
350
- t = "".dup
351
- depth = 2
352
-
353
- base_tree = tree.first
354
- base_tree_name = base_tree.name
355
-
356
- if base_tree_name.end_with?("\0")
357
- metadata_requirements[base_tree_name] = base_tree
358
- t = nil
359
- else
360
- tree.each do |req|
361
- t << " " * depth << SharedHelpers.pretty_dependency(req)
362
- unless tree.last == req
363
- if spec = conflict.activated_by_name[req.name]
364
- t << %( was resolved to #{spec.version}, which)
365
- end
366
- t << %( depends on)
367
- end
368
- t << %(\n)
369
- depth += 1
370
- end
371
- end
372
- t
373
- end.compact.join("\n")
374
-
375
- if name == "bundler"
376
- o << %(\n Current Bundler version:\n bundler (#{Bundler::VERSION}))
377
-
378
- conflict_dependency = conflict.requirement
379
- conflict_requirement = conflict_dependency.requirement
380
- other_bundler_required = !conflict_requirement.satisfied_by?(Gem::Version.new(Bundler::VERSION))
381
-
382
- if other_bundler_required
383
- o << "\n\n"
384
-
385
- candidate_specs = source_for(:default_bundler).specs.search(conflict_dependency)
386
- if candidate_specs.any?
387
- target_version = candidate_specs.last.version
388
- new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ")
389
- o << "Your bundle requires a different version of Bundler than the one you're running.\n"
390
- o << "Install the necessary version with `gem install bundler:#{target_version}` and rerun bundler using `#{new_command}`\n"
391
- else
392
- o << "Your bundle requires a different version of Bundler than the one you're running, and that version could not be found.\n"
393
- end
394
- end
395
- elsif name.end_with?("\0")
396
- o << %(\n Current #{name} version:\n #{SharedHelpers.pretty_dependency(metadata_requirements[name])}\n\n)
397
- elsif conflict.locked_requirement
398
- o << "\n"
399
- o << %(Running `bundle update` will rebuild your snapshot from scratch, using only\n)
400
- o << %(the gems in your Gemfile, which may resolve the conflict.\n)
401
- elsif !conflict.existing
402
- o << "\n"
403
-
404
- relevant_source = conflict.requirement.source || source_for(name)
405
-
406
- extra_message = if conflict.requirement_trees.first.size > 1
407
- ", which is required by gem '#{SharedHelpers.pretty_dependency(conflict.requirement_trees.first[-2])}',"
408
- else
409
- ""
410
- end
411
-
412
- o << gem_not_found_message(name, conflict.requirement, relevant_source, extra_message)
413
- end
346
+ raise_not_found!(dep_package)
347
+ end.compact.to_h
348
+ end
349
+
350
+ def other_specs_matching_message(specs, requirement)
351
+ message = String.new("The source contains the following gems matching '#{requirement}':\n")
352
+ message << specs.map {|s| " * #{s.full_name}" }.join("\n")
353
+ message
354
+ end
414
355
 
415
- o
356
+ def requirement_to_range(requirement)
357
+ ranges = requirement.requirements.map do |(op, version)|
358
+ ver = Resolver::Candidate.new(version).generic!
359
+ platform_ver = Resolver::Candidate.new(version).platform_specific!
360
+
361
+ case op
362
+ when "~>"
363
+ name = "~> #{ver}"
364
+ bump = Resolver::Candidate.new(version.bump.to_s + ".A")
365
+ PubGrub::VersionRange.new(:name => name, :min => ver, :max => bump, :include_min => true)
366
+ when ">"
367
+ PubGrub::VersionRange.new(:min => platform_ver)
368
+ when ">="
369
+ PubGrub::VersionRange.new(:min => ver, :include_min => true)
370
+ when "<"
371
+ PubGrub::VersionRange.new(:max => ver)
372
+ when "<="
373
+ PubGrub::VersionRange.new(:max => platform_ver, :include_max => true)
374
+ when "="
375
+ PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true)
376
+ when "!="
377
+ PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true).invert
378
+ else
379
+ raise "bad version specifier: #{op}"
380
+ end
381
+ end
382
+
383
+ ranges.inject(&:intersect)
384
+ end
385
+
386
+ def to_dependency_hash(dependencies, packages)
387
+ dependencies.inject({}) do |deps, dep|
388
+ package = packages[dep.name]
389
+
390
+ current_req = deps[package]
391
+ new_req = parse_dependency(package, dep.requirement)
392
+
393
+ deps[package] = if current_req
394
+ current_req.intersect(new_req)
395
+ else
396
+ new_req
416
397
  end
417
- )
398
+
399
+ deps
400
+ end
401
+ end
402
+
403
+ def bundler_not_found_message(conflict_dependencies)
404
+ candidate_specs = filter_matching_specs(source_for(:default_bundler).specs.search("bundler"), conflict_dependencies)
405
+
406
+ if candidate_specs.any?
407
+ target_version = candidate_specs.last.version
408
+ new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ")
409
+ "Your bundle requires a different version of Bundler than the one you're running.\n" \
410
+ "Install the necessary version with `gem install bundler:#{target_version}` and rerun bundler using `#{new_command}`\n"
411
+ else
412
+ "Your bundle requires a different version of Bundler than the one you're running, and that version could not be found.\n"
413
+ end
418
414
  end
419
415
  end
420
416
  end