如何使rake任务依赖于文件和另一个任务

时间:2015-04-01 00:43:59

标签: ruby rake

我有两个需要依赖于文件的rake任务,以及另一个rake任务。这是我尝试过的:

task :dependencies do
  # Install some pacman packages if necessary
end

# the :build task should be dependent on output.pdf and the dependencies task
task :build => [:dependencies, 'output.pdf']

# the file task should also be dependent on dependencies (in case it's run directly)
file 'output.pdf' => [:dependencies, 'output.md'] do

如何判断文件任务依赖于另一个rake任务以及其输入文件?另外,如何判断常规任务是否依赖于文件任务和常规任务?

1 个答案:

答案 0 :(得分:2)

你得到的东西对我有用。没有输出我无法进一步诊断。

Rake文件:

task :dependencies do
  puts "installing dependencies"
end

task build: ['dependencies', 'output.pdf']

file 'output.pdf' => ['dependencies', 'output.md'] do
  File.write 'output.pdf', ''
end

正在运行构建:

$ ls
Rakefile    output.md
$ rake -t build
** Invoke build (first_time)
** Invoke dependencies (first_time)
** Execute dependencies
installing dependencies
** Invoke output.pdf (first_time)
** Invoke dependencies 
** Invoke output.md (first_time, not_needed)
** Execute output.pdf
** Execute build
$ ls
Rakefile    output.md   output.pdf

运行output.pdf:

$ rm output.pdf
$ rake -t output.pdf
** Invoke output.pdf (first_time)
** Invoke dependencies (first_time)
** Execute dependencies
installing dependencies
** Invoke output.md (first_time, not_needed)
** Execute output.pdf
$ ls
Rakefile    output.md   output.pdf

PS:Rake不关心任务或依赖名称中的符号与字符串。