Skip to content

Instantly share code, notes, and snippets.

@voluntas
Created December 9, 2012 07:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voluntas/4243802 to your computer and use it in GitHub Desktop.
Save voluntas/4243802 to your computer and use it in GitHub Desktop.
Erlang アプリケーション コトハジメ

Erlang アプリケーション コトハジメ

更新

2012-09-15

作者

@voluntas

バージョン

0.1.0

Gist で書いてみたシリーズ

宣伝

Erlang アプリケーション コトハジメ

https://gist.github.com/4243802

Erlang リリース コトハジメ

https://gist.github.com/4243786

Riak コトハジメ

https://gist.github.com/4243797

レビューのススメ?

https://gist.github.com/73efe2f36ac1513c02a8

継続開発のススメ Erlang/OTP 編

https://gist.github.com/9ee65f0dfa9b7dd78fde

TODO

  • rebar.config の説明

取り扱わない事

  • Erlang の言語についての説明
  • サンプルアプリケーションの開発

Erlang のインストール

ここは飛ばしてかまいません

できる限りソースコードからインストールしましょう。最新版を使うべきです。

R15B02 をコンパイルしてインストールします。

rebar の準備

Erlang アプリの開発で rebar を使わないという選択肢はありません。 まず Erlang でアプリを作りたい場合は rebar の機能を覚える事をススメます。

rebar を git clone してくる:

$ git clone git://github.com/basho/rebar.git
$ cd rebar
$ make

rebar ファイルが生成されます

アプリケーションフォルダの準備

アプリ名を決めます、ここでは仮に snowflake とします。

フォルダを作る:

$ mkdir snowflake

rebar ファイルをフォルダの中に入れましょう。この後は rebar コマンドを使っていきます。

アプリケーションのベースを rebar コマンドを使って生成する

rebar の create-app コマンドを使えば最低限必要なコードを生成してくれます

$ ./rebar create-app appid=snowflake
==> snowflake (create-app)
Writing src/snowflake.app.src
Writing src/snowflake_app.erl
Writing src/snowflake_sup.erl

これで最低限のアプリを作る準備が出来ました。

コンパイルしてみる

コンパイル:

$ ./rebar compile

rebar コマンドの解説

rebar コマンドには skip_deps という引数があります。これは依存しているライブラリを対象に含めるかどうか、です。開発中は skip_deps=true で依存ライブラリのテスト等は行いません。

簡単なモジュールを生成するコマンド:

$ ./rebar create tmplate=simplemod modid=snowflake_simple_mod skip_deps=true

gen_server を生成するコマンド:

$ ./rebar create template=simplesrv srvid=snowflake_gen_server skip_deps=true

eunit を実行するコマンド:

$ ./rebar eunit skip_deps=true

eunit で特定のモジュールだけをテストする:

$ ./rebar eunit skip_deps=true suites=モジュール名

最新の rebar では特定のテスト関数が実行できるようになりました:

$ ./rebar eunit suites=msgpack skip_deps=true tests=unpack
==> yet-another-msgpack-erlang (eunit)
NOTICE: Using experimental option 'tests'
    Running test function(s):
      msgpack_tests:unpack_test_/0
  All 3 tests passed.

まだ experimental な機能ではありますが今後よく使う機能になる気がします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment