`rake` 如何知道去哪里寻找 Rakefiles? [英] How does `rake` know where to look for Rakefiles?

查看:21
本文介绍了`rake` 如何知道去哪里寻找 Rakefiles?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更好地理解 rake 的工作原理.我在 rake 网站上查看了它是如何工作的,但没有明确解释 rake 如何搜索 Rakefiles 以及它在解决依赖项时所经历的步骤.有人能解释一下 rake 是如何工作的吗?

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?

推荐答案

默认情况下,rake 将在您执行它的目录下查找以下文件之一:

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

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

您可以查看 Rake 的应用程序文档以查看此列表

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

此外,任何 ruby​​ 文件包括其他 rakefiles 都可以包含在标准的 Ruby require 命令中:

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

require 'rake/loaders/external-rakefile'

或者,您可以导入它们:

import 'rake/loaders/external-rakefile'

要使一组 Rake 任务可从任何目录使用,请在您的主目录中创建一个 .rake 子目录,并将适当的 Rake 文件放在那里.任何带有 -g 选项的 rake 命令都将使用这些全局 Rake 文件(阅读更多这里):

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

另外,如果设置了 -g 选项,Rake 将首先尝试从 RAKE_SYSTEM 环境变量中加载文件,如果没有设置,它将默认为home 用户目录/.rake/*.rake.除了上面列出的默认文件之一,这些文件将被加载/导入.

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.

否则它将加载第一个默认文件(从上面的列表中),并且另外rakelib 目录(在你运行 rake from),或者可以使用以下命令指定此目录:

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

这篇关于`rake` 如何知道去哪里寻找 Rakefiles?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆