AOT + War?

Can you use AOT compilation and a war together to deploy a rails app
(for obfuscation via class files instead of including raw ruby source
in the jar)? If so, is this possible with default warbler, or do we
need to do something special? Any links or references are welcome.
Here’s one old thread I found, but I’m not sure what the current
status is:

http://archive.codehaus.org/lists/org.codehaus.jruby.user/msg/[email protected]

Thanks…


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Sep 24, 2009 at 10:48 AM, Chad W. [email protected]
wrote:

Can you use AOT compilation and a war together to deploy a rails app
(for obfuscation via class files instead of including raw ruby source
in the jar)? If so, is this possible with default warbler, or do we
need to do something special? Any links or references are welcome.
Here’s one old thread I found, but I’m not sure what the current
status is:

http://archive.codehaus.org/lists/org.codehaus.jruby.user/msg/[email protected]

Just found this more recent thread (still almost a year old). Any new
status on this?

http://jruby.markmail.org/message/47c4q46sqlxkoh4o


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Sep 24, 2009 at 12:03 PM, Chad W. [email protected]
wrote:

Just found this more recent thread (still almost a year old). Any new
status on this?

Re: [jruby-user] Compiling Rails app/**/* to .class files - Charles Oliver Nutter - org.codehaus.jruby.user - MarkMail

So, we sort of hacked this to work in a test app. We manually deleted
our .rb files before creating a war with warbler, and had to vendor
rails and apply this patch:

http://jruby.markmail.org/message/qe2cwxnjhy3qdfgv

THere was also a problem with default routes working, we had to put an
explicit route for it to find a controller. Probably more stuff
hardcoded to .rb in the Rails routing code.

It doesn’t look like these patches ever made it into rails. Is anyone
else playing with this or have it working?

Thanks…


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Thu, Sep 24, 2009 at 11:01 PM, Daniel S.
[email protected] wrote:

I’ve got about a dozen sites running live on compiled rails code (the
compiling and warring is all a big custom mess). The following is all
the fixes I need for rails 2.2.2:

Thanks a lot Daniel, this worked for us so far. The only catch was
that the ActionController patch had to come after the Rails
Initializer block, the other two were before.

Below is the rake task we hacked up to compile and build the war with
warbler. Annoyances were:

  1. jrubyc doesn’t take a glob like app/**/*.rb, it has to have a
    dirname or a file apparently
  2. jrubyc doesn’t return a nonzero return code if something fails
    compilation, so you can’t know if you are building a broken war unless
    we grepped the output for “Failure” or something.

I should enter these as jrubyc bugs if they aren’t already, and your
patches should get put into rails…

desc “Package a warbler war with compiled (‘obfuscated’) rails app
classes”
task :compiled_war => [“war:app”, “war:public”, “war:webxml”] do

Compile the classes

war_files_path = “#{RAILS_ROOT}/tmp/war/WEB-INF”
dirs_to_compile = [
“app”,
“lib”
#“vendor/plugins”
]
compile_cmd = “cd #{war_files_path} && jruby -S jrubyc
#{dirs_to_compile.join(’ ')}”
puts “Compiling: '#{compile_cmd}”
system(compile_cmd) || raise(“Error compiling jruby”)

remove compiled .rb files

files_to_delete = dirs_to_compile.map {|dir|
Dir.glob(“#{war_files_path}/#{dir}/**/*.rb”)}.flatten
FileUtils.rm_f(files_to_delete)

Rake::Task[“war:jar”].invoke
end

– Chad


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

THere was also a problem with default routes working, we had to put an
explicit route
for it to find a controller. Probably more stuff hardcoded to .rb in
the Rails routing code.

It doesn’t look like these patches ever made it into rails. Is anyone
else playing with
this or have it working?

I’ve got about a dozen sites running live on compiled rails code (the
compiling and warring is all a big custom mess). The following is all
the fixes I need for rails 2.2.2:

#require ‘activesupport/dependencies’
ActiveSupport::Dependencies.module_eval do
def search_for_file(path_suffix)
path_suffix = path_suffix + ‘.rb’ unless path_suffix.ends_with?
‘.rb’
load_paths.each do |root|
path = File.join(root, path_suffix)
return path if File.file? path
path = File.join(root, path_suffix.sub(/.rb$/,’.class’))
return path.sub(/.class$/,’’) if File.file? path
end
nil
end
end

Rails::Initializer.module_eval do
def load_application_classes
if configuration.cache_classes
configuration.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}(.)(?:.rb|.class)\Z/
Dir.glob("#{load_path}/**/
").sort.each do |file|
if matcher === file
require_dependency $1
end
end
end
end
end
end

ActionController::Helpers::ClassMethods.module_eval do
def all_application_helpers
extract =
/^#{Regexp.quote(ActionController::Helpers::HELPERS_DIR)}/?(.)_helper.
(?:rb|class)$/
Dir["#{ActionController::Helpers::HELPERS_DIR}/**/
_helper.*"].map {
|file|
file.sub extract, ‘\1’ if extract === file
}.compact
end
end


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Sep 25, 2009 at 5:25 PM, Chad W. [email protected]
wrote:

I should enter these as jrubyc bugs if they aren’t already, and your
patches should get put into rails…

Bugs opened:

http://jira.codehaus.org/browse/JRUBY-4004

http://jira.codehaus.org/browse/JRUBY-4005

http://jira.codehaus.org/browse/JRUBY-4006


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email