スポンサーリンク

2016年2月8日

rebarインストールのメモ

Goal

rebarをインストールする。

Dev-Environment

OS: Windows8.1
Erlang: Eshell V7.2.1, OTP-Version 18.1
Elixir: v1.2.0

Wait a minute

以前インストールしていたはずなんですが、環境を整理しているうちに消していたようです。
なので、再インストールしようと思ったのですが、二つほど問題が生じたためメモを残す。

Index

rebar install memo
|> What issue?
|> Resolve issue!!

What issue?

どのような問題が起こったのか?
まずは以下のインストールを実行しようとして起こった内容をご覧ください。

Example:

> git clone https://github.com/basho/rebar.git
Cloning into 'rebar'...
remote: Counting objects: 6093, done.
remote: Total 6093 (delta 0), reused 0 (delta 0), pack-reused 6093
Receiving objects: 100% (6093/6093), 2.23 MiB | 319.00 KiB/s, done.
Resolving deltas: 100% (3512/3512), done.
Checking connectivity... done.

> cd rebar

> bootstrap.bat
bootstrap:91: Warning: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
C:\...\rebar\ebin\rebar.beam が見つかりませんでした。
Recompile: src/getopt
Recompile: src/mustache
Recompile: src/rebar
Recompile: src/rebar_abnfc_compiler
Recompile: src/rebar_app_utils
Recompile: src/rebar_appups
Recompile: src/rebar_asn1_compiler
Recompile: src/rebar_base_compiler
Recompile: src/rebar_cleaner
Recompile: src/rebar_config
src/rebar_config.erl:48: type dict() undefined
Failed to compile rebar files!
なんだよ…見つからないって…
なんだよ…undefinedって…
俺がWindowsユーザだからってこんなのあんまりだ!(実際は違う)
閑話休題…
勘の良い人はこの時点でお気づきかと思います。
そう、OTPで非推奨または廃止された機能を使っていますね。
(ガイド見ろってメッセージが出てる時点でお察し…)

Resolve issue!!

どうやって解決したか?…助けてGoogle先生~!!
冗談はさて置き、まず一つ目の問題に対処する。
せっかくガイド見ろって言われてるんだから、Erlangのガイドを見に行く。
参考: 2 Time and Time Correction in Erlang
上記リンク先の”2.7 New Time API - Retrieve Erlang System Time”に書いてある。
必要なところだけ取得すると…timestampの方を使ってね!って話だ。
対象のファイルを以下のように修正した。
(行番号90~93の部分だけ抜粋)

File: bootstrap

  • 修正前
build_time() ->
    {{Y, M, D}, {H, Min, S}} = calendar:now_to_universal_time(now()),
    lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
                                [Y, M, D, H, Min, S])).
  • 修正後
build_time() ->
    {{Y, M, D}, {H, Min, S}} = calendar:now_to_universal_time(erlang:timestamp()),
    lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
                                [Y, M, D, H, Min, S])).
問題が解消されたか確認してみる。
> bootstrap.bat
Recompile: src/rebar
Recompile: src/rebar_config
src/rebar_config.erl:48: type dict() undefined
Failed to compile rebar files!
一つ目のエラーは解消。
次は二つ目の問題について。dictなんて定義されてないよって話。
状況は違えどどうせ、調べれば似たような問題で誰か困ってた人が出てくるでしょう…
ですよね~(先人に礼!)
R18でdict自体が廃止になってる。
んで、それでも使うんなら、dict:dict()にしろって話ですね。
方法も分かったところで、対象のファイルを修正してしまいましょう。
(行番号42~48を抜粋)

File: src/rebar_config.erl

  • 修正前
-record(config, { dir :: file:filename(),
                  opts = [] :: list(),
                  globals = new_globals() :: dict(),
                  envs = new_env() :: dict(),
                  %% cross-directory/-command config
                  skip_dirs = new_skip_dirs() :: dict(),
                  xconf = new_xconf() :: dict() }).
  • 修正後(全部で四つ)
-record(config, { dir :: file:filename(),
                  opts = [] :: list(),
                  globals = new_globals() :: dict:dict(),
                  envs = new_env() :: dict:dict(),
                  %% cross-directory/-command config
                  skip_dirs = new_skip_dirs() :: dict:dict(),
                  xconf = new_xconf() :: dict:dict() }).
さて、これでインストールができるはず…
> bootstrap.bat
...
Congratulations! You now have a self-contained script called "rebar" in
your current working directory. Place this script anywhere in your path
and you can use rebar to build OTP-compliant apps.

> rebar --version
rebar 2.1.0-pre 18 20160208_065533 git 2.1.0-pre-171-gcd55176-dirty
問題が解消して、バージョンの確認までできました。

Extra

ちょっと気になってiexからerlangのnowとtimestampを実行してみた。
iex> :erlang.now
{1454, 914299, 284000}
iex> :erlang.timestamp
{1454, 914305, 425000}
nowも動作すんのね。(非推奨ですが…)

Speaking to oneself

rebarがちょっと必要になったので入れようと思ったら、時間を取られてしまった。
本題はこれじゃないんですけどね…

Bibliography

人気の投稿