| Class | Gem::Platform |
| In: |
lib/rubygems/platform.rb
|
| Parent: | Object |
Available list of platforms for targeting Gem installations.
| DEPRECATED_CONSTS | = | [ :DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX | ||
| RUBY | = | 'ruby' | A pure-ruby gem that may use Gem::Specification#extensions to build binary files. | |
| CURRENT | = | 'current' | A platform-specific gem that is built for the packaging ruby‘s platform. This will be replaced with Gem::Platform::local. |
| cpu | [RW] | |
| os | [RW] | |
| version | [RW] |
# File lib/rubygems/platform.rb, line 24
24: def self.const_missing(name) # TODO remove six months from 2007/12
25: if DEPRECATED_CONSTS.include? name then
26: raise NameError, "#{name} has been removed, use CURRENT instead"
27: else
28: super
29: end
30: end
# File lib/rubygems/platform.rb, line 32
32: def self.local
33: arch = Gem::ConfigMap[:arch]
34: arch = "#{arch}_60" if arch =~ /mswin32$/
35: @local ||= new(arch)
36: end
# File lib/rubygems/platform.rb, line 38
38: def self.match(platform)
39: Gem.platforms.any? do |local_platform|
40: platform.nil? or local_platform == platform or
41: (local_platform != Gem::Platform::RUBY and local_platform =~ platform)
42: end
43: end
# File lib/rubygems/platform.rb, line 56
56: def initialize(arch)
57: case arch
58: when Array then
59: @cpu, @os, @version = arch
60: when String then
61: arch = arch.split '-'
62:
63: if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
64: extra = arch.pop
65: arch.last << "-#{extra}"
66: end
67:
68: cpu = arch.shift
69:
70: @cpu = case cpu
71: when /i\d86/ then 'x86'
72: else cpu
73: end
74:
75: if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line
76: @os, @version = arch
77: return
78: end
79:
80: os, = arch
81: @cpu, os = nil, cpu if os.nil? # legacy jruby
82:
83: @os, @version = case os
84: when /aix(\d+)/ then [ 'aix', $1 ]
85: when /cygwin/ then [ 'cygwin', nil ]
86: when /darwin(\d+)?/ then [ 'darwin', $1 ]
87: when /freebsd(\d+)/ then [ 'freebsd', $1 ]
88: when /hpux(\d+)/ then [ 'hpux', $1 ]
89: when /^java$/, /^jruby$/ then [ 'java', nil ]
90: when /^java([\d.]*)/ then [ 'java', $1 ]
91: when /linux/ then [ 'linux', $1 ]
92: when /mingw32/ then [ 'mingw32', nil ]
93: when /(mswin\d+)(\_(\d+))?/ then
94: os, version = $1, $3
95: @cpu = 'x86' if @cpu.nil? and os =~ /32$/
96: [os, version]
97: when /netbsdelf/ then [ 'netbsdelf', nil ]
98: when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ]
99: when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ]
100: # test
101: when /^(\w+_platform)(\d+)/ then [ $1, $2 ]
102: else [ 'unknown', nil ]
103: end
104: when Gem::Platform then
105: @cpu = arch.cpu
106: @os = arch.os
107: @version = arch.version
108: else
109: raise ArgumentError, "invalid argument #{arch.inspect}"
110: end
111: end
# File lib/rubygems/platform.rb, line 125
125: def ==(other)
126: self.class === other and
127: @cpu == other.cpu and @os == other.os and @version == other.version
128: end
# File lib/rubygems/platform.rb, line 130
130: def ===(other)
131: return nil unless Gem::Platform === other
132:
133: # cpu
134: (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
135:
136: # os
137: @os == other.os and
138:
139: # version
140: (@version.nil? or other.version.nil? or @version == other.version)
141: end
# File lib/rubygems/platform.rb, line 143
143: def =~(other)
144: case other
145: when Gem::Platform then # nop
146: when String then
147: # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
148: other = case other
149: when /^i686-darwin(\d)/ then ['x86', 'darwin', $1]
150: when /^i\d86-linux/ then ['x86', 'linux', nil]
151: when 'java', 'jruby' then [nil, 'java', nil]
152: when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2]
153: when 'powerpc-darwin' then ['powerpc', 'darwin', nil]
154: when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1]
155: when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8']
156: when /universal-darwin(\d)/ then ['universal', 'darwin', $1]
157: else other
158: end
159:
160: other = Gem::Platform.new other
161: else
162: return nil
163: end
164:
165: self === other
166: end
# File lib/rubygems/platform.rb, line 113
113: def inspect
114: "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
115: end