mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
8598f8c2dc
rubygems 2.7.x depends bundler-1.15.x. This is preparation for rubygems and bundler migration. * lib/bundler.rb, lib/bundler/*: files of bundler-1.15.4 * spec/bundler/*: rspec examples of bundler-1.15.4. I applied patches. * https://github.com/bundler/bundler/pull/6007 * Exclude not working examples on ruby repository. * Fake ruby interpriter instead of installed ruby. * Makefile.in: Added test task named `test-bundler`. This task is only working macOS/linux yet. I'm going to support Windows environment later. * tool/sync_default_gems.rb: Added sync task for bundler. [Feature #12733][ruby-core:77172] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
75 lines
2.9 KiB
Ruby
75 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
module Bundler
|
|
module VersionRanges
|
|
NEq = Struct.new(:version)
|
|
ReqR = Struct.new(:left, :right)
|
|
class ReqR
|
|
Endpoint = Struct.new(:version, :inclusive)
|
|
def to_s
|
|
"#{left.inclusive ? "[" : "("}#{left.version}, #{right.version}#{right.inclusive ? "]" : ")"}"
|
|
end
|
|
INFINITY = Object.new.freeze
|
|
ZERO = Gem::Version.new("0.a")
|
|
|
|
def cover?(v)
|
|
return false if left.inclusive && left.version > v
|
|
return false if !left.inclusive && left.version >= v
|
|
|
|
if right.version != INFINITY
|
|
return false if right.inclusive && right.version < v
|
|
return false if !right.inclusive && right.version <= v
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
def empty?
|
|
left.version == right.version && !(left.inclusive && right.inclusive)
|
|
end
|
|
|
|
def single?
|
|
left.version == right.version
|
|
end
|
|
|
|
UNIVERSAL = ReqR.new(ReqR::Endpoint.new(Gem::Version.new("0.a"), true), ReqR::Endpoint.new(ReqR::INFINITY, false)).freeze
|
|
end
|
|
|
|
def self.for_many(requirements)
|
|
requirements = requirements.map(&:requirements).flatten(1).map {|r| r.join(" ") }
|
|
requirements << ">= 0.a" if requirements.empty?
|
|
requirement = Gem::Requirement.new(requirements)
|
|
self.for(requirement)
|
|
end
|
|
|
|
def self.for(requirement)
|
|
ranges = requirement.requirements.map do |op, v|
|
|
case op
|
|
when "=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v, true))
|
|
when "!=" then NEq.new(v)
|
|
when ">=" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(ReqR::INFINITY, false))
|
|
when ">" then ReqR.new(ReqR::Endpoint.new(v, false), ReqR::Endpoint.new(ReqR::INFINITY, false))
|
|
when "<" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, false))
|
|
when "<=" then ReqR.new(ReqR::Endpoint.new(ReqR::ZERO, true), ReqR::Endpoint.new(v, true))
|
|
when "~>" then ReqR.new(ReqR::Endpoint.new(v, true), ReqR::Endpoint.new(v.bump, false))
|
|
else raise "unknown version op #{op} in requirement #{requirement}"
|
|
end
|
|
end.uniq
|
|
ranges, neqs = ranges.partition {|r| !r.is_a?(NEq) }
|
|
|
|
[ranges.sort_by {|range| [range.left.version, range.left.inclusive ? 0 : 1] }, neqs.map(&:version)]
|
|
end
|
|
|
|
def self.empty?(ranges, neqs)
|
|
!ranges.reduce(ReqR::UNIVERSAL) do |last_range, curr_range|
|
|
next false unless last_range
|
|
next false if curr_range.single? && neqs.include?(curr_range.left.version)
|
|
next curr_range if last_range.right.version == ReqR::INFINITY
|
|
case last_range.right.version <=> curr_range.left.version
|
|
when 1 then next curr_range
|
|
when 0 then next(last_range.right.inclusive && curr_range.left.inclusive && !neqs.include?(curr_range.left.version) && curr_range)
|
|
when -1 then next false
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|