Daniel Berger
2/19/2009 6:09:00 PM
On Feb 18, 10:06=A0pm, Ryan Davis <ryand-r...@zenspider.com> wrote:
> On Feb 18, 2009, at 07:15 , Daniel Berger wrote:
>
>
>
> > How do I run a task after the fact with Rake?
>
> > For example, I have a test task for a C extension. It looks something
> > like this:
>
> > Rake::TestTask.new('test') do |test|
> > =A0 task :test =3D> [:build]
> > =A0 test.libs << 'ext'
> > =A0 test.warning =3D true
> > =A0 test.verbose =3D true
> > end
>
> > That works fine, but I'd like it to run the "clean" task after it's
> > finished.
>
> > And no, simply sticking "task :test =3D> [:clean]" at the bottom of the
> > test task doesn't work.
>
> task :test =3D> :clean DOES work, just _before_ the fact, not after.
>
> to do after you attach another task to the same name:
>
> task :test do
> =A0 =A0after
> end
>
> One problem with Tim's suggestion:
>
> > task :test do
> > =A0Rake.application[:clean].execute
> > end
>
> is that it won't run if that dependency has already been met, so:
>
> % rake clean test
>
> won't run it after your test. You might prefer to do:
>
> > task :test do
> > =A0 sh "rake clean"
> > end
>
> instead.
Interesting, thanks.
> that said... why are you cleaning afterwards? I can imagine a number =A0
> of situations where that will screw you up. You probably DO want to =A0
> put :clean (pre) dependencies on a number of your tasks like packaging =
=A0
> and stuff, but having it after your test could introduce some hiccups.
>
> if it is a lengthy build/link, it'll also slow down code/test cycles.
It's a small C extension, meaning I have to :build before I run the
tests. That's fine, but it leaves the .so, .obj, etc, files laying
around afterward. So rather than running 'rake clean' (or running
'make distclean' manually) after every 'rake test', I just want the
build files cleaned up automatically because I have no use for them.
Regards,
Dan