【问题标题】:How to force the execution of a task in Rake, even if prereqs are met?即使满足先决条件,如何强制执行 Rake 中的任务?
【发布时间】:2012-06-11 10:52:41
【问题描述】:

是否有任何方法可以强制在 Rake 中执行任务,即使先决条件已经满足?

我正在寻找 GNU/make (http://www.gnu.org/software/make/manual/make.html#Options-Summary) 的 --always-make 选项的等效项

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 和手册页中找不到任何选项。

【问题讨论】:

    标签: ruby makefile rake pipeline


    【解决方案1】:

    如果我理解正确,您可以使用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 时使用的选项。
    • 要强制重新检查前提条件,请使用Rake::Task["foo"].invoke
    猜你喜欢
    • 2013-01-11
    • 2013-08-08
    • 1970-01-01
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 2021-11-28
    相关资源
    最近更新 更多