views:

290

answers:

2

I've been learning Ruby recently, and I've not gotten into the dirty recesses of learning Rake yet. I've been playing around with NetBeans, and I made a little Ruby project with a file that simply prints "Hello, World!". I was looking at the Rakefile that NetBeans generates, and I noticed that it had commented out the s.executables line, so I uncommented, and tried to build it. Of course it failed with:

Don't know how to build task 'bin/your_executable_here'

What I'm trying to do, is figure out how to make that work. I've googled around, and I can't find any information on how to correctly generate an executable. Here is the Rakefile generated by NetBeans:

require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'

spec = Gem::Specification.new do |s|
  s.name = 'Learning'
  s.version = '0.0.1'
  s.has_rdoc = true
  s.extra_rdoc_files = ['README', 'LICENSE']
  s.summary = 'Your summary here'
  s.description = s.summary
  s.author = ''
  s.email = ''
  s.executables = ['your_executable_here']
  s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
  s.require_path = "lib"
  s.bindir = "bin"
end

Rake::GemPackageTask.new(spec) do |p|
  p.gem_spec = spec
  p.need_tar = true
  p.need_zip = true
end

Rake::RDocTask.new do |rdoc|
  files =['README', 'LICENSE', 'lib/**/*.rb']
  rdoc.rdoc_files.add(files)
  rdoc.main = "README" # page to start on
  rdoc.title = "Learning Docs"
  rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
  rdoc.options 

I'm sorry if this is a stupid question, I honestly did try to find the information myself.

EDIT: I was unaware that there had to be an executable file by the same name as the default one you specify in ./bin in your project. I figured it all out.

+1  A: 

This code is used to make a gem file. Gems are ruby's package management devices. Some gems come with executable script files to be run from the command line. They are placed in the ./bin directory when the gem is built, and hen it is deployed they will be copied into the same folder as the ruby executable.

To make a file executable you will need to add a shabang (#!/user/local/bin/ruby) to the first line and change the file permission to allow execution.

John F. Miller
So, what exactly do I need to do to make it do this? It just gives me that "Don't know how to build task 'bin/testexe'" error. Am I supposed to put the file in the bin folder relative to the Rakefile? Because I tried that, and it continued to give me the error. I'm beginning to wonder if this maybe isn't just a NetBeans problem...
Rayne
Never mind, my stupid ass figured it out. :\, thanks for your help.
Rayne
+1  A: 

The s.executables array must contain the names of the executables in the bin directory of your gem

 s.executables = %w( my_awesome_commandline_churner )
Julik
Correct, it appears that nobody cares to document that very well. :p
Rayne
See: http://docs.rubygems.org/read/chapter/20#executablesAlso, when in doubt look at how everyone else does it.
Matt Haley