recognition of windows

53 views
Skip to first unread message

Thierry

unread,
Aug 3, 2010, 1:25:15 PM8/3/10
to RubyInstaller
Hi,

I noticed quite a few gems and standard libraries recognize Windows by
grepping RUBY_PLAFORM for "win32". This unfortunately fails in our
case, since RUBY_PLAFORM is "i386-mingw32". Would it be possible to
change this to "i386-mingwin32"? It would be easier than to wave at
each and every ruby developer around...

Cheers
-- Thierry

Luis Lavena

unread,
Aug 3, 2010, 1:35:17 PM8/3/10
to rubyin...@googlegroups.com

Hello Thierry.

Can you explain it better?

Detecting Windows using RUBY_PLATFORM is not correct:

http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/

We can't change the RubyInstaller platform (since is part of Ruby own
internals) and neither how RubyGems identify it.

Gem authors should be in charge of correct gem platform detection.

As shortcut I had used in the past:

RUBY_PLATFORM =~ /mingw|mswin/

Which covers 32 and 64bits versions of Ruby on both mswin and mingw
distributions.

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Thierry

unread,
Aug 4, 2010, 3:02:44 AM8/4/10
to RubyInstaller
Hello Luis,

You say "Detecting Windows using RUBY_PLATFORM is not correct", but
rbconfig is not part of the standard ruby installation on all
platforms, as far as I know?
More specifically, I grepped my installed gems for '/win32/', and
found this:

C:\Ruby\lib\ruby\gems\1.8\gems\daemons-1.1.0\lib\daemons
\application.rb
SIGNAL = (RUBY_PLATFORM =~ /win32/ ? 'KILL' : 'TERM')

C:\Ruby\lib\ruby\gems\1.8\gems\ZenTest-4.3.3\lib\autotest.rb
WINDOZE = /win32/ =~ RUBY_PLATFORM

C:\Ruby\lib\ruby\gems\1.8\gems\ZenTest-4.3.3\lib\unit_diff.rb
WINDOZE = /win32/ =~ RUBY_PLATFORM unless defined? WINDOZE

I know redgreen has the same problem, by the way, but I uninstalled
it, so it does not show.

Should I report to the gem authors? What would be a "native" way to
detect Windows on all patforms? Would RUBY_PLATFORM =~ /mingw|mswin/
be OK?

Thanks
-- Thierry

On 3 août, 19:35, Luis Lavena <luislav...@gmail.com> wrote:
> On Tue, Aug 3, 2010 at 2:25 PM, Thierry <thyres...@gmail.com> wrote:
> > Hi,
>
> > I noticed quite a few gems and standard libraries recognize Windows by
> > grepping RUBY_PLAFORM for "win32". This unfortunately fails in our
> > case, since RUBY_PLAFORM is "i386-mingw32". Would it be possible to
> > change this to "i386-mingwin32"? It would be easier than to wave at
> > each and every ruby developer around...
>
> Hello Thierry.
>
> Can you explain it better?
>
> Detecting Windows using RUBY_PLATFORM is not correct:
>
> http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-plat...

Roger Pack

unread,
Aug 4, 2010, 6:53:41 AM8/4/10
to rubyin...@googlegroups.com
> Should I report to the gem authors? What would be a "native" way to
> detect Windows on all patforms? Would RUBY_PLATFORM =~ /mingw|mswin/
> be OK?

The only real "native" way is to check for

ENV['OS'] == 'Windows_NT'

My suggestion would be to tell all of those authors to use the new
regex, as you specified.
-r

Luis Lavena

unread,
Aug 4, 2010, 7:34:55 AM8/4/10
to rubyin...@googlegroups.com
On Wed, Aug 4, 2010 at 4:02 AM, Thierry <thyr...@gmail.com> wrote:
> Hello Luis,
>
> You say "Detecting Windows using RUBY_PLATFORM is not correct", but
> rbconfig is not part of the standard ruby installation on all
> platforms, as far as I know?

rbconfig is part of *all* versions of Ruby, no matter what implementation.

> More specifically, I grepped my installed gems for '/win32/', and
> found this:
>
> C:\Ruby\lib\ruby\gems\1.8\gems\daemons-1.1.0\lib\daemons
> \application.rb
>    SIGNAL = (RUBY_PLATFORM =~ /win32/ ? 'KILL' : 'TERM')
>

Gem author issue, is not Ruby fault, more on this:

http://blog.mmediasys.com/2008/10/21/guas-is-giving-unwanted-advice-series-1/

> C:\Ruby\lib\ruby\gems\1.8\gems\ZenTest-4.3.3\lib\autotest.rb
>    WINDOZE = /win32/ =~ RUBY_PLATFORM
>

I hate to say it but some patches to ZenTest are sitting getting dust
in RubyForge.

> C:\Ruby\lib\ruby\gems\1.8\gems\ZenTest-4.3.3\lib\unit_diff.rb
>  WINDOZE = /win32/ =~ RUBY_PLATFORM unless defined? WINDOZE
>

Same as above.

> I know redgreen has the same problem, by the way, but I uninstalled
> it, so it does not show.
>
> Should I report to the gem authors? What would be a "native" way to
> detect Windows on all patforms? Would RUBY_PLATFORM =~ /mingw|mswin/
> be OK?
>

The RUBY_PLATFORM regexp is good in the short term, but moving forward
and considering other implementations as JRuby, the real one is use
RbConfig::CONFIG['host_os'] option with the regexp.

HTH,

Luis Lavena

unread,
Aug 4, 2010, 7:35:46 AM8/4/10
to rubyin...@googlegroups.com

That is way too brittle and will not work when doing cross compilation
or anything like that.

Safety note: stick to RbConfig::CONFIG['host_os'], please

Reply all
Reply to author
Forward
0 new messages