Module: Bundler::GemHelpers

Included in:
Definition, MatchPlatform, Resolver
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("x64-mingw-ucrt"), Gem::Platform.new("x64-mingw-ucrt")],
  [Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")],
].freeze

Class Method Summary collapse

Class Method Details

.force_ruby_platform(specs) ⇒ Object



56
57
58
59
60
# File 'lib/bundler/gem_helpers.rb', line 56

def force_ruby_platform(specs)
  matching = specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! }

  sort_best_platform_match(matching, Gem::Platform::RUBY)
end

.generic(p) ⇒ Object



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

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



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

def generic_local_platform
  generic(local_platform)
end

.generic_local_platform_is_ruby?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/bundler/gem_helpers.rb', line 37

def generic_local_platform_is_ruby?
  generic_local_platform == Gem::Platform::RUBY
end

.local_platformObject



32
33
34
# File 'lib/bundler/gem_helpers.rb', line 32

def local_platform
  Bundler.local_platform
end

.platform_specificity_match(spec_platform, user_platform) ⇒ Object



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

def platform_specificity_match(spec_platform, user_platform)
  spec_platform = Gem::Platform.new(spec_platform)

  PlatformMatch.specificity_score(spec_platform, user_platform)
end

.same_deps(spec, exemplary_spec) ⇒ Object



120
121
122
123
124
# File 'lib/bundler/gem_helpers.rb', line 120

def same_deps(spec, exemplary_spec)
  same_runtime_deps = spec.dependencies.sort == exemplary_spec.dependencies.sort
   = spec.required_ruby_version == exemplary_spec.required_ruby_version && spec.required_rubygems_version == exemplary_spec.required_rubygems_version
  same_runtime_deps && 
end

.same_specificity(platform, spec, exemplary_spec) ⇒ Object



115
116
117
# File 'lib/bundler/gem_helpers.rb', line 115

def same_specificity(platform, spec, exemplary_spec)
  platform_specificity_match(spec.platform, platform) == platform_specificity_match(exemplary_spec.platform, platform)
end

.select_best_platform_match(specs, platform) ⇒ Object



49
50
51
52
53
# File 'lib/bundler/gem_helpers.rb', line 49

def select_best_platform_match(specs, platform)
  matching = specs.select {|spec| spec.match_platform(platform) }

  sort_best_platform_match(matching, platform)
end

.sort_best_platform_match(matching, platform) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/bundler/gem_helpers.rb', line 63

def sort_best_platform_match(matching, platform)
  exact = matching.select {|spec| spec.platform == platform }
  return exact if exact.any?

  sorted_matching = matching.sort_by {|spec| platform_specificity_match(spec.platform, platform) }
  exemplary_spec = sorted_matching.first

  sorted_matching.take_while {|spec| same_specificity(platform, spec, exemplary_spec) && same_deps(spec, exemplary_spec) }
end