On Thu, 14 Dec 2006 17:40:06 +0900, Alex Fenton  
<alex / deleteme.pressure.to> wrote:

> Zev Blut wrote:
>
>> My attempts to make a gem have failed.  I think because Saikuro wants
>> to be installed as an application in /bin.
>
> Take a look at the 'executables' setting within the gemspec
>
> http://rubygems.org/read/chapter/20#executables
>
> This will install the listed executable files into the bin directory  
> where the ruby executable is, which will commonly be in PATH (eg  
> /usr/local/bin)

Yes thank you I have already looked into this.

It appears I have made two mistakes when it comes to using RubyGems.

I did use the executables option, but I am not sure it was designed to
work the way I wrote Saikuro.  Here are the two problems:

1)
Saikuro uses the "if __FILE__ == $0" check before doing the
"application work".  When RubyGems creates a new gemified saikuro
wrapper to call the real saikuro bin "$0" is the gemified saikuro and
not the real one.  Thus, by default nothing happens.

For fun I cheated and commented out the "if __FILE__" check and
replaced it with "if true".  I then ran "saikuro -?" to get a usage
message and found the next problem:

2)
I was reading through the Programming Ruby book and found a part that
showed how to use rdoc to create usage messages.  I figured this might
be better than my normal technique so I used it in saikuro.  This has
caused a number of problems actually.

* With the above cheat I get the gem message:
--
/usr/bin/saikuro: invalid option -- ?
This file was generated by RubyGems.

The application 'Saikuro' is installed as part of a gem, and this file
is here to facilitate running it.
--

Which is not the usage message I wanted.

* Part two is only somewhat related to gems but also a bug in Ruby
1.8.5 's rdoc API that makes this actually give an error due to it
not being able to require an options file.  This is fixed in the
Ruby head, but not in the official release.

So I am wondering what is the best practice for this?

I could always separate saikuro into a lib and bin file.  The bin file
will not do the if __FILE__ check.  This should then work with
RubyGems, but of course I need to drop the rdoc usage technique.

My original goal was to keep saikuro simple so that as a single file
nothing complicated was needed.  But now I suppose that should change.

Here is my basic gemspec file if someone wants to show me a better
technique.

----------------------------------------------------------------------
require 'rubygems'

spec = Gem::Specification.new do |s|
   s.name = "Saikuro"
   s.version = "1.0.0"
   s.author = "Zev Blut"
   s.homepage = "http://saikuro.rubyforge.org/"
   s.rubyforge_project = 'saikuro'
   s.platform = Gem::Platform::RUBY
   candidates = Dir.glob("{bin,tests}/**/*")
   s.files = candidates.delete_if do |item|
     item.include?(".svn") || item.include?("rdoc")
   end
   s.executables = ['saikuro']
   s.has_rdoc = true
   s.extra_rdoc_files = ["README"]
end

if __FILE__ == $0
   Gem::manage_gems
   Gem::Builder.new(spec).build
end
----------------------------------------------------------------------


Thanks,
Zev