I have created a gem that exposes an executable that works under Linux. In Windows, if I navigate to the directory where the gem is installed I can run it from the command line, but I have to specify -Ilib
myself when invoking ruby
.
I want use Ocra to turn the executable + dependencies (the rest of the gem) + Ruby into an exe file for other users, but the documentation seems to be saying that manually messing with load path is a bad idea with Ocra.
How do I tell Ocra to work with a gem's executable scripts without messing with Ruby's load path myself? I guess this would depend on there being some way I can run the executable scripts that takes advantage of the fact that they are part of an installed gem and figures out the dependencies for me.
My question proved to require a two part answer:
The underlying ignorance regarding how Rugbygems packages executables in Windows: it puts them in a bin/ directory in the ruby install directory, which was added to the path when Ruby was installed. The scripts themselves are not executable, but Rubygems creates a .bat
file wrapper for each executable, e.g. for mygem.rb
an accompanying mygem.rb.bat
file which will run from anywhere on the command prompt.
The ocra script can therefore be run using the following: ocra path/to/Ruby/bin/mygem.rb
.
Beware if you start up some sort of server as part of your executable it may end up running when you run ocra, and never move on to creating the executable. Therefore necessary to check for whether ocra is running before starting up the server:
if not defined? Ocra
#do server startup stuff here
end
In fact I ended up creating an "installer" script with the if not defined?
code in it so as not to mess with my executable script that I might want for other purposes.