Smart(er) platform detection

M

Matt Mower

Hi folks,

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

if RUBY_PLATFORM =3D~ /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

--=20
Matt Mower :: http://matt.blogs.it/
 
B

BG - Ben Armstrong

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.

$ 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
 
R

Robert Klemme

Matt said:
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,

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
 
M

Matt Mower

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 unknow= n
Cygwin
14:41:00 [cg-tsp-hq]: ruby /c/temp/ruby/platform.rb
Platform OS=3Dunix, IMPL=3Dcygwin, ARCH=3Dx86
14:41:04 [cg-tsp-hq]:
=20
Looks pretty much ok IMHO. Does anybody think cygwin should not be
reported as "unix"?
=20

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 =3D :cygwin and let people work it out for themselves.

I'm open to suggestions.

M

--=20
Matt Mower :: http://matt.blogs.it/
 
M

Matt Mower

Hi Ben,

On Wed, 2005-06-29 at 19:16 +0900, Matt Mower wrote:
$ ruby platform.rb
Platform OS=3Dvms, IMPL=3Dvms, ARCH=3Dalpha

Thanks for that.
=20
Looks right to me. What would IMPL would be if ruby ever runs on this
platform?
=20
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=3Dvms now and IMPL=3Dfreevms later if

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

M

--=20
Matt Mower :: http://matt.blogs.it/
 
B

BG - Ben Armstrong

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/

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 :)
** 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.
 
M

Matt Mower

=20
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:
=20
http://gnv.sourceforge.net/
=20

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

OS =3D=3D :unix

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

OS =3D> :hybrid
IMPL =3D> :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 =3D=3D :unix
# do unix
else if OS =3D=3D :hybrid && IMPL =3D=3D :cygwin
# handle Cygwin case

or

if OS =3D=3D :unix || ( OS =3D=3D :hybrid && IMPL =3D=3D :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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top