Rebarをインストール
$ git clone https://github.com/basho/rebar.git
$ cd rebar && make
Rebarの提供しているコマンドをチェック
$ ./rebar -c
helpを見たいときに
$ rebar help clean
==> help clean
=== rebar_cleaner:clean ===
Delete list of files.
Valid rebar.config options:
{clean_files,["file","file2"]}
=== rebar_protobuffs_compiler:clean ===
Delete Protobuffs (*.proto) build results.
......
アプリケーションを作成
$ ./rebar create-app appid=mysample
これでsrc/ディレクトリが作成される
$ tree -L 2
.
├── rebar
└── src
├── mysample_app.erl
├── mysample.app.src
└── mysample_sup.erl
1 directory, 4 files
Rebar can fetch and build projects including source code from external sources (git, hg, etc.)
It is assumed that these dependencies are available in source form and adhere to the rebar conventions. Moreover, if a project's dependencies have their own dependencies, rebar fetches and builds these transitive dependencies recursively.
Dependencies are defined in the rebar.config
file by the adding the deps
tuple of the following form:
{deps, [Dependency1, Dependency2, ...]}.
Each dependency is defined by a triplet {App, VsnRegex, Source}
{deps, [
{em, ".*", {git, "https://github.com/sheyll/erlymock.git"}},
{nano_trace, ".*", {git, "https://github.com/sheyll/nano_trace.git", {branch, "feature/rebar-migration"}}},
{mochiweb, "2.3.2", {git, "https://github.com/mochi/mochiweb.git", {tag, "v2.3.2"}}},
% Or specify a revision to refer a particular commit, useful if the project has only the master branch
% {mochiweb, "2.3.2", {git, "https://github.com/mochi/mochiweb.git", "15bc558d8222b011e2588efbd86c01d68ad73e60"},
% An example of a "raw" dependency:
{rebar, ".*", {git, "git://github.com/rebar/rebar.git", {branch, "master"}}, [raw]}
]}.
Compile the application with:
$ rebar compile
A new directory ebin/ should now exist and contain the .beam files corresponding to the Erlang source files in the src/ directory. In addition, note the presence of the ebin/myapp.app file. Rebar has dynamically generated a proper OTP application specification using the src/myapp.app.src file as a template by adding information about all compiled Erlang modules of the application into the myapp.app file's modules section.
rebarで単体テストする方法
$ rebar compile eunit
Add the following code into the src/myapp_app.erl
(アプレケーションファイル) file, right after the -export(...) directive:
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
and add the following block of code at the very end of of the file:
-ifdef(TEST).
simple_test() ->
ok = application:start(myapp),
?assertNot(undefined == whereis(myapp_sup)).
-endif.
あるいは関数をテスト
-ifdef(TEST).
rpn_test() ->
?assertEqual(3, do_rpn("1 2 +")),
?assertEqual(2.0, do_rpn("4 2 /")),
?assertEqual(4, do_rpn("6 2 -")).
-endif.
$ rebar list-templates
==> wang (list-templates)
* simplesrv: priv/templates/simplesrv.template (escript) (variables: "srvid")
* simplenode: priv/templates/simplenode.template (escript) (variables: "nodeid")
* simplemod: priv/templates/simplemod.template (escript) (variables: "modid")
* simplelib: priv/templates/simplelib.template (escript) (variables: "libid")
* simplefsm: priv/templates/simplefsm.template (escript) (variables: "fsmid")
* simpleevent: priv/templates/simpleevent.template (escript) (variables: "eventid")
* simpleapp: priv/templates/simpleapp.template (escript) (variables: "appid")
* ctsuite: priv/templates/ctsuite.template (escript) (variables: "testmod")
* basicnif: priv/templates/basicnif.template (escript) (variables: "module")