On Thu, Feb 19, 2009 at 1:34 PM, Tim Pease <tim.pease / gmail.com> wrote:
>
> On Feb 18, 2009, at 10:06 PM, Ryan Davis 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|
>>> =A0task :test =3D> [:build]
>>> =A0test.libs << 'ext'
>>> =A0test.warning =3D true
>>> =A0test.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
>> =A0after
>> end
>>
>> One problem with Tim's suggestion:
>>
>>> task :test do
>>> Rake.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:
>>
>
> The Rake::Task#execute method will always run the task regardless of whet=
her
> it has been run previously. You are thinking of the Rake::Task#invoke met=
hod
> -- this method ensures the task is only executed once.

Interestingly, I discovered that the Rake::Task.execute approach you
suggested broke with Rake 0.8.1. It worked fine after I upgraded to
0.8.3.

Don't ask me how I forgot to upgrade Rake on this particular system,
but there you go.

Regards,

Dan