-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require_relative through symlinks behaves differently in jruby than in MRI ruby #3092
Comments
i.e., in my understanding since |
This difference in behavior between jruby and the MRI is not new. The test code above behaves identically in MRI ruby 1.9.3 (p547) and 2.2.2. Similarly the test code behaves identically in jruby 1.7.4, 1.7.20.1 and 9.0.0.0.rc1. I modified the link_target.rb as follows to include some debugging output. The line labelled 'absolute_feature' is copied from the jruby implementation of require_relative (9.0.0.0.rc1 core/src/main/ruby/jruby/kernel/kernel.rb line 21) with the arguments resolved to the equivalent local values. # link_target.rb
$stderr.puts ""
$stderr.puts "__FILE__ = " + __FILE__
$stderr.puts "File.absolute_path(__FILE__) = " + File.absolute_path(__FILE__)
$stderr.puts "File.realdirpath(__FILE__) = " + File.realdirpath(__FILE__)
$stderr.puts "File.realpath(__FILE__) = " + File.realpath(__FILE__)
$stderr.puts ""
$stderr.puts "absolute_feature = " + File.expand_path('./included_by_target', File.dirname(__FILE__))
$stderr.puts "mimic_mri = " + File.expand_path('./included_by_target', File.dirname(File.realpath(__FILE__)))
$stderr.puts ""
require_relative './included_by_target'
class LinkTarget
include IncludedByTarget
end which produce the following output from MRI ruby:
and this output from jruby:
The difference in require_relative behavior between MRI and jruby appears to be that the MRI resolves the relative-path argument to its realpath (analogous to the line labeled 'mimic_mri') and jruby doesn't. |
So is this as simple as just throwing File.realpath into our require_relative impl? |
I have a fix locally and it appears to pass specs and tests. |
(my mistake, it seems normal |
If you require a source file that contains require_relative through a symlink in a different diretory, MRI ruby interprets the require_relative relative to the directory containing the link target but jruby 9.0.0.0.rc1 interprets it relative to the directory containing the symlink itself.
The real application code that brought this to my attention is simulated by the following source files and symlink:
This code works in MRI ruby:
but fails under jruby 9.0.0.0.rc1. Note that the interpreter is looking for the included file in the directory containing the symlink rather than in the directory containing the linked file:
The text was updated successfully, but these errors were encountered: