Module: Bundler::GemHelpers

Included in:
Definition, MatchPlatform, Resolver::SpecGroup
Defined in:
lib/bundler/gem_helpers.rb

Defined Under Namespace

Classes: PlatformMatch

Constant Summary collapse

GENERIC_CACHE =

rubocop:disable Style/MutableConstant

{ Gem::Platform::RUBY => Gem::Platform::RUBY }
GENERICS =
[
  [Gem::Platform.new("java"), Gem::Platform.new("java")],
  [Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")],
  [Gem::Platform.new("mswin64"), Gem::Platform.new("mswin64")],
  [Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")],
  [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")],
  [Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")],
  [Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")],
].freeze

Class Method Summary collapse

Class Method Details

.generic(p) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/bundler/gem_helpers.rb', line 16

def generic(p)
  GENERIC_CACHE[p] ||= begin
    _, found = GENERICS.find do |match, _generic|
      p.os == match.os && (!match.cpu || p.cpu == match.cpu)
    end
    found || Gem::Platform::RUBY
  end
end

.generic_local_platformObject



26
27
28
# File 'lib/bundler/gem_helpers.rb', line 26

def generic_local_platform
  generic(Bundler.local_platform)
end

.platform_specificity_match(spec_platform, user_platform) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bundler/gem_helpers.rb', line 31

def platform_specificity_match(spec_platform, user_platform)
  spec_platform = Gem::Platform.new(spec_platform)
  return PlatformMatch::EXACT_MATCH if spec_platform == user_platform
  return PlatformMatch::WORST_MATCH if spec_platform.nil? || spec_platform == Gem::Platform::RUBY || user_platform == Gem::Platform::RUBY

  PlatformMatch.new(
    PlatformMatch.os_match(spec_platform, user_platform),
    PlatformMatch.cpu_match(spec_platform, user_platform),
    PlatformMatch.platform_version_match(spec_platform, user_platform)
  )
end

.select_best_platform_match(specs, platform) ⇒ Object



44
45
46
47
# File 'lib/bundler/gem_helpers.rb', line 44

def select_best_platform_match(specs, platform)
  specs.select {|spec| spec.match_platform(platform) }.
    min_by {|spec| platform_specificity_match(spec.platform, platform) }
end