$: - where does it get its initial values?

Howdy,

Where does $: get its values from? The book says that it contains an
array of places to search for loaded files and that it is “initialized
to the list of standard directories, plus any additional ones you
specify using RUBYLIB and -I.” Where does ruby get these standard
directories? I realize that I can set up RUBYLIB in my environment if I
want to search directories I specify, but I am mystified as to the
origin of the directories originally in $: . Any help would be welcome.

Thanks,
Tuan

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
/usr/local/lib/ruby/site_ruby/1.6/i686-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.6
/usr/local/lib/ruby/1.6/i686-linux
/usr/local/bin:/usr/ucb:/usr/bin:/bin:.

Gennady.

···

----- Original Message -----
From: “Tuan Bui” tuanbui@cray.com.nospam
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, August 06, 2003 1:23 PM
Subject: $: - where does it get its initial values?

Howdy,

Where does $: get its values from? The book says that it contains an
array of places to search for loaded files and that it is “initialized
to the list of standard directories, plus any additional ones you
specify using RUBYLIB and -I.” Where does ruby get these standard
directories? I realize that I can set up RUBYLIB in my environment if I
want to search directories I specify, but I am mystified as to the
origin of the directories originally in $: . Any help would be welcome.

Thanks,
Tuan

In ruby.c, look for rb_load_path and calls to ruby_incpush; it is set from a
series of compile-time constants and/or environmnet variables.

if (rb_safe_level() == 0) {
    ruby_incpush(getenv("RUBYLIB"));
}

#ifdef RUBY_SEARCH_PATH
ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
#endif

ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB2));

#ifdef RUBY_SITE_THIN_ARCHLIB
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_THIN_ARCHLIB));
#endif
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_ARCHLIB));
ruby_incpush(RUBY_RELATIVE(RUBY_SITE_LIB));

ruby_incpush(RUBY_RELATIVE(RUBY_LIB));

#ifdef RUBY_THIN_ARCHLIB
ruby_incpush(RUBY_RELATIVE(RUBY_THIN_ARCHLIB));
#endif
ruby_incpush(RUBY_RELATIVE(RUBY_ARCHLIB));

if (rb_safe_level() == 0) {
    ruby_incpush(".");
}
···

On Thu, Aug 07, 2003 at 05:23:35AM +0900, Tuan Bui wrote:

Where does $: get its values from? The book says that it contains an
array of places to search for loaded files and that it is “initialized
to the list of standard directories, plus any additional ones you
specify using RUBYLIB and -I.” Where does ruby get these standard
directories?

This may have been the cause of problems I had when using ruby-mysql. My Ruby
binary was compiled for generic i386, but mysql was compiled for i686 so it
wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result was
that I had an i386-linux and an i686-linux directory, but only one was being
searched. I got around that by using -I and/or setting an environment
variable… but it seems like it should be possible for Ruby to “figure this
out”. Am I asking too much of it?

Ben

···

On Wed August 6 2003 4:33 pm, Gennady wrote:

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
/usr/local/lib/ruby/site_ruby/1.6/i686-linux
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.6
/usr/local/lib/ruby/1.6/i686-linux
/usr/local/bin:/usr/ucb:/usr/bin:/bin:.

:

How do you know, all strings with /usr/local in the ruby-executable
make up this path? Isn’t easier, just to print out $: without any
-I or RUBYLIB?

$ (unset RUBYLIB; ruby -e ‘p $:’)
[“/usr/local/lib/site_ruby/1.6”, “/usr/local/lib/site_ruby/1.6/i386-linux”, “/usr/local/lib/site_ruby”, “/usr/lib/ruby/1.6”, “/usr/lib/ruby/1.6/i386-linux”, “.”]

···

On Thu, Aug 07, 2003 at 05:33:51AM +0900, Gennady wrote:

They are figured out during Ruby build by configure and then hardcoded into
the resulting executable. If your ruby is installed in /usr/local you can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6

marko schulz

They are figured out during Ruby build by configure and then hardcoded
into
the resulting executable. If your ruby is installed in /usr/local you
can
check it with

$ strings /usr/local/bin/ruby | grep /usr/local
/usr/local/lib/ruby/site_ruby/1.6
:

How do you know, all strings with /usr/local in the ruby-executable
make up this path? Isn’t easier, just to print out $: without any
-I or RUBYLIB?

I did not mention that they ALL make up LOADPATH, I just showed the way to
see that whatever makes up the default path is hardcoded during make
process.

$ (unset RUBYLIB; ruby -e ‘p $:’)
[“/usr/local/lib/site_ruby/1.6”,
“/usr/local/lib/site_ruby/1.6/i386-linux”, “/usr/local/lib/site_ruby”,
“/usr/lib/ruby/1.6”, “/usr/lib/ruby/1.6/i386-linux”, “.”]

The original question was just this: why $: is what it is?

···

----- Original Message -----
From: “Marko Schulz” in6x059@public.uni-hamburg.de
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, August 06, 2003 2:25 PM
Subject: Re: - where does it get its initial values?

On Thu, Aug 07, 2003 at 05:33:51AM +0900, Gennady wrote:


marko schulz

[snip]

This may have been the cause of problems I had when using ruby-mysql. My
Ruby binary was compiled for generic i386, but mysql was compiled for i686 so
it wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result
was that I had an i386-linux and an i686-linux directory, but only one was
being searched. […]

Couldn’t you have solved that by symlinking
/usr/local/lib/ruby/site_ruby/i686-linux to
/usr/local/lib/ruby/site_ruby/i386-linux?

···

On Thu, 7 Aug 2003 05:57:33 +0900 Ben Giddings ben@thingmagic.com wrote:

Even though you compile it for i686, the installer should know, that
he has to put it in /usr/local/lib/ruby/site_ruby/i386-linux. This is
AFAIK what mkmf.rb does, by using rbconfig: It queries the paths, ruby
was build with.

···

On Thu, Aug 07, 2003 at 05:57:33AM +0900, Ben Giddings wrote:

This may have been the cause of problems I had when using ruby-mysql. My Ruby
binary was compiled for generic i386, but mysql was compiled for i686 so it
wanted to go in /usr/local/lib/ruby/site_ruby/i686-linux. The end result was
that I had an i386-linux and an i686-linux directory, but only one was being
searched. I got around that by using -I and/or setting an environment
variable… but it seems like it should be possible for Ruby to “figure this
out”. Am I asking too much of it?


marko schulz

Sure, had I known that mysql-ruby’s RPM was going to install into i686-linux
(and/or create it). There are all kinds of easy ways to fix it after it has
been installed – I’m just suggesting that if the default for installing Ruby
binaries is to have them in an “arch-os” directory, it would make sense that
it also knows that if arch is i686, i386 binaries will also work.

Ben

···

On Wed August 6 2003 5:43 pm, Anders K. Madsen wrote:

Couldn’t you have solved that by symlinking
/usr/local/lib/ruby/site_ruby/i686-linux to
/usr/local/lib/ruby/site_ruby/i386-linux?

Ehrm, correct me if I’m wrong, but couldn’t you just have moved the content of
i686-linux to i386-linux and then made the symlink?

Best regards
madsen

···

On Thu, 7 Aug 2003 06:50:55 +0900 Ben Giddings ben@thingmagic.com wrote:

On Wed August 6 2003 5:43 pm, Anders K. Madsen wrote:

Couldn’t you have solved that by symlinking
/usr/local/lib/ruby/site_ruby/i686-linux to
/usr/local/lib/ruby/site_ruby/i386-linux?

Sure, had I known that mysql-ruby’s RPM was going to install into i686-linux
(and/or create it). There are all kinds of easy ways to fix it after it has
been installed – I’m just suggesting that if the default for installing Ruby
binaries is to have them in an “arch-os” directory, it would make sense that
it also knows that if arch is i686, i386 binaries will also work.