瀏覽代碼

Merge pull request #2435 from kivra/add-support-for-relx-config-file

Add support for relx config file
pull/2438/head
Fred Hebert 4 年之前
committed by GitHub
父節點
當前提交
ef6476dd1d
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 3 個檔案被更改,包括 63 行新增2 行删除
  1. +33
    -2
      src/rebar_relx.erl
  2. +29
    -0
      test/rebar_release_SUITE.erl
  3. +1
    -0
      test/rebar_test_utils.erl

+ 33
- 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,36 @@ do(Provider, State) ->
{ok, State}.
read_relx_config(State, Options) ->
ConfigFile = proplists:get_value(config, Options, []),
case ConfigFile of
"" ->
ConfigPath = filename:join([rebar_dir:root_dir(State), "relx.config"]),
case {rebar_state:get(State, relx, []), file:consult(ConfigPath)} of
{[], {ok, Config}} ->
?DEBUG("Configuring releases with relx.config", []),
Config;
{Config, {error, enoent}} ->
?DEBUG("Configuring releases the {relx, ...} entry"
" from rebar.config", []),
Config;
{_, {error, Reason}} ->
erlang:error(?PRV_ERROR({config_file, "relx.config", Reason}));
{RebarConfig, {ok, _RelxConfig}} ->
?WARN("Found conflicting relx configs, configuring releases"
" with rebar.config", []),
RebarConfig
end;
ConfigFile ->
case file:consult(ConfigFile) of
{ok, Config} ->
?DEBUG("Configuring releases with: ~ts", [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 +108,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 ~ts: ~p", [Filename, Error]);
format_error(Error) ->
io_lib:format("~p", [Error]).

+ 29
- 0
test/rebar_release_SUITE.erl 查看文件

@ -4,6 +4,7 @@
-include_lib("eunit/include/eunit.hrl").
all() -> [release,
config_file,
dev_mode_release,
profile_dev_mode_override_release,
tar,
@ -45,6 +46,34 @@ release(Config) ->
{ok, [{release, list_to_atom(Name), Vsn, false}]}
).
config_file(Config) ->
AppDir = ?config(apps, Config),
Name = list_to_atom(?config(name, Config)),
%% Relase build fails if no relx config exists
?assertError({error, {relx, no_releases_in_system}},
rebar_test_utils:run_and_check(Config, [], ["release"], result)),
%% Write relx.config
RelxConfig = fun(Vsn) -> [{release, {Name, Vsn}, [Name]}, {lib_dirs, [AppDir]}] end,
rebar_test_utils:create_config(AppDir, "relx.config", RelxConfig("1.0.0")),
%% Release is built with relx.config (default)
rebar_test_utils:run_and_check(Config, [], ["release"],
{ok, [{release, Name, "1.0.0", false}]}),
%% Release is built with custom.config (--config)
rebar_test_utils:create_config(AppDir, "custom.config", RelxConfig("2.0.0")),
rebar_test_utils:run_and_check(Config, [], ["release", "--config", "custom.config"],
{ok, [{release, Name, "2.0.0", false}]}),
%% Fail due to non-existing file
?assertError({error, {rebar_relx, {config_file, "no_exist.config", enoent}}},
rebar_test_utils:run_and_check(Config, [],
["release", "--config", "no_exist.config"], result)),
%% Fail due to non-existing file, even with relx config in rebar.config
?assertError({error, {rebar_relx, {config_file, "no_exist.config", enoent}}},
rebar_test_utils:run_and_check(Config, [{relx, RelxConfig("3.0.0")}],
["release", "--config", "no_exist.config"], result)),
%% rebar.config overrides relx.config if both exist
rebar_test_utils:run_and_check(Config, [{relx, RelxConfig("4.0.0")}], ["release"],
{ok, [{release, Name, "4.0.0", false}]}).
dev_mode_release(Config) ->
AppDir = ?config(apps, Config),
Name = ?config(name, Config),

+ 1
- 0
test/rebar_test_utils.erl 查看文件

@ -431,6 +431,7 @@ check_results(AppDir, Expected, ProfileRun) ->
end,
DevMode = lists:all(IsSymLinkFun, RelLibs),
?assertEqual(ExpectedDevMode, DevMode),
?assert(ec_file:exists(filename:join([ReleaseDir, Name, "releases", Vsn]))),
%% throws not_found if it doesn't exist
ok

Loading…
取消
儲存