当前位置: 传客网 > 【转移】How does Rake search for rakefiles?

【转移】How does Rake search for rakefiles?

2016-12-28 作者:mixmaster

Most of my understandings of rake come from the analogue to make. I thought, like make, rake requires a rakefile located in the current path where I issue the command if no rakefile explicitly specified in the arguments. However, I accidentally typed vm under the root path of the source code without a rakefile available yesterday when I was playing with Rubinius. It compiled!

Later when I tried to find the details on how the virtual machine was built I can't find anything in the root rakefile except for a line of comment saying "See vm.rake for more information". It was easy to locate the file but how was it loaded?

From the behaviors I could guess that rake would recursively search the up a level of directory for a rakefile if none exists in the current one, and rakefiles located in the rakelib directory would be somehow automatically imported, but I wanted some concrete documentation to prove my guess. I was astonished after some googling that it seemed that everyone knew the answers but no one ever wrote about it.

Therefore, the last weapon I could use was RTFSC. Fortunately the source code of Rake is pretty straightforward. The searching and importing logic is basically

  1. chdir to .. if there is no rakefile existing in the current dir;
  2. when finding a rakefile record its directory to location and load it;
  3. import all of .rake files located under location/rakelib if exist.

Wish this post could provide a little help to any rookies like me that are also seeking for the answers to this questions!

(写于2009年10月8日)



相关推荐

返回
顶部