[Rubygems-developers] Recognizing Platforms

Eric Hodel drbrain at segment7.net
Sun Aug 19 18:11:06 EDT 2007


Here's my proposal for how we recognize platforms.  From  
Config::CONFIG, take the target_os and run it through a case  
statement to figure out OS and OS version (if any).  Combine the  
target_cpu, OS and OS version.  This value is your platform.

There will be a rubygems-platforms.gem much like sources.gem that can  
be updated as-necessary.

Using the tattle data, I came up with this implementation:

def match(cpu, os)
   os = case os
        when /cygwin/ then            [ 'cygwin',  nil ]
        when /darwin(\d+)?/ then      [ 'darwin',  $1  ]
        when /freebsd(\d+)/ then      [ 'freebsd', $1  ]
        when /^java([\d.]*)/ then     [ 'java',    $1  ]
        when /linux/ then             [ 'linux',   $1  ]
        when /mingw32/ then           [ 'mingw32', nil ]
        when /mswin32/ then           [ 'mswin32', nil ]
        when /openbsd(\d+)/ then      [ 'openbsd', $1  ]
        when /solaris(\d+\.\d+)/ then [ 'solaris', $1  ]
        else                          [ 'unknown', nil ]
        end

   [cpu, os].flatten.compact.join("-")
end

require 'rbconfig'

target_cpu = Config::CONFIG['target_cpu']
target_os = Config::CONFIG['target_os']

puts "Your target_cpu is:   #{target_cpu.inspect}"
puts "Your target_os is:    #{target_os.inspect}"
puts "Your platform is: #{match(target_cpu, target_os).inspect}"

This code recognizes 26 unique platforms:

amd64-freebsd-6
java
java-1.4
powerpc-darwin-7
powerpc-darwin-8
powerpc-darwin-9
powerpc-linux
powerpc64-linux
sparc-solaris-2.10
sparc-solaris-2.8
sparc-solaris-2.9
x86-cygwin
x86-darwin
x86-darwin-8
x86-freebsd-4
x86-freebsd-5
x86-freebsd-6
x86-linux
x86-mingw32
x86-mswin32
x86-openbsd-4
x86-solaris-2.10
x86-solaris-2.8
x86_64-linux
x86_64-openbsd-3
x86_64-openbsd-4

Don't worry about legacy platforms, that's an entirely separate problem.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars




More information about the Rubygems-developers mailing list