Smart(er) platform detection

Hi folks,

I recently got bitten by some code which uses an idiom like:

if RUBY_PLATFORM =~ /win/i
  # windows stuff here
end

which is fine until you try it on a machine (like my shiny new
PowerBook) whose platform string is:

  powerpc-darwin-8.1.0

I looked around and couldn't find a systematic solution to getting
useful information from RUBY_PLATFORM so I quickly hacked something
together which you can find described at:

  http://matt.blogs.it/2005/06/29.html#a1882

at the moment it's a single require to get definitions of:

  Platform::OS (e.g. :unix or :win32)
  Platform::IMPL (e.g. :macosx or :mingw)
  Platform::ARCH (e.g. :powerpc or :x86)

or :unknown if it can't figure your platform out.

I'd be very grateful if everyone on the list would please take a
moment download the 'platform.rb' code and run it as 'ruby
platform.rb' and check that it prints out sensible values for ::OS,
::IMPL, and ::ARCH.

If not please either reply here or in a comment to the post including
the output of

  ruby -e 'puts RUBY_PLATFORM'

and what you would expect ::OS, ::IMPL, and ::ARCH to be for your platform.

I'd like to get as comprehensive coverage as possible and then release
this as a library that people can depend upon for detecting platform
differences.

Regards,

Matt

···

--
Matt Mower :: http://matt.blogs.it/

$ ruby platform.rb
Platform OS=vms, IMPL=vms, ARCH=alpha

Looks right to me. What would IMPL would be if ruby ever runs on this
platform?

http://www.systella.fr/~bertrand/FreeVMS/indexGB.html

Would the answer to this question influence the choice of IMPL for an HP
(or DEC or Compaq) implementation of Ruby for VMS? Or would it stay the
same? I suppose we might have IMPL=vms now and IMPL=freevms later if
there are significant differences between the two.

Ben

···

On Wed, 2005-06-29 at 19:16 +0900, Matt Mower wrote:

If not please either reply here or in a comment to the post including
the output of

  ruby -e 'puts RUBY_PLATFORM'

and what you would expect ::OS, ::IMPL, and ::ARCH to be for your platform.

Matt Mower wrote:

Hi folks,

I recently got bitten by some code which uses an idiom like:

if RUBY_PLATFORM =~ /win/i
  # windows stuff here
end

which is fine until you try it on a machine (like my shiny new
PowerBook) whose platform string is:

  powerpc-darwin-8.1.0

I looked around and couldn't find a systematic solution to getting
useful information from RUBY_PLATFORM so I quickly hacked something
together which you can find described at:

  blogs.it

at the moment it's a single require to get definitions of:

  Platform::OS (e.g. :unix or :win32)
  Platform::IMPL (e.g. :macosx or :mingw)
  Platform::ARCH (e.g. :powerpc or :x86)

or :unknown if it can't figure your platform out.

I'd be very grateful if everyone on the list would please take a
moment download the 'platform.rb' code and run it as 'ruby
platform.rb' and check that it prints out sensible values for ::OS,

IMPL, and ::ARCH.

If not please either reply here or in a comment to the post including
the output of

  ruby -e 'puts RUBY_PLATFORM'

and what you would expect ::OS, ::IMPL, and ::ARCH to be for your
platform.

I'd like to get as comprehensive coverage as possible and then release
this as a library that people can depend upon for detecting platform
differences.

14:40:33 [cg-tsp-hq]: cmd /c ver

Microsoft Windows 2000 [Version 5.00.2195]
14:40:58 [cg-tsp-hq]: uname -a
CYGWIN_NT-5.0 bond 1.5.17(0.129/4/2) 2005-05-25 19:38 i686 unknown unknown
Cygwin
14:41:00 [cg-tsp-hq]: ruby /c/temp/ruby/platform.rb
Platform OS=unix, IMPL=cygwin, ARCH=x86
14:41:04 [cg-tsp-hq]:

Looks pretty much ok IMHO. Does anybody think cygwin should not be
reported as "unix"?

Kind regards

    robert

I really wasn't sure what to do in this case. Obviously it's windows
under there but AFAIK cygwin is supposed to emulate a Unix
environment, right?

Alternatives seem to be report :win32 or call a spade a spade and
report OS = :cygwin and let people work it out for themselves.

I'm open to suggestions.

M

···

On 6/29/05, Robert Klemme <bob.news@gmx.net> wrote:

14:40:58 [cg-tsp-hq]: uname -a
CYGWIN_NT-5.0 bond 1.5.17(0.129/4/2) 2005-05-25 19:38 i686 unknown unknown
Cygwin
14:41:00 [cg-tsp-hq]: ruby /c/temp/ruby/platform.rb
Platform OS=unix, IMPL=cygwin, ARCH=x86
14:41:04 [cg-tsp-hq]:

Looks pretty much ok IMHO. Does anybody think cygwin should not be
reported as "unix"?

--
Matt Mower :: http://matt.blogs.it/

Hi Ben,

$ ruby platform.rb
Platform OS=vms, IMPL=vms, ARCH=alpha

Thanks for that.

Looks right to me. What would IMPL would be if ruby ever runs on this
platform?

http://www.systella.fr/~bertrand/FreeVMS/indexGB.html

Would the answer to this question influence the choice of IMPL for an HP
(or DEC or Compaq) implementation of Ruby for VMS? Or would it stay the
same? I suppose we might have IMPL=vms now and IMPL=freevms later if

That seems sensible. Of course it would require that RUBY_PLATFORM
expose it as FreeVMS.

M

···

On 6/29/05, BG - Ben Armstrong <BArmstrong@dymaxion.ca> wrote:

On Wed, 2005-06-29 at 19:16 +0900, Matt Mower wrote:

--
Matt Mower :: http://matt.blogs.it/

It occurs to me that there is also this project to consider, and it is
related to your question about whether cygwin should be reported as
"unix" or not:

Depending on how "UNIX-like" GNV becomes, it is conceivable that a
GNV-based Ruby on VMS might be analogous to the cygwin/win32 situation.
Would this ruby then be OS=vms, IMPL=gnv? OS=unix, IMPL=gnv? OS=gnv,
IMP=gnv?

My gut feeling is that enough of the ugly details* of VMS would show
through any implementation that we should never say OS=unix. And it
seems strange to me to say OS=gnv (just as it seems strange to me to say
OS=cygwin). Anyway, whatever you decide about cygwin, I think the
choice for vms/gnv should be consistent with that decision.**

Ben
* Although beauty is in the eye of the beholder :slight_smile:
** Then again, you could justifiably argue that all this talk of
hypothetical alternate implementations of VMS Ruby when we barely have
one implementation today is so much in the realm of fantasy as to be
entirely irrelevant.

···

On Wed, 2005-06-29 at 21:55 +0900, Matt Mower wrote:

That seems sensible. Of course it would require that RUBY_PLATFORM
expose it as FreeVMS.

I guess the issue here is about what decisions one might be trying to
make based upon seeing:

OS == :unix

It might be best for hybrid's like cygwin, gnv, and so on if we
reported something unambigous, e.g.

OS => :hybrid
IMPL => :cygwin, :gnv, etc...

At least this way you can plan what you're going to do if you're not
on a straightforward platform.

e.g.

if OS == :unix
  # do unix
else if OS == :hybrid && IMPL == :cygwin
  # handle Cygwin case

or

if OS == :unix || ( OS == :hybrid && IMPL == :cygwin )
  # we don't care

I'm tempted to wonder about "hybrid-unix" but think that might be
getting too complicated. In all likelyhood there aren't that many
combinations that would need to be given special treatment.

M

···

On 6/29/05, BG - Ben Armstrong <BArmstrong@dymaxion.ca> wrote:

On Wed, 2005-06-29 at 21:55 +0900, Matt Mower wrote:
> That seems sensible. Of course it would require that RUBY_PLATFORM
> expose it as FreeVMS.

It occurs to me that there is also this project to consider, and it is
related to your question about whether cygwin should be reported as
"unix" or not:

http://gnv.sourceforge.net/

--
Matt Mower :: http://matt.blogs.it/