[ANN] RubyScript2Exe 0.2.0

E

Erik Veenstra

I did a test (on Linux) with the progressbar example. Yes,
RubyScript2Exe detects progressbar.rb [1] and yes, it is
included in the executable [2]. But when the executable is
run, require_gem only searches for progressbar.rb in its
own dirs, not in the regular places. Resulting in an
Gem::LoadError.

There are a couple of ways of attacking this. You /could/
replicate the gem metadata (not really recommended). Perhaps
supplying a custom require_gem that works in your packaged
app. I think the only thing the custom require_gem would need
to do is do a require on that gems autorequire file (if any).

RubyScript2Exe executes the application, in order to trace it,
with (simplified):

$ ruby -r require2lib app.rb

This require2lib sets an at_exit block. In this block, all
required and loaded files are copied to ./lib . This ./lib is
packed into the executable and recreated on the destination
machine just before doing something like:

$ ruby -I ./lib app.rb

That's part of the job RubyScript2Exe does to satisfy the
requirements (besides ruby.exe and ruby.dll and a bunch of
recursively determined dll's en so's).

This copying works for files required via require_gem as well,
because the old require is still done by require_gem, so they
show up in $". Checked that. It works. It's just that
rubygems.rb doesn't work properly on the targeted machine,
because it expects its own environment, which is not recreated.
My plan was to overwrite this rubygems.rb which a version of my
own, only implementing require_gem. I came up with the code
below.

Any RubyGems hackers willing to have a look at it? Just
shoot...

Thanks in advance.

gegroet,
Erik V.

----------------------------------------------------------------

at_exit do

# Copy the required files to ./lib .

$".each do |req|
...
end

# Overwrite rubygems.rb with my own version of require_gem.

autorequire = {}

Gem::Specification.list.each do |gem|
unless gem.autorequire.nil?
unless $".collect{|s| (s =~ /^#{gem.autorequire}\.\w+$/)}.compact.empty?
autorequire[gem.name] = gem.autorequire
end
end
end

File.open("./lib/rubygems.rb", "w") do |f|
f.puts "module Kernel"
f.puts " def require_gem(file, version=nil)"
f.puts " autorequire = %s" % autorequire.inspect
f.puts " file = autorequire[file]"
f.puts " require(file) unless file.nil?"
f.puts " end"
f.puts "end"
end
end

----------------------------------------------------------------
Contact me (or another gem developer) if you need help
pursuing this. We would be glad to help.

(I tried, no response...)
 
E

Erik Veenstra

File.open("./lib/rubygems.rb", "w") do |f|
f.puts "module Kernel"
f.puts " def require_gem(file, version=nil)"
f.puts " autorequire = %s" % autorequire.inspect
f.puts " file = autorequire[file]"
f.puts " require(file) unless file.nil?"
f.puts " end"
f.puts "end"
end

Resulting in:

module Kernel
def require_gem(file, version=nil)
autorequire = {"activerecord"=>"active_record"}
file = autorequire[file]
require(file) unless file.nil?
end
end
 
S

steven_todd_harris

This sounds cool. Anyone know what it would take to have this for OS X?
It would be cool to be able to use RubyCocoa or TKRuby or QTRuby and
then
make it into an executable easily.

Florian said:
Erik said:
I just want to say that RubyScript2Exe 0.2.0 [1] has been
released. Both Windows and Linux are supported.

Is a change list available somewhere? I couldn't find one on the homepage.

Also while I'm writing to you, would it be possible to allow custom
.DLLs and resources to be added? I have an application that uses a C++
extension which loads more .DLLs -- RubyScript2Exe does not
automatically include those and I can't find a way of manually including
them that works. (I can unpack and repackage, but then the .DLLs will
 
E

Erik Veenstra

Florian said:
I just want to say that RubyScript2Exe 0.2.0 [1] has been
released. Both Windows and Linux are supported.

Thank you for a great library!

This sounds cool. Anyone know what it would take to have this
for OS X?

You need "FreePascal on the Macintosh" [1] and a machine with
OS X. Since I'm the only developer of RubyScript2Exe and not
possessing such a machine, it will probably never happen.
Unless somebody is able and willing to do the porting... Or
provides a SSH connection... I don't think it's to hard to do.
It would be cool to be able to use RubyCocoa or TKRuby or
QTRuby and then make it into an executable easily.

The bindings for QT and TK are detected and included in the
executable. QT and TK themselfs are not detected, because they
have nothing to do with Ruby. They have to be installed
manually.

gegroet,
Erik V.

[1] http://www.freepascal.org/fpcmac.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top