Rake - running a sequence of tasks

663 views Asked by At

I'm using Rake to compile some annoying LaTeX stuff.

As a matter of fact, I'd like to clean my working dir before and after compiling. So I defined two tasks: :clean and :compile.

Somehow naively, I wrote this:

task :default => [:clean, :compile, :clean]

but, as I discovered a little later while reading Rake's docs, this won't work because the array of tasks contains dependencies, not actions to make.

So, is there a clean way to execute a sequence of tasks without invoking them manually with Rake::Task("clean") etc.? Something similar to the dependencies array.

1

There are 1 answers

0
Patru On

Just define your dependencies and rely on rake to figure out a valid order. Of course you will have a little trouble to execute the :clean task more than once, but you can reenable it or use an alias. Or you can define

def clean
   ...
end

task :default => [:clean_after_compile]
task :clean_after_compile => [:compile] do clean end
task :compile => [:clean_before_compile]
task :clean_before_compile => [:compile] do clean end

in order to stay somewhat dry. As rake deals with dependencies and not with sequences it might just turn out to be a little more work than you liked.