Stuff Goes Bad:Erlang In Anger

OTP Applications

For OTP applications, the proper structure is pretty much the same as what was explained in 1.2:

 对于OTP applicaitons,合适的结构基本同1.2中描述的那样:

1 doc/
2 deps/
3 ebin/
4 src/
5 test/
8 rebar.config

What’s new in this one is the deps/ directory, which is fairly useful to have, but that will be generated automatically by rebar 2 if necessary.
That’s because there is no canonical package management in Erlang. People instead adopted rebar, which fetches dependencies locally, on a per-project basis.
This is fine and removes a truckload of conflicts, but means that each project you have may have to download its own set of dependencies.
This is accomplished with rebar by adding a few config lines to rebar.config:

 新加的文件夹:deps/ 非常有用的一个文件夹。这个文件夹如果有必要也可以直接通过rebar自动生成2
这是因为在Erlang没有标准的包管理器(canonical package management)。现在的做法是用rebar来为每一个项目在本地获取依赖项。
1 {deps,
2 [{application_name, "1.0.*",
3 {git, "git://", {branch,"master"}}},
4 {application_name, "2.0.1",
5 {git, "git://", {tag,"2.0.1"}}},
6 {application_name, "",
7 {git, "", "7cd0aef4cd65"}},
8 {application_name, "my regex",
9 {hg, "" {branch, "stable"}}}]}.

Feel free to install rebar globally on your system, or keep a local copy if you require a specific version to build your system. Applications are fetched directly from a git (or hg, or svn) source, recursively. They can then be compiled, and specific compile options can be added with the {erl_opts, List}.option in the config file 3 .
Within these directories, you can do your regular development of an OTP application.
To compile them, call rebar get-deps compile, which will download all dependencies,and then build them and your app at once.
When making your application public to the world, distribute it without the dependencies. It’s quite possible that other developers’ applications depend on the same applications yours do, and it’s no use shipping them all multiple times.
The build system in place (in this case, rebar) should be able to figure out duplicated entries and fetch everything necessary only once.

 rebar会递归地从git(或hg,或svn)中直接拿到application的源代码。他们可以被编译,也可使用特定的选项{erl_opts,List}编译. 此选项也在config文件中定义3
你可以在这些文件夹中,开发自己的OTP application功能。
 为了编译他们,你可以使用rebar get-deps把依赖项也下载下来编译,并马上构建依赖项和你自己的app。

[2] A lot of people package rebar directly in their application. This was initially done to help people who had never used rebar before use libraries and projects in a boostrapped manner.
[3] More details by calling rebar help compile.

[注3]:你可以输入rebar help来查看更多的帮助信息。