如何在Rake中强制执行任务,即使前置任务已完成?

3

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

我正在寻找 GNU/make 中 --always-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个回答

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,它将在不检查任何先决条件的情况下执行。如果这样还不能帮助您,请告诉我。

谢谢,这很有效,虽然我正在寻找一种在命令行调用rake时使用的选项。 - dalloliogm
要强制重新检查先决条件,使用 Rake::Task["foo"].invoke - Markus Strauss

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接