Class | Gem::Platform |
In: |
lib/rubygems/platform.rb
|
Parent: | Object |
Available list of platforms for targeting Gem installations.
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 14 14: def self.local 15: arch = Gem::ConfigMap[:arch] 16: arch = "#{arch}_60" if arch =~ /mswin32$/ 17: @local ||= new(arch) 18: end
# File lib/rubygems/platform.rb, line 20 20: def self.match(platform) 21: Gem.platforms.any? do |local_platform| 22: platform.nil? or local_platform == platform or 23: (local_platform != Gem::Platform::RUBY and local_platform =~ platform) 24: end 25: end
# File lib/rubygems/platform.rb, line 38 38: def initialize(arch) 39: case arch 40: when Array then 41: @cpu, @os, @version = arch 42: when String then 43: arch = arch.split '-' 44: 45: if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu 46: extra = arch.pop 47: arch.last << "-#{extra}" 48: end 49: 50: cpu = arch.shift 51: 52: @cpu = case cpu 53: when /i\d86/ then 'x86' 54: else cpu 55: end 56: 57: if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line 58: @os, @version = arch 59: return 60: end 61: 62: os, = arch 63: @cpu, os = nil, cpu if os.nil? # legacy jruby 64: 65: @os, @version = case os 66: when /aix(\d+)/ then [ 'aix', $1 ] 67: when /cygwin/ then [ 'cygwin', nil ] 68: when /darwin(\d+)?/ then [ 'darwin', $1 ] 69: when /freebsd(\d+)/ then [ 'freebsd', $1 ] 70: when /hpux(\d+)/ then [ 'hpux', $1 ] 71: when /^java$/, /^jruby$/ then [ 'java', nil ] 72: when /^java([\d.]*)/ then [ 'java', $1 ] 73: when /linux/ then [ 'linux', $1 ] 74: when /mingw32/ then [ 'mingw32', nil ] 75: when /(mswin\d+)(\_(\d+))?/ then 76: os, version = $1, $3 77: @cpu = 'x86' if @cpu.nil? and os =~ /32$/ 78: [os, version] 79: when /netbsdelf/ then [ 'netbsdelf', nil ] 80: when /openbsd(\d+\.\d+)/ then [ 'openbsd', $1 ] 81: when /solaris(\d+\.\d+)/ then [ 'solaris', $1 ] 82: # test 83: when /^(\w+_platform)(\d+)/ then [ $1, $2 ] 84: else [ 'unknown', nil ] 85: end 86: when Gem::Platform then 87: @cpu = arch.cpu 88: @os = arch.os 89: @version = arch.version 90: else 91: raise ArgumentError, "invalid argument #{arch.inspect}" 92: end 93: end
Is other equal to this platform? Two platforms are equal if they have the same CPU, OS and version.
# File lib/rubygems/platform.rb, line 115 115: def ==(other) 116: self.class === other and 117: @cpu == other.cpu and @os == other.os and @version == other.version 118: end
Does other match this platform? Two platforms match if they have the same CPU, or either has a CPU of ‘universal’, they have the same OS, and they have the same version, or either has no version.
# File lib/rubygems/platform.rb, line 125 125: def ===(other) 126: return nil unless Gem::Platform === other 127: 128: # cpu 129: (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu) and 130: 131: # os 132: @os == other.os and 133: 134: # version 135: (@version.nil? or other.version.nil? or @version == other.version) 136: end
Does other match this platform? If other is a String it will be converted to a Gem::Platform first. See #=== for matching rules.
# File lib/rubygems/platform.rb, line 142 142: def =~(other) 143: case other 144: when Gem::Platform then # nop 145: when String then 146: # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007 147: other = case other 148: when /^i686-darwin(\d)/ then ['x86', 'darwin', $1 ] 149: when /^i\d86-linux/ then ['x86', 'linux', nil ] 150: when 'java', 'jruby' then [nil, 'java', nil ] 151: when /mswin32(\_(\d+))?/ then ['x86', 'mswin32', $2 ] 152: when 'powerpc-darwin' then ['powerpc', 'darwin', nil ] 153: when /powerpc-darwin(\d)/ then ['powerpc', 'darwin', $1 ] 154: when /sparc-solaris2.8/ then ['sparc', 'solaris', '2.8' ] 155: when /universal-darwin(\d)/ then ['universal', 'darwin', $1 ] 156: else other 157: end 158: 159: other = Gem::Platform.new other 160: else 161: return nil 162: end 163: 164: self === other 165: end
# File lib/rubygems/platform.rb, line 95 95: def inspect 96: "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a] 97: end