如果满足先决条件,如何在Rake中强制执行任务?

时间:2012-06-11 10:52:41

标签: ruby makefile rake pipeline

有没有办法强制在Rake中执行任务,即使已满足先决条件?

我正在寻找相当于GNU / make(http://www.gnu.org/software/make/manual/make.html#Options-Summary)的

示例Rakefile:

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

--always-make选项如何工作:

# 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

我正在运行Rake版本0.9.2.2,但我在--help和man页面中找不到任何选项。

1 个答案:

答案 0 :(得分:2)

如果我不正确,您可以使用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

当您运行rake bar时,您会看到:

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

如果您使用Rake::Task,它将在不检查任何先决条件的情况下执行。如果这对您没有帮助,请告诉我。