Class: Gem::Platform
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/bundler/rubygems_ext.rb |
Constant Summary
-
GENERICS =
private
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 68[JAVA, *WINDOWS].freeze
-
GENERIC_CACHE =
private
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 71GENERICS.each_with_object({}) {|g, h| h[g] = g }
-
JAVA =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 57Gem::Platform.new("java")
-
MINGW =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 60Gem::Platform.new("x86-mingw32")
-
MSWIN =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 58Gem::Platform.new("mswin32")
-
MSWIN64 =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 59Gem::Platform.new("mswin64")
-
UNIVERSAL_MINGW =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 63Gem::Platform.new("universal-mingw")
-
WINDOWS =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 64[MSWIN, MSWIN64, UNIVERSAL_MINGW].freeze
-
X64_LINUX =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 65Gem::Platform.new("x86_64-linux")
-
X64_LINUX_MUSL =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 66Gem::Platform.new("x86_64-linux-musl")
-
X64_MINGW =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 62Gem::Platform.new("x64-mingw-ucrt")
-
X64_MINGW_LEGACY =
Internal use only
# File 'lib/bundler/rubygems_ext.rb', line 61Gem::Platform.new("x64-mingw32")
Class Method Summary
-
.generic(platform)
Returns the generic platform for the given platform.
-
.platform_specificity_match(spec_platform, user_platform)
Returns the platform specificity match for the given spec platform and user platform.
-
.sort_and_filter_best_platform_match(matching, platform)
Sorts and filters the best platform match for the given matching specs and platform.
-
.sort_best_platform_match(matching, platform)
Sorts the best platform match for the given matching specs and platform.
- .cpu_match(spec_platform, user_platform) private
- .os_match(spec_platform, user_platform) private
- .same_deps?(spec, exemplary_spec) ⇒ Boolean private
- .same_specificity?(platform, spec, exemplary_spec) ⇒ Boolean private
- .version_match(spec_platform, user_platform) private
Class Method Details
.cpu_match(spec_platform, user_platform) (private)
[ GitHub ]# File 'lib/bundler/rubygems_ext.rb', line 148
def cpu_match(spec_platform, user_platform) if spec_platform.cpu == user_platform.cpu 0 elsif spec_platform.cpu == "arm" && user_platform.cpu.to_s.start_with?("arm") 0 elsif spec_platform.cpu.nil? || spec_platform.cpu == "universal" 1 else 2 end end
.generic(platform)
Returns the generic platform for the given platform.
# File 'lib/bundler/rubygems_ext.rb', line 78
def generic(platform) return Gem::Platform::RUBY if platform.nil? || platform == Gem::Platform::RUBY GENERIC_CACHE[platform] ||= begin found = GENERICS.find do |match| platform === match end found || Gem::Platform::RUBY end end
.os_match(spec_platform, user_platform) (private)
[ GitHub ]# File 'lib/bundler/rubygems_ext.rb', line 140
def os_match(spec_platform, user_platform) if spec_platform.os == user_platform.os 0 else 1 end end
.platform_specificity_match(spec_platform, user_platform)
Returns the platform specificity match for the given spec platform and user platform.
# File 'lib/bundler/rubygems_ext.rb', line 92
def platform_specificity_match(spec_platform, user_platform) return -1 if spec_platform == user_platform return 1_000_000 if spec_platform.nil? || spec_platform == Gem::Platform::RUBY || user_platform == Gem::Platform::RUBY os_match(spec_platform, user_platform) + cpu_match(spec_platform, user_platform) * 10 + version_match(spec_platform, user_platform) * 100 end
.same_deps?(spec, exemplary_spec) ⇒ Boolean
(private)
# File 'lib/bundler/rubygems_ext.rb', line 134
def same_deps?(spec, exemplary_spec) spec.required_ruby_version == exemplary_spec.required_ruby_version && spec.required_rubygems_version == exemplary_spec.required_rubygems_version && spec.dependencies.sort == exemplary_spec.dependencies.sort end
.same_specificity?(platform, spec, exemplary_spec) ⇒ Boolean
(private)
# File 'lib/bundler/rubygems_ext.rb', line 130
def same_specificity?(platform, spec, exemplary_spec) platform_specificity_match(spec.platform, platform) == platform_specificity_match(exemplary_spec.platform, platform) end
.sort_and_filter_best_platform_match(matching, platform)
Sorts and filters the best platform match for the given matching specs and platform.
# File 'lib/bundler/rubygems_ext.rb', line 104
def sort_and_filter_best_platform_match(matching, platform) return matching if matching.one? exact = matching.select {|spec| spec.platform == platform } return exact if exact.any? sorted_matching = sort_best_platform_match(matching, platform) exemplary_spec = sorted_matching.first sorted_matching.take_while {|spec| same_specificity?(platform, spec, exemplary_spec) && same_deps?(spec, exemplary_spec) } end
.sort_best_platform_match(matching, platform)
Sorts the best platform match for the given matching specs and platform.
# File 'lib/bundler/rubygems_ext.rb', line 119
def sort_best_platform_match(matching, platform) matching.sort_by.with_index do |spec, i| [ platform_specificity_match(spec.platform, platform), i, # for stable sort ] end end
.version_match(spec_platform, user_platform) (private)
[ GitHub ]# File 'lib/bundler/rubygems_ext.rb', line 160
def version_match(spec_platform, user_platform) if spec_platform.version == user_platform.version 0 elsif spec_platform.version.nil? 1 else 2 end end