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