[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Building extensions with Hoe

Alex Gutteridge

1/16/2007 1:53:00 AM

Hi,

I'm developing a library that includes a C extension, so during
development I need to keep re-compiling the extension before testing.

I'm using Hoe for packaging, so I've added the following task to my
Rakefile.rb which allows me to rebuild the extension using extconf.rb/
make. My library has a further dependency on an external C library
(libR), at the moment this is semi-hardcoded into the script by
referencing the environment variable R_HOME:

desc "Uses extconf.rb and make to build the extension"
task :build_extension do
Dir.chdir('ext')
system("ruby extconf.rb --with-R-dir=$R_HOME")
system("make")
Dir.chdir('..')
end

Two questions (I'm pretty new with Rake/Hoe so forgive me if these
are obvious):

1. The 'build_extension' task works fine, but seems a little hacky,
how do other people build extensions with Rake/Hoe?

2. Can I retrospectively add this task as a dependency of the 'test'
task, so that when I run my tests I can ensure the library is freshly
built?

Alex Gutteridge

Bioinformatics Center
Kyoto University



2 Answers

Eric Hodel

1/21/2007 2:37:00 AM

0

On Jan 15, 2007, at 17:53, Alex Gutteridge wrote:
> I'm developing a library that includes a C extension, so during
> development I need to keep re-compiling the extension before testing.
>
> I'm using Hoe for packaging, so I've added the following task to my
> Rakefile.rb which allows me to rebuild the extension using
> extconf.rb/make. My library has a further dependency on an external
> C library (libR), at the moment this is semi-hardcoded into the
> script by referencing the environment variable R_HOME:
>
> desc "Uses extconf.rb and make to build the extension"
> task :build_extension do
> Dir.chdir('ext')
> system("ruby extconf.rb --with-R-dir=$R_HOME")
> system("make")
> Dir.chdir('..')
> end
>
> Two questions (I'm pretty new with Rake/Hoe so forgive me if these
> are obvious):
>
> 1. The 'build_extension' task works fine, but seems a little hacky,
> how do other people build extensions with Rake/Hoe?

RubyGems looks for both an extconf.rb and an 'extension' rake task.

> 2. Can I retrospectively add this task as a dependency of the
> 'test' task, so that when I run my tests I can ensure the library
> is freshly built?

I'm not sure how to do this with rake, but we'd accept a patch to Hoe.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Devin Mullins

1/21/2007 3:26:00 AM

0

Alex Gutteridge wrote:
> 2. Can I retrospectively add this task as a dependency of the 'test'
> task, so that when I run my tests I can ensure the library is freshly
> built?
Yes. I forget exactly, but it's something easy like
Rake::Task['test'].prerequisites << 'build_extension'.

Devin