ruby/ruby — pull request #643 by lotheac (2014-06-27 12:14:35+00:00)
Title: fix empty RbConfig::CONFIG["prefix"] when configured --with-rubyarchprefix

This fixes RbConfig::CONFIG["prefix"] being empty when ruby was configured
--with-rubyarchprefix. The 'why' is pretty convoluted:

rbconfig.rb is *not* generated by autoconf for some reason I cannot fathom, but
instead, at compile-time, miniruby is used to run tool/mkconfig.rb to generate
it. mkconfig.rb parses the config.status shell script to do that; that's weird,
but okay. The actually relevant lines in the script look like this:

S["rubyarchdir"]="${rubyarchprefix}/${ruby_version}"

So mkconfig.rb has code to expand these variables as well. But it doesn't end
here. TOPDIR in rbconfig.rb is what is used to figure out CONFIG["prefix"];
this is done by chopping off the part without the prefix from the full path of
the file:

TOPDIR = File.dirname(__FILE__).chomp!("/lib/amd64/ruby/2.0.0")

and

CONFIG["prefix"] = (TOPDIR || DESTDIR + "/opt/niksula")

I don't know why this needs to be done at runtime. Anyway, the bug lies in the
mkconfig.rb code that generates the TOPDIR line above. After reading the
variables from config.status, "prefix" and "exec_prefix" are set to the empty
string, and the expansion is only done *after* this. That means, if your
rubyarchprefix happens to begin with either "${prefix}" or "${exec_prefix}",
you will get a correctly generated TOPDIR line (one that does not contain your
prefix). However, if you used --with-rubyarchprefix to set it explicitly,
you're not so lucky: there is no prefix or exec_prefix variable there, so you
get the full rubyarchdir path on the TOPDIR line in rbconfig.rb, and thus the
prefix resolves to empty at runtime.

Because I don't know why TOPDIR is decided at runtime, I'm leaving it like that
with this patch; otherwise I'd just set it to be prefix.

I tested this against ruby 2.1.2 release version.