[ANN] RubyScript2Exe 0.2.0

E

Erik Veenstra

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

gegroet,
Erik V.

[1] http://www.erikveen.dds.nl/rubyscript2exe/index.html

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

RubyScript2Exe transforms your Ruby script into a standalone
Windows or Linux executable. You can look at it as a
"compiler". Not in the sense of a source-code-to-byte-code
compiler, but as a "collector", for it collects all necessary
files to run your script on an other machine: the Ruby script,
the Ruby interpreter and the Ruby runtime library (stripped
down for this script). Anyway, the result is the same: a
standalone exe-file (Windows) or bin-file (Linux). And that's
what we want!

Because of the gathering of files from your own Ruby
installation, RubyScript2Exe creates an executable for the
platform it's being run on. No cross compile.

And when I say Windows, I mean both Windows (RubyInstaller,
MinGW and MSWin32) and Cygwin. But the generated exe under
Cygwin is very, very big, because its exe's are very big
(static?) and it includes cygwin1.dll, so it can run on
machines without Cygwin.

----------------------------------------------------------------
 
F

Florian Gross

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
still not get loaded from the temporary directory.)

Being able to easily include own media would also be very nifty in my
use case. (I'm writing games with Ruby -- it's always nice to have a
single EXE distribution that contains all the game media.)

Thank you for a great library!
 
E

Erik Veenstra

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.

It's there, really... The Download section [1] has a link to
both [2] and [3]. I think you are interested in [2].
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 still not
get loaded from the temporary directory.)

There's a link to Tar2RubyScript [4] on the page as well.
Tar2RubyScript generates a standalone Ruby script from an
existing directory, which contains a complete Ruby application
(scripts, DLL's and resources). This standalone Ruby script can
be converted to an executable with RubyScript2Exe.

That's how I distribute all my applications, complete with
resources, help files, licenses, readme, images, default
configurations, everything. Even including the graphical front
end (WXRuby or RubyWebDialogs [5]). And it just works...
Being able to easily include own media would also be very
nifty in my use case. (I'm writing games with Ruby -- it's
always nice to have a single EXE distribution that contains
all the game media.)

Thank you for a great library!

[1] http://www.erikveen.dds.nl/rubyscript2exe/index.html#6..Download
[2] http://www.erikveen.dds.nl/rubyscript2exe/download.html
[3] http://www.erikveen.dds.nl/rubyscript2exe/history.txt.html
[4] http://www.erikveen.dds.nl/tar2rubyscript/index.html
[5] http://www.erikveen.dds.nl/rubywebdialogs/index.html
 
E

Erik Veenstra

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

Will this support all manner of 'require'd files, including
those loaded by the gems require-hack?

Never worked with gems before...

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. If I
catch this exception, it does work. See below.

I'll have a look at it.

Thanks.

gegroet,
Erik V.

[1] /usr/local/lib/ruby/gems/1.8/gems/progressbar-0.0.3/lib/progressbar.rb
[2] ./lib/progressbar.rb

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

Development machine:

[erik@devel]$ ruby rubyscript2exe.rb testgem.rb
Tracing testgem...
Gathering files...% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00
Copying files...
Copying /lib/ld-linux.so.2 ...
Copying /usr/local/bin/ruby ...
Copying /scratch/testgem.rb ...
Creating testgem.bin ...

Test machine:

[erik@test1]$ ./testgem.bin
Example progr: 100% |oooooooooooooooooooooooooooooooooooooooo| ETA: 00:00:00

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

# Doesn't work.

require 'rubygems'
require_gem 'progressbar'

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

# Does work.

require 'rubygems'
begin
require_gem 'progressbar'
rescue Gem::LoadError
require 'progressbar'
end

----------------------------------------------------------------
 
G

Gavin Sinclair

Will this support all manner of 'require'd files, including
those loaded by the gems require-hack?

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

# Doesn't work.

require 'rubygems'
require_gem 'progressbar'

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

# Does work.

require 'rubygems'
begin
require_gem 'progressbar'
rescue Gem::LoadError
require 'progressbar'
end

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

Try:

require 'rubygems'
require 'progressbar'

Cheers,
Gavin
 
M

Mauricio Fernández

Will this allow nested (gem and non-gem) requires within 'progressbar' to
work?

require 'foo' will always load the version from RubyGems, if you're
referring to that. Once you require 'rubygems', it overrides
Kernel.require and it is no longer possible to load the files in the
standard library dir, unless you use the GEM_SKIP env. variable.
Is the "ruby -r ubygems myfile.rb" and then just plain "require progressbar"
no longer recommended? Or the environment variable GEM_PATH (on WinXP) ?

ruby -rubygems foo is equivalent to doing a require 'rubygems'...
 
J

James Edward Gray II

require 'foo' will always load the version from RubyGems, if you're
referring to that. Once you require 'rubygems', it overrides
Kernel.require and it is no longer possible to load the files in the
standard library dir, unless you use the GEM_SKIP env. variable.

Hmm, is this a good thing? If Ruby Gems replaces the require(),
couldn't it be set to try the old require() when a Gem require fails?
Just a thought.

James Edward Gray II
 
M

Mauricio Fernández

Hmm, is this a good thing? If Ruby Gems replaces the require(),
couldn't it be set to try the old require() when a Gem require fails?
Just a thought.

I didn't phrase that correctly. require 'foo' will load preferentially
the file in the gemdir (instead of the one in sitelibdir as usual).
 
E

Erik Veenstra

Will this support all manner of 'require'd files,
including those loaded by the gems require-hack?

[......]

Try:

require 'rubygems'

require 'progressbar'

$ grep * -wie def | grep -wie require
loadpath_manager.rb: def require(file)

Looks like RubyGems does an overwrite of Kernel.require:

module Kernel
alias require__ require
def require(file)
Gem::LoadPathManager.search_loadpath(file) || Gem::LoadPathManager.search_gempath(file)
require__(file)
end
end

That will do the trick in our application. But what happens
when a library does a require_gem? Time for the next test. I
don't know Rails, but I think it has some dependencies. Just
giving it a shot...

Test 1:

$ cat test1.rb
require "rubygems"
require_gem "rails"

$ ruby test1.rb

Looks good. It's useless, but the dependencies are fullfilled.

Test 2:

$ cat test2.rb
require "rubygems"
require "rails"

$ ruby test2.rb
/usr/local/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require__': No such file to load -- rails (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:in `require'
from test2.rb:2

Oops! I think it hasn't anything to do with dependencies. The
trick doesn't work.

Any RubyGem hacker, out there?

gegroet,
Erik V.
 
J

Jim Weirich

Erik Veenstra said:
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.

require_gem does not search for progressbar.rb. It searches for the
progressbar *gem* (progressbar.rb gets required as a side effect if the
gem specifies an autorequire file). Since you are not replicating the
gems metadata structure in your packaged app, its not surprizing that it
is not found.

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).

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

James Edward Gray II

I didn't phrase that correctly. require 'foo' will load preferentially
the file in the gemdir (instead of the one in sitelibdir as usual).

That makes a lot more sense to me. Thanks for setting me straight.

James Edward Gray II
 
J

Jim Weirich

Mauricio Fernández said:
I didn't phrase that correctly. require 'foo' will load preferentially
the file in the gemdir (instead of the one in sitelibdir as usual).

Actually, this isn't accurate either.

Gems will only prefer the gem based file if the gem containing that file
has been activated.

Things that will activate a gem:

* an explicit require_gem
* requiring of a file not found in the current load path, but
can be found in a gem.

Once activated, files from the activated gem will be preferred. However,
files from unactivated gems will continue to be preferred from the
existing load path.
 
A

Aredridel

Mauricio Fernández said:


Actually, this isn't accurate either.

Gems will only prefer the gem based file if the gem containing that file
has been activated.

Things that will activate a gem:

* an explicit require_gem
* requiring of a file not found in the current load path, but
can be found in a gem.

Once activated, files from the activated gem will be preferred. However,
files from unactivated gems will continue to be preferred from the
existing load path.

Wow. That's delightfully polite. I like it!
 
J

Jim Weirich

itsme213 said:
I am trying to settle on one standard way to use my gems transparently
i.e.
without something like 'require_gem' (or was that 'gem_require'?). While
GEM_PATH seems to work, it appears to cause problems with other apps or
libs that assume Rubys standard directory layout.

Advice?

If you don't care what version you get, just do a normal require. In
addition, you need to make sure the rubygems library is loaded. You can
do this by:

* explicitly requiring 'rubygems' before requiring any file
that would be in a gem.[1]
* explicitly starting ruby with a -rubygems command line option.
* Setting the RUBYOPT environment variable to 'rubygems'

If you /do/ care about which the version of a gem you are using, then use
a require_gem command with explicit versioning requirements. Again, make
sure the rubygems library is loaded using one of the above three
techniques.

Regarding your GEM_PATH comment, I'm not sure what you are getting at.
GEM_PATH is for specifying where multiple gem repositories are locally
stored. Were you refering to RUBYOPT?

--
-- Jim Weirich (e-mail address removed) http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

[1] If you do choose to explicitly include rubygems, but don't
want to depend on rubygems always being available, do this:

begin
require 'rubygems'
rescue LoadError
end
 
F

Florian Gross

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

It's there, really... The Download section [1] has a link to
both [2] and [3]. I think you are interested in [2].

Thanks, while this is not exactly what I was looking for it is still
similar enough to be of help.
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 still not
get loaded from the temporary directory.)

There's a link to Tar2RubyScript [4] on the page as well.
Tar2RubyScript generates a standalone Ruby script from an
existing directory, which contains a complete Ruby application
(scripts, DLL's and resources). This standalone Ruby script can
be converted to an executable with RubyScript2Exe.

But will the .DLLs really be found when I use Tar2RubyScript? I think I
tried this without success.
 
J

Jim Weirich

itsme213 said:
Which would have gem's loadpath manager give me the latest gem-installed
version (assuming it is not in the current load path), true?

Yes.
 
J

Jim Weirich

itsme213 said:
Do you think tt may be good to have a gem-recommended way of dealing with
this more broadly? With gems gaining wider use this could be useful for
any
app (rubscript, an IDE, etc.) that needs to know about ruby's directory
structure, and hence about gems.

Coincidently, on the rubygems-dev mailing list we just had a discussion on
the value of identifying an "API" for gems that identifies some kind of
programatic interface for doing gem related things. These kinds of
operations certainly fall into that category.

Thanks for the feedback. We certainly want to head in that direction.
 
E

Erik Veenstra

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 still not get loaded from the temporary
directory.)

There's a link to Tar2RubyScript [4] on the page as well.
Tar2RubyScript generates a standalone Ruby script from an
existing directory, which contains a complete Ruby
application (scripts, DLL's and resources). This standalone
Ruby script can be converted to an executable with
RubyScript2Exe.

But will the .DLLs really be found when I use Tar2RubyScript?
I think I tried this without success.

I did it once. It was something like this:

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Newlocation the is path to "the internals of the package". (Of
course, it's a temp dir...)

But that only works when you directly access the DLL.
Otherwise, when you access the DLL indirectly, you have to
change the environment before starting the child process. Could
be done with:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
system("command")

You might have to combine them:

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

Not tested. Just an idea.

gegroet,
Erik V.
 
E

Erik Veenstra

Long lines... Sorry.
ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +
ENV["PATH"] system("command")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +
";" +
ENV["PATH"]

system("command")
ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" +
ENV["PATH"] api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P
P), "V")

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") +
";" +
ENV["PATH"]

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")
 
F

Florian Gross

Erik said:
But will the .DLLs really be found when I use Tar2RubyScript?
I think I tried this without success.
I did it once. It was something like this:

api = Win32API.new(newlocation("file.dll"), "proc", %w(P P P P), "V")

[...]

ENV["PATH"] = newlocation("bin/in/package").gsub(/\//, "\\\\") + ";" + ENV["PATH"]
system("command")

Not doing either of those though. I'm just require()ing a Ruby library
(C++ extension) that is dynamically linked against a few DLLs. One of
those is fmod.dll, but there's also msvcp71.dll and msvcr71.dll and a
custom one involved. I know that RubyScript2Exe is already able to
bundle the DLLs that Ruby uses so an option for adding the specified
DLLs in a similar way would be just what I need. I'm not sure if this
involves doing a Win32-API call to tell Ruby to also look for DLLs at
the location the executable was unpacked to. Does this sound possible?

Thanks a lot for helping out with this.
 

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

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top