3
votes

is there any way to force the execution of task in Rake, even if the prerequisites are already met?

I am looking for the equivalent of the --always-make option for GNU/make (http://www.gnu.org/software/make/manual/make.html#Options-Summary )

Example Rakefile:

file "myfile.txt" do
    system "touch myfile.txt"
    puts "myfile.txt created"
end

How would the --always-make option work:

# executing the rule for the first time creates a file:
$: rake myfile.txt 
myfile.txt created

# executing the rule a second time returns no output 
# because myfile.txt already exists and is up to date 
$: rake myfile.txt

# if the --always-make option is on, 
# the file is remade even if the prerequisites are met
$: rake myfile.txt --always-make
myfile.txt created

I am running Rake version 0.9.2.2, but I can't find any option in the --help and man pages.

1

1 Answers

2
votes

If I undersand you correctly, you can manually execute the task using Rake::Task.

task "foo" do
  puts "Doing something in foo"
end

task "bar" => "foo" do
  puts "Doing something in bar"
  Rake::Task["foo"].execute
end

When you run rake bar, you'll see:

Doing something in foo
Doing something in bar
Doing something in foo

If you use Rake::Task, it will be executed without checking any pre-requisites. Let me know if this doesn't help you.