2011-12-22 112 views
1

有几个地方已经说过“目录”关键字可以用作简写。显然,它可以表示为一个依赖关系,所以如果它不存在的话它将被创建。rake - “目录”关键字如何工作?

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 

回答

1

如何:

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

我相信它应该作为一个单独的任务使用,并像任何其他任务一样指定为依赖项。这与指定运行mkdirfile任务基本相同,但操作是隐式的。语法是相同的。

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