-
-
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
Kernel#require cannot find compiled ruby classes in jruby 9.0.0.0 #3270
Comments
Sorry, see I misspelled , should be 'require "test2". |
You'll probably need to pass HTH |
Thank you very much for pointing this out. JRUBY lists aot.loadClasses as a valid option:jruby -v Look for .class before .rb to load AOT-compiled codeOptions: [true, false], Default: false.#aot.loadClasses=false JRUBY-COMPLETE ( based on the same version of JRUBY) does not seem to support this option:java -jar jruby-complete-9.0.0.0.jar -v java -jar jruby-complete-9.0.0.0.jar -Xaot.loadClasses=true java -jar lib\java\jruby-complete-9.0.0.0.jar -X |
Further progress: |
@CeesZ yes jruby-complete can not use those -X options since they are meant for the launcher which does convert them to -Djruby. ones for the |
Yes, thank you for explaining; I understand that now. |
@CeesZ We'll narrow this to just the require_relative issue. Can you provide a small sample repository that shows this problem? With the |
Sorry for late reply. At the moment on holiday in Scotland with only occasional access to internet. Will be back home at the end of this week and work on a small sample repository.
|
I constructed the following archive (test1.jar) for testing require_relative:
run with jruby-complete:
output (as expected)
test2.jar is identical to test1.jar, with .rb files replaced by their .class files; using same java command:
instead of loading test2.class from uri:classloader:/app/test2.class it attempts
I also noticed some odd behavior of (supposedly a String object)
when using .rb files:
Hope this will be of some help to solve the problem. ==Cees |
Sorry tried to attach the test jars, but does not seem to work |
I can reproduce it on my machine (not windows) and get
it does not complain not finding test2 but not finding test1 on the filesystem - indeed this is looking odd. @CeesZ thanks for the testcase - my own trial never failed ;) |
OK, here are the test jars: https://www.dropbox.com/s/fe1n7p8juuj532b/test1.jar?dl=0 @mkristian maybe it is caused by a File.dirname request on |
@mkristian Do you have any thoughts on this? We'd like to put 9.0.2 out soon. |
looking now . . . |
the caller in this line
with the compiled files it is
adjusting the @headius stepping into the caller is new territory for nothing I am able to do today |
the class has this is probably also the reason why there are two representation of FILE around, one from the class-file and one from the LoadService. |
@mkristian @headius This is the last blocker for 9.0.2.0. There multiple things I do not understand at play here :) FILE in a compiled version of a .rb file SHOULD be a .rb name shouldn't it? I mean compilation is just a different way of storing a .rb. In that sense I think it is weird to ever display this as .class. So I do not think the solution is to do rename FILE. My stance is compilation is just a different save format for a .rb file and it should not change any user-visible behavior from the act of compilation. If I require_relative a AOT compiled class should I even care what the extension is of the file I am in? I do care about the base parent path but I would think we would do that correctly? Can't we just strip the extension off the caller data and this will just work? We don't actually know if we will be loading a .rb or a .class from this file. |
@enebo I thought absolute path does need the file extension. but just tried it on both jruby + mri and it works. yes, this is one thing which can be improved easily. |
not sure if this is related or not, but there are more inconsistencies:
then compile and put it into a jar
now
some with "." on the classpath
but
and whatever jruby or jruby-complete they all can not find the file without ".class"
|
@mkristian could this be because of special logic for uri:classloader somehow? |
@enebo I really would like to take this uri:classloader: path out of the equation and once the following example works, it should basically fix the original problem here: test.rb
and a.rb with
then execute it with MRI
and with jruby
slightly different setup but same error. |
diff --git a/core/src/main/ruby/jruby/kernel/kernel.rb b/core/src/main/ruby/jruby/kernel/kernel.rb
index b4dd5e13..6ec4164 100644
--- a/core/src/main/ruby/jruby/kernel/kernel.rb
+++ b/core/src/main/ruby/jruby/kernel/kernel.rb
@@ -8,7 +8,12 @@ module Kernel
file = $` # just the filename
raise LoadError, "cannot infer basepath" if /\A\((.*)\)/ =~ file # eval etc.
- absolute_feature = File.expand_path(relative_arg, File.dirname(File.realpath(file)))
+ dir = File.dirname(file)
+ if File.exists?(dir)
+ absolute_feature = File.expand_path(relative_arg, File.dirname(File.realpath(file)))
+ else
+ absolute_feature = File.join(dir, relative_arg.sub(/\\.[^.\/]+$/, ''))
+ end
require absolute_feature
end will "fix" this original example but it will fail in case there is an empty directory searching some files or directories on the filesystem based on the PWD is not the right thing to do. |
I opted to make the Filename operand load the filename set into the containing scope, which makes it simple to set it in a single place when loading IR. Unsure whether this is the best approach or not.
I pushed a change that makes AOT-compiled IR set a proper FILE based on how it was loaded. My approach was to make the Filename operand retrieve the filename from its containing scope, which delegates up to whatever the top scope is in that context. I'm not sure if this is the best way but it was simple to implement. |
|
I know this is changing behavior but I find it strange that FILE is transformed with AOT'd to be .class. It is the file it is loaded from but I think it means an AOT-version of a ruby file now has different outward appearange. It also means it is impossible to run debugging tools on AOT'd code. Can anyone comment on what would happen if we make FILE report original .rb instead of its ultmate .class? |
After talking to @headius I think my desire for this change is unimportant for this particular fix. If we are running debugging tools and AOT those instructions into the compiled class it will emit the actual name so FILE is less clear how it is important (or not). Something about it still bugs me but I will open another issue when/if I can think of a better reason for disliking this .rb/.class mismatch on AOT'd file. |
so my suspicion on anyways can we close this one now ? |
@mkristian If there's no other changes needed for require_relative and friends, we can close this. FILE behavior should match 1.7 now. |
I successfully transferred an application running a large number of
Ruby programs in a JAR from jruby-complete-1.7.19 to jruby-complete-9.0.0.0.
However, when I use JRUBYC to compile one or more of the ruby programs to
Java classes (e.g replacing test2.rb by test2.class in the same position in
the JAR filestructure) I get "LoadError: no such file to load -- test2" as a result of 'require "tes2"'
This worked fine in all previous versions of JRuby but maybe the procedure has changed?
The text was updated successfully, but these errors were encountered: