fix empty RbConfig::CONFIG["prefix"] when configured --with-rubyarchprefix #643
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
and
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.