rebar3实例

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
%% directory for artifacts produced by rebar3
{base_dir, "_build"}.
%% directory in '<base_dir>/<profile>/' where deps go
{deps_dir, "lib"}.
%% where rebar3 operates from; defaults to the current working directory
{root_dir, "."}.
%% where checkout dependencies are to be located
{checkouts_dir, "_checkouts"}.
%% directory in '<base_dir>/<profile>/' where plugins go
{plugins_dir, "plugins"}.
%% directories where OTP applications for the project can be located
{project_app_dirs, ["apps/*", "lib/*", "."]}.
%% Directories where source files for an OTP application can be found
{src_dirs, ["src"]}.
%% Paths to miscellaneous Erlang files to compile for an app
%% without including them in its modules list
{extra_src_dirs, []}. 
%% Paths the compiler outputs when reporting warnings or errors
%% relative (default), build (all paths are in _build, default prior
%% to 3.2.0, and absolute are valid options
{compiler_source_format, relative}.



% 
{overrides, [
    %% For all apps:
    {del, [{erl_opts, [warnings_as_errors]}]},
    %% Or for just one app:
    {del, one_app, [{erl_opts, [warnings_as_errors]}]}
]}.





{erl_opts, [
  warn_unused_vars
  ,warn_export_all
  ,warn_shadow_vars
  ,warn_unused_import
  ,warn_unused_function
  ,warn_bif_clash
  ,warn_unused_record
  ,warn_deprecated_function
  ,warn_obsolete_guard
  ,strict_validation
  ,warn_export_vars
  ,warn_exported_vars
  ,warn_missing_spec
  ,warn_untyped_record
  ,debug_info       % 调试
  ,no_debug_info    % 
  ,nowarn_unused_function
  ,{i, "./include"}  % 指定include文件目录
  ,{d, 'NOTEST', true}   %
  ,{d, TEST, true}       % -ifdef(TEST).
  ,{d, EUNIT, true}      % -ifdef(EUNIT).
  ,{parse_transform, lager_transform}
]}.


% 增加这句,依赖有冲突时,会中止
{deps_error_on_conflict, true}.
% 设定rebar镜像
{rebar_packages_cdn, "https://hexpm.upyun.com"}.

%% ================================================
%% 插件
%% ================================================
{plugins, [
  { pc, {git, "https://github.com/blt/port_compiler.git", {tag, "1.6.0"}}}
  % .dtl格式文件插件
  {rebar3_erlydtl_plugin, ".*",
    {git, "https://github.com/tsloughter/rebar3_erlydtl_plugin.git", {branch, "master"}}}
]}.

{erlydtl_opts,[ % erlydtl插件相关配置
  {doc_root, "templates"}
  %,{compiler_options, [report, return, debug_info]}
]}.


%% ================================================
%% deps
%% ================================================
{deps, [
  %% Packages
  rebar,
  {rebar,"1.0.0"},
  {rebar, {pkg, rebar_fork}}, % rebar app under a different pkg name
  {rebar, "1.0.0", {pkg, rebar_fork}},
  %% Source Dependencies
  {rebar, {git, "git://github.com/erlang/rebar3.git"}},
  {rebar, {git, "http://github.com/erlang/rebar3.git"}},
  {rebar, {git, "https://github.com/erlang/rebar3.git"}},
  {rebar, {git, "git@github.com:erlang/rebar3.git"}},
  {rebar, {hg, "https://othersite.com/erlang/rebar3"}},
  {rebar, {git, "git://github.com/erlang/rebar3.git", {ref, "aef728"}}},
  {rebar, {git, "git://github.com/erlang/rebar3.git", {branch, "master"}}},
  {rebar, {git, "git://github.com/erlang/rebar3.git", {tag, "3.0.0"}}},
  %% Legacy support -- added parts such as [raw] are ignored
  {rebar, "3.*", {git,"git://github.com/erlang/rebar3.git"}},
  {rebar, {git, "git://github.com/erlang/rebar3.git"}, [raw]},
  {rebar, "3.*", {git, "git://github.com/erlang/rebar3.git"}, [raw]}
]}.




%% ================================================
%% hooks
%% ================================================
{provider_hooks, [  %% hook钩子
  {pre, [{compile, {erlydtl, compile}}]}  % 执行rebar3 compile时先执行rebar3 plugin compile
]}.

{pre_hooks, [{"(linux|darwin|solaris)", compile, "make -C \"$REBAR_DEPS_DIR/merl\" all -W test"},
             {"(freebsd|netbsd|openbsd)", compile, "gmake -C \"$REBAR_DEPS_DIR/merl\" all"},
             {"win32", compile, "make -C \"%REBAR_DEPS_DIR%/merl\" all -W test"},
             {eunit, "erlc -I include/erlydtl_preparser.hrl -o test test/erlydtl_extension_testparser.yrl"},
             {"(linux|darwin|solaris)", eunit, "make -C \"$REBAR_DEPS_DIR/merl\" test"},
             {"(freebsd|netbsd|openbsd)", eunit, "gmake -C \"$REBAR_DEPS_DIR/merl\" test"},
             {"win32", eunit, "make -C \"%REBAR_DEPS_DIR%/merl\" test"}
            ]}.


{post_hooks, [
%  {compile, "./relx"}   % 每次调用 rebar compile 时,都会生成 release
]}.



%% ================================================
%% relx
%% ================================================
{relx, [
  {release,
    { demo_erlang, "0.1.2" },
    [
      cowboy,
      lager,
      demo_erlang,
      reloader,
      sasl
    ]
  },
  {release,
    { demo_lager, "0.0.3" },
    [
      observer_cli,
      lager,
      demo_lager,
      reloader,
      sasl
    ]
  },

  {sys_config, "./config/sys.config"},
  {vm_args, "./config/vm.args"},

  {dev_mode, true},
  {include_erts, false},

  {extended_start_script, true}
]}.


%% ================================================
%% profiles
%% ================================================
{profiles, [
  {prod, [{relx, [
    {dev_mode, false},
    {include_erts, true}
  ]}]},
  {cowboy, [{relx, [
    {release,
      { demo_erlang, "0.1.0" },
      [
        cowboy,
        demo_erlang,
        sasl
      ]
    },
    {dev_mode, false}
  ]}]},
  {lager, [{relx, [
    {dev_mode, false}
  ]}]}
  ]
}.