1

很多地方都说“目录”关键字可以用作简写。显然,它可以被指示为依赖项,以便在不存在时创建它。

http://onestepback.org/articles/buildingwithrake/directorydependencies.html

想法是将目标目录指定为依赖项,而不是每次都尝试手动创建它,这可以通过使用mkdir_p. 使用的缺点mkdir_p是无论目录是否已经存在,它都会显示输出。另一种解决方案是使该命令静音——如果仅在创建目录时才显示输出,则效果会更好。

我试过使用“目录”关键字,如下所示:


file "destFile" => ["srcFile", directory "myOutputDir"] do
    FileUtils.cp "srcFile" "myOutputDir/destFile"
end

file "destFile" => ["srcFile"] + [directory "myOutputDir"] do
    FileUtils.cp "srcFile" "myOutputDir/destFile"
end

file "destFile" => ["srcFile"] do
    directory "myOutputDir"
    FileUtils.cp "srcFile" "myOutputDir/destFile"
end
4

1 回答 1

1

这个怎么样:

directory "myOutputDir"
file "myOutputDir/destFile" => ["srcFile", "myOutputDir"] do
  FileUtils.cp "srcFile" "myOutputDir/destFile"
end

我相信它应该被用作一个单独的任务,并像任何其他任务一样被指定为依赖项。file它与指定运行的任务基本相同mkdir,但动作是隐含的。语法在其他方面是相同的。

directory还将使所有层的子目录像这样: http: //onestepback.org/articles/buildingwithrake/directorydependencies.html

于 2011-12-23T04:21:37.757 回答