How does `rake` know where to look for Rakefiles?

半世苍凉 提交于 2019-12-21 05:06:10

问题


I'm trying to better understand how rake works. I've looked on the rake website to see how it works but there isn't a clear explanation for how rake searches for Rakefiles and the steps it goes through in resolving dependencies. Can someone explain how rake works?


回答1:


By default rake will look for one of these files under the directory you execute it from:

  • rakefile
  • Rakefile
  • rakefile.rb
  • Rakefile.rb

You can look at Rake's Application docs to see this list

Additionally, any ruby file including other rakefiles can be included with a standard Ruby require command:

require 'rake/loaders/external-rakefile'

alternatively, you can import them:

import 'rake/loaders/external-rakefile'

To make a set of Rake tasks available for use from any directory, create a .rake subdirectory within your home directory, and place the appropriate Rake files there. Any rake command with the -g option will use these global Rake files (read more here):

rake -g -T

Additionally, if -g option is set, Rake will first try to load the files form RAKE_SYSTEM environment variable, if that is not set, it will default to a home user directory/.rake/*.rake. These files will be loaded/imported in addition to one of the default files listed above.

Otherwise it will load the first default file (from the above list), and additionally import all the rake files from the rakelib directory (under location you run rake from), OR this directory can be specified using:

--rakelibdir=RAKELIBDIR or -R RAKELIBDIR: Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')  


来源:https://stackoverflow.com/questions/7694967/how-does-rake-know-where-to-look-for-rakefiles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!