PHP 8.2.31
Preview: gem_helpers.rb Size: 4.72 KB
//proc/thread-self/root/opt/alt/ruby33/share/gems/gems/bundler-2.5.22/lib/bundler/gem_helpers.rb

# frozen_string_literal: true

module Bundler
  module GemHelpers
    GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant
    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

    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
    module_function :generic

    def generic_local_platform
      generic(local_platform)
    end
    module_function :generic_local_platform

    def local_platform
      Bundler.local_platform
    end
    module_function :local_platform

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

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

      PlatformMatch.specificity_score(spec_platform, user_platform)
    end
    module_function :platform_specificity_match

    def select_best_platform_match(specs, platform, force_ruby: false, prefer_locked: false)
      matching = if force_ruby
        specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! }
      else
        specs.select {|spec| spec.match_platform(platform) }
      end

      if prefer_locked
        locked_originally = matching.select {|spec| spec.is_a?(LazySpecification) }
        return locked_originally if locked_originally.any?
      end

      sort_best_platform_match(matching, platform)
    end
    module_function :select_best_platform_match

    def select_best_local_platform_match(specs, force_ruby: false)
      select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map(&:materialize_for_installation).compact
    end
    module_function :select_best_local_platform_match

    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
    module_function :sort_best_platform_match

    class PlatformMatch
      def self.specificity_score(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 +
          platform_version_match(spec_platform, user_platform) * 100
      end

      def self.os_match(spec_platform, user_platform)
        if spec_platform.os == user_platform.os
          0
        else
          1
        end
      end

      def self.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

      def self.platform_version_match(spec_platform, user_platform)
        if spec_platform.version == user_platform.version
          0
        elsif spec_platform.version.nil?
          1
        else
          2
        end
      end
    end

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

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

Directory Contents

Dirs: 12 × Files: 76

Name Size Perms Modified Actions
cli DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
fetcher DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
installer DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
man DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
plugin DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
resolver DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
settings DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
source DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
templates DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
ui DIR
- drwxr-xr-x 2026-04-30 07:09:19
Edit Download
vendor DIR
- drwxr-xr-x 2026-04-07 13:52:11
Edit Download
1.22 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
877 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
6.94 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
3.72 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
40.91 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
3.28 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
311 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
1.79 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
36.88 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
3.30 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
3.19 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
876 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
2.16 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
22.26 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.09 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.92 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
1.42 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
7.96 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
1.79 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
11.50 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
544 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
3.69 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
6.88 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.72 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
138 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
5.15 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.95 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.85 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
10.03 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
3.10 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
9.97 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
5.79 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
2.43 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
8.63 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
390 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
583 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
863 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
5.77 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
11.41 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
686 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
3.78 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
18.35 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
1.59 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
13.63 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.68 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
13.61 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
1.83 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
4.68 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
9.92 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
597 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
6.45 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
15.02 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
1.36 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
11.84 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
1.84 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
3.01 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
6.81 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
2.17 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
6.94 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
3.27 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download
255 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
1.27 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
715 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
101 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
735 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
197 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
99 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
449 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
180 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
209 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
93 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
496 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
260 B lrw-r--r-- 2026-04-07 13:52:14
Edit Download
465 B lrw-r--r-- 2026-04-07 13:52:13
Edit Download
2.85 KB lrw-r--r-- 2026-04-07 13:52:14
Edit Download
2.42 KB lrw-r--r-- 2026-04-07 13:52:13
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).