瀏覽代碼

Add support for reading relx config file

pull/2435/head
Hakan Nilsson 4 年之前
父節點
當前提交
424fdcb8fa
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 3F273821A0C8B845
共有 1 個文件被更改,包括 30 次插入2 次删除
  1. +30
    -2
      src/rebar_relx.erl

+ 30
- 2
src/rebar_relx.erl 查看文件

@ -21,8 +21,7 @@
-spec do(atom(), rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(Provider, State) ->
{Opts, _} = rebar_state:command_parsed_args(State),
%% TODO: read in ./relx.config if it exists or --config value
RelxConfig = rebar_state:get(State, relx, []),
RelxConfig = read_relx_config(State, Opts),
ProfileString = rebar_dir:profile_dir_name(State),
ExtraOverlays = [{profile_string, ProfileString}],
@ -72,6 +71,33 @@ do(Provider, State) ->
{ok, State}.
read_relx_config(State, Options) ->
ConfigFile = proplists:get_value(config, Options, []),
case ConfigFile of
"" ->
case {rebar_state:get(State, relx, []), file:consult("relx.config")} of
{[], {ok, Config}} ->
?DEBUG("Using relx.config", []),
Config;
{Config, {error, enoent}} ->
?DEBUG("Using relx config from rebar.config", []),
Config;
{_, {error, Reason}} ->
erlang:error(?PRV_ERROR({config_file, "relx.config", Reason}));
{RebarConfig, {ok, _RelxConfig}} ->
?WARN("Found conflicting relx configs, using rebar.config", []),
RebarConfig
end;
ConfigFile ->
case file:consult(ConfigFile) of
{ok, Config} ->
?DEBUG("Using relx config file: ~p", [ConfigFile]),
Config;
{error, Reason} ->
erlang:error(?PRV_ERROR({config_file, ConfigFile, Reason}))
end
end.
-spec format_error(any()) -> iolist().
format_error(unknown_release) ->
"Option --relname is missing";
@ -79,6 +105,8 @@ format_error(unknown_vsn) ->
"Option --relvsn is missing";
format_error(all_relup) ->
"Option --all can not be applied to `relup` command";
format_error({config_file, Filename, Error}) ->
io_lib:format("Failed to read config file ~s: ~p", [Filename, Error]);
format_error(Error) ->
io_lib:format("~p", [Error]).

Loading…
取消
儲存