Compiling Rails app/**/* to .class files

Does anyone know if compiling rb files to class files using jrubyc works
with Rails?

Rich

Rich M. wrote:

Does anyone know if compiling rb files to class files using jrubyc works
with Rails?

I believe Peter Chan was doing something with this, and possible Ricardo
Trinidade…you guys out there?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I compiled a subset of Rails, activerecord and activesupport, into java
byte code and found it working very well in my app.

Peter

Did my own test on an existing JRoR app (jrubyc app/) and it didn’t
work.
Complained about an application_support dependency. Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich

Thanks! I’ll create a rake task to compile everything in my app dir and
see
if it works.

Rich

Can you post the exact error message?

I haven’t noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:[email protected]]
Sent: Friday, October 10, 2008 3:01 PM
To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn’t
work.
Complained about an application_support dependency. Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
[email protected]
wrote:
Thanks! I’ll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan [email protected] wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter

Here’s what I did:

jrubyc app/
jruby script/server ← rb/class files together… works fine.
rm find app/ -name "*.rb"
jruby script/server ← class files only… fails with the following error:

=> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_support/dependencies.rb:512:in
require': uninitialized constant ApplicationHelper (NameError) from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.rb:39 from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.rb:27:in require’
from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
from script/server:3

Thoughts?

Rich

Looks like the dependencies module in active support tries to load
dependencies by appending the .rb to the constant names which is why
it’s
failing. I’m patching these now to see if I can get it to work.

More to come…

Rich

I don’t use the full Rails framework myself, so I have to defer other
experts
on this subject.

The only thing that I can think of is for you to trace where the error
originates. Figure out what file defines ApplicationHelper and what line
is
loading it, and from that point determine what is not working in loading
the
compiled file.

You may also find it helpful to leave the source file and see if the app
can
pick that up, instead of the compiled version.

Peter

From: Rich M. [mailto:[email protected]]
Sent: Friday, October 10, 2008 3:42 PM
To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Here’s what I did:

jrubyc app/
jruby script/server ← rb/class files together… works fine.
rm find app/ -name "*.rb"
jruby script/server ← class files only… fails with the following error:

=> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_supp
ort/dependencies.rb:512:in require': uninitialized constant ApplicationHelper (NameError) from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server. rb:39 from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server. rb:27:in require’
from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.r
b:27:in `require’
from script/server:3

Thoughts?

Rich
On Fri, Oct 10, 2008 at 1:30 PM, Peter K Chan [email protected] wrote:
Can you post the exact error message?

I haven’t noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:[email protected]]
Sent: Friday, October 10, 2008 3:01 PM
To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn’t
work.
Complained about an application_support dependency. Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
[email protected]
wrote:
Thanks! I’ll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan [email protected] wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter

I’ll wait to see from Rich, but you’re right, it should try to find both
foo.class and foo.rb (in that order) if you require ‘foo.rb’, but I’m
not sure whether we made it do that for load or not. I’d have to check
the code, and I’m working on something else at the moment.

Peter K Chan wrote:

From: Rich M. [mailto:[email protected]]
More to come…
The only thing that I can think of is for you to trace where the error
From: Rich M. [mailto:[email protected]

jruby script/server ← rb/class files together… works fine.
JRuby limited openssl loaded. gem install jruby-openssl for full support.
/Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server.
mailto:[email protected]> wrote:
I just compiled activerecord and activesupport, ensure that the resulting
Did my own test on an existing JRoR app (jrubyc app/) and it didn’t work.
if it works.
-----Original Message-----
with Rails?


http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I seem to remember that JRuby automatically handles loading file ending
in .rb
to using the compiled version. But it has been a while (and a few
versions),
so maybe you need to discard the .rb suffix.

Peter

From: Rich M. [mailto:[email protected]]
Sent: Friday, October 10, 2008 5:02 PM
To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Looks like the dependencies module in active support tries to load
dependencies by appending the .rb to the constant names which is why
it’s
failing. I’m patching these now to see if I can get it to work.

More to come…

Rich

On Fri, Oct 10, 2008 at 2:48 PM, Peter K Chan [email protected] wrote:

I don’t use the full Rails framework myself, so I have to defer other
experts
on this subject.

The only thing that I can think of is for you to trace where the error
originates. Figure out what file defines ApplicationHelper and what line
is
loading it, and from that point determine what is not working in loading
the
compiled file.

You may also find it helpful to leave the source file and see if the app
can
pick that up, instead of the compiled version.

Peter

From: Rich M. [mailto:[email protected]]

Sent: Friday, October 10, 2008 3:42 PM

To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Here’s what I did:

jrubyc app/
jruby script/server ← rb/class files together… works fine.
rm find app/ -name "*.rb"
jruby script/server ← class files only… fails with the following error:

=> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment…
JRuby limited openssl loaded. gem install jruby-openssl for full
support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Exiting
/Users/richmanalang/dev/connect.git/vendor/rails/activesupport/lib/active_supp
ort/dependencies.rb:512:in require': uninitialized constant ApplicationHelper (NameError) from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server. rb:39 from /Users/richmanalang/dev/connect.git/vendor/rails/railties/lib/commands/server. rb:27:in require’
from
/Users/richmanalang/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.r
b:27:in `require’
from script/server:3

Thoughts?

Rich
On Fri, Oct 10, 2008 at 1:30 PM, Peter K Chan [email protected] wrote:
Can you post the exact error message?

I haven’t noticed any problem with loading compiled code, compared to
ruby
source. Mixed loading of compiled and plain source also worked. You may
want
to double check to make sure that you have at least something called
application_support.rb or application_support.class (with the
appropriate java
package prefix, if applicable) and that it is inside the loadpath or
classpath.

I just compiled activerecord and activesupport, ensure that the
resulting
files are in classpath, and was able to load them from my application
code.

Peter

From: Rich M. [mailto:[email protected]]
Sent: Friday, October 10, 2008 3:01 PM
To: [email protected]
Subject: Re: [jruby-user] Compiling Rails app/**/* to .class files

Did my own test on an existing JRoR app (jrubyc app/) and it didn’t
work.
Complained about an application_support dependency. Looking into it
further.

Peter, did you compile your app source or just the vendor/rails dir?

Rich
On Fri, Oct 10, 2008 at 12:00 PM, Rich M.
[email protected]
wrote:
Thanks! I’ll create a rake task to compile everything in my app dir and
see
if it works.

Rich

On Thu, Oct 9, 2008 at 11:33 PM, Peter K Chan [email protected] wrote:
I compiled a subset of Rails, activerecord and activesupport, into java
byte
code and found it working very well in my app.

Peter

Ok… I got it to work (compiled app/ and lib/), but I had to modify
rails/activesupport/lib/active_support/dependencies.rb. This file loads
all
deps during rails initialization and looks specifically for *.rb files.
I
had to add *.class to the searches.

I’ve attached the diff. I’d love for rails to be able to do this
automatically, how would you guys suggest getting this stuff to rails
core?

Rich

On Fri, Oct 10, 2008 at 3:12 PM, Charles Oliver N. <

FYI – I’ve forked rails and added my changes here:

http://github.com/manalang/rails/commit/29de7f2746e4809e8f1e010bda558ab32c522f43

Rich

Rich M. wrote:

Ok… I got it to work (compiled app/ and lib/), but I had to modify
rails/activesupport/lib/active_support/dependencies.rb. This file loads
all deps during rails initialization and looks specifically for *.rb
files. I had to add *.class to the searches.

I’ve attached the diff. I’d love for rails to be able to do this
automatically, how would you guys suggest getting this stuff to rails core?

I think we should actually modify JRuby so that “load ‘foo.rb’” will
also look for .class, since basically this is like .py/.pyc in Python
and .rb/.rbc in Rubinius; the .class version should be treated as an
equivalent compiled version of the .rb file.

Agreed? I think we may have had a bug on this previous and either not
fixed it or punted on it, since it’s obviously not doing that.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I agree this should be in JRuby, but it looks like ActiveSupport
overrides
load and require… which is why it doesn’t work out of the box.

Rich

On Tue, Oct 14, 2008 at 5:22 PM, Charles Oliver N. <

Rich M. wrote:

I agree this should be in JRuby, but it looks like ActiveSupport
overrides load and require… which is why it doesn’t work out of the box.

Eventually it needs to fall back on require/load logic though, which is
where JRuby is falling down:

~/projects/jruby âž” vi foo.rb

~/projects/jruby âž” jrubyc foo.rb
Compiling foo.rb to class foo

~/projects/jruby âž” rm foo.rb

~/projects/jruby âž” jruby -e “load ‘./foo.rb’”
-e:1:in `load’: No such file to load – ./foo.rb (LoadError)
from -e:1

~/projects/jruby âž” jruby -e “load ‘./foo.class’”
here

I will file a bug for 1.1.5. I see the light now, and believe load
should search for both .class and .rb when requested to load xxx.rb.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email