Method: Bundler::PubGrub::BasicPackageSource#incompatibilities_for

Defined in:
lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb

#incompatibilities_for(package, version) ⇒ Object

[View source]

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb', line 137

def incompatibilities_for(package, version)
  package_deps = @cached_dependencies[package]
  sorted_versions = @sorted_versions[package]
  package_deps[version].map do |dep_package, dep_constraint_name|
    low = high = sorted_versions.index(version)

    # find version low such that all >= low share the same dep
    while low > 0 &&
        package_deps[sorted_versions[low - 1]][dep_package] == dep_constraint_name
      low -= 1
    end
    low =
      if low == 0
        nil
      else
        sorted_versions[low]
      end

    # find version high such that all < high share the same dep
    while high < sorted_versions.length &&
        package_deps[sorted_versions[high]][dep_package] == dep_constraint_name
      high += 1
    end
    high =
      if high == sorted_versions.length
        nil
      else
        sorted_versions[high]
      end

    range = VersionRange.new(min: low, max: high, include_min: true)

    self_constraint = VersionConstraint.new(package, range: range)

    if !@packages.include?(dep_package)
      # no such package -> this version is invalid
    end

    dep_constraint = parse_dependency(dep_package, dep_constraint_name)
    if !dep_constraint
      # falsey indicates this dependency was invalid
      cause = Bundler::PubGrub::Incompatibility::InvalidDependency.new(dep_package, dep_constraint_name)
      return [Incompatibility.new([Term.new(self_constraint, true)], cause: cause)]
    elsif !dep_constraint.is_a?(VersionConstraint)
      # Upgrade range/union to VersionConstraint
      dep_constraint = VersionConstraint.new(dep_package, range: dep_constraint)
    end

    Incompatibility.new([Term.new(self_constraint, true), Term.new(dep_constraint, false)], cause: :dependency)
  end
end