【转移】How does Rake search for rakefiles?

rake ruby it

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日)


相关推荐

你的评论

就没有什么想说的吗?

最新博客

关于我们 加入传客 媒体报道 帮助中心 传客活动 免责声明 联系我们 移动版 移动应用

©2017传客网    琼ICP备15003173号-2    

本站部分文章来源于互联网,版权归属于原作者。
本站所有转载文章言论不代表本站观点,如是侵犯了原作者的权利请发邮件联系站长(weishubao@126.com),我们收到后立即删除。
站内所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!

X