rake - how does the “directory” keyword work?
Pregunta
It's been stated in several places that "directory" keyword can be used as a shorthand. Apparently, it can be indicated as a dependency, so that it will be created if not already present.
http://onestepback.org/articles/buildingwithrake/directorydependencies.html
The idea is to specify destination directory as a dependency, not to attempt to create it manually each time, which can be achieved by using mkdir_p
. Downside of using mkdir_p
is that it displays output regardless of whether the directory was already present. An alternative solution is to silence this command -- and even better if the output is displayed only when the directory is created.
I've tried using "directory" keyword as follows:
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
Solución
How about this:
directory "myOutputDir"
file "myOutputDir/destFile" => ["srcFile", "myOutputDir"] do
FileUtils.cp "srcFile" "myOutputDir/destFile"
end
I believe it's supposed to be used as a separate task and specified as a dependency like any other task. It's basically the same as specifying a file
task that runs mkdir
, but the action is implicit. The syntax is otherwise the same.
directory
will also make all layers of subdirectories like so: http://onestepback.org/articles/buildingwithrake/directorydependencies.html