4 # Available list of platforms for targeting Gem installations.
14 attr_accessor :version
25 def self.const_missing(name) # TODO remove six months from 2007/12
26 if DEPRECATED_CONSTS.include? name then
27 raise NameError, "#{name} has been removed, use CURRENT instead"
34 arch = Gem::ConfigMap[:arch]
35 arch = "#{arch}_60" if arch =~ /mswin32$/
39 def self.match(platform)
40 Gem.platforms.any? do |local_platform|
41 platform.nil? or local_platform == platform or
42 (local_platform != Gem::Platform::RUBY and local_platform =~ platform)
46 def self.new(arch) # :nodoc:
48 when Gem::Platform::CURRENT then
50 when Gem::Platform::RUBY, nil, '' then
60 @cpu, @os, @version = arch
64 if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
66 arch.last << "-#{extra}"
72 when /i\d86/ then 'x86'
76 if arch.length == 2 and arch.last =~ /^\d+$/ then # for command-line
82 @cpu, os = nil, cpu if os.nil? # legacy jruby
84 @os, @version = case os
85 when /aix(\d+)/ then [ 'aix', $1 ]
86 when /cygwin/ then [ 'cygwin', nil ]
87 when /darwin(\d+)?/ then [ 'darwin', $1 ]
88 when /freebsd(\d+)/ then [ 'freebsd', $1 ]
89 when /hpux(\d+)/ then [ 'hpux', $1 ]
90 when /^java$/, /^jruby$/ then [ 'java', nil ]
91 when /^java([\d.]*)/ then [ 'java', $1 ]
92 when /linux/ then [ 'linux', $1 ]
93 when /mingw32/ then [ 'mingw32', nil ]
94 when /(mswin\d+)(\_(\d+))?/ then
96 @cpu = 'x86' if @cpu.nil? and os =~ /32$/
98 when /netbsdelf/ then [ 'netbsdelf', nil ]
99 when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ]
100 when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ]
102 when /^(\w+_platform)(\d+)/ then [ $1, $2 ]
103 else [ 'unknown', nil ]
105 when Gem::Platform then
108 @version = arch.version
110 raise ArgumentError, "invalid argument #{arch.inspect}"
115 "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
119 [@cpu, @os, @version]
123 to_a.compact.join '-'
127 # Is +other+ equal to this platform? Two platforms are equal if they have
128 # the same CPU, OS and version.
131 self.class === other and
132 @cpu == other.cpu and @os == other.os and @version == other.version
136 # Does +other+ match this platform? Two platforms match if they have the
137 # same CPU, or either has a CPU of 'universal', they have the same OS, and
138 # they have the same version, or either has no version.
141 return nil unless Gem::Platform === other
144 (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and
150 (@version.nil? or other.version.nil? or @version == other.version)
154 # Does +other+ match this platform? If +other+ is a String it will be
155 # converted to a Gem::Platform first. See #=== for matching rules.
159 when Gem::Platform then # nop
161 # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
163 when /^i686-darwin(\d)/ then ['x86', 'darwin', $1]
164 when /^i\d86-linux/ then ['x86', 'linux', nil]
165 when 'java', 'jruby' then [nil, 'java', nil]
166 when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2]
167 when 'powerpc-darwin' then ['powerpc', 'darwin', nil]
168 when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1]
169 when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8']
170 when /universal-darwin(\d)/ then ['universal', 'darwin', $1]
174 other = Gem::Platform.new other
183 # A pure-ruby gem that may use Gem::Specification#extensions to build
189 # A platform-specific gem that is built for the packaging ruby's platform.
190 # This will be replaced with Gem::Platform::local.