summaryrefslogtreecommitdiff
path: root/spec/bundler/support/platforms.rb
blob: 526e1c09a9c039a92693c06c205f7cf21ad3888d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# frozen_string_literal: true

module Spec
  module Platforms
    include Bundler::GemHelpers

    def rb
      Gem::Platform::RUBY
    end

    def mac
      Gem::Platform.new("x86-darwin-10")
    end

    def x64_mac
      Gem::Platform.new("x86_64-darwin-15")
    end

    def java
      Gem::Platform.new([nil, "java", nil])
    end

    def linux
      Gem::Platform.new("x86_64-linux")
    end

    def x86_mswin32
      Gem::Platform.new(["x86", "mswin32", nil])
    end

    def x64_mswin64
      Gem::Platform.new(["x64", "mswin64", nil])
    end

    def x86_mingw32
      Gem::Platform.new(["x86", "mingw32", nil])
    end

    def x64_mingw32
      Gem::Platform.new(["x64", "mingw32", nil])
    end

    def x64_mingw_ucrt
      Gem::Platform.new(["x64", "mingw", "ucrt"])
    end

    def windows_platforms
      [x86_mswin32, x64_mswin64, x86_mingw32, x64_mingw32, x64_mingw_ucrt]
    end

    def all_platforms
      [rb, java, linux, windows_platforms].flatten
    end

    def not_local
      all_platforms.find {|p| p != generic_local_platform }
    end

    def local_tag
      if RUBY_PLATFORM == "java"
        :jruby
      elsif ["x64-mingw32", "x64-mingw-ucrt"].include?(RUBY_PLATFORM)
        :windows
      else
        :ruby
      end
    end

    def not_local_tag
      [:jruby, :windows, :ruby].find {|tag| tag != local_tag }
    end

    def local_ruby_engine
      RUBY_ENGINE
    end

    def local_engine_version
      RUBY_ENGINE == "ruby" ? Gem.ruby_version : RUBY_ENGINE_VERSION
    end

    def not_local_engine_version
      case not_local_tag
      when :ruby, :windows
        not_local_ruby_version
      when :jruby
        "1.6.1"
      end
    end

    def not_local_ruby_version
      "1.12"
    end

    def not_local_patchlevel
      9999
    end

    def default_platform_list(*extra, defaults: default_locked_platforms)
      defaults.concat(extra).uniq
    end

    def lockfile_platforms(*extra, defaults: default_locked_platforms)
      platforms = default_platform_list(*extra, defaults: defaults)
      platforms.map(&:to_s).sort.join("\n  ")
    end

    def default_locked_platforms
      [local_platform, generic_local_platform]
    end
  end
end