浏览代码

Refactor overlay_vars to enable overrides from command-line

pull/3/head
Dave Smith 14 年前
父节点
当前提交
b7111dce85
共有 1 个文件被更改,包括 25 次插入28 次删除
  1. +25
    -28
      src/rebar_reltool.erl

+ 25
- 28
src/rebar_reltool.erl 查看文件

@ -139,24 +139,33 @@ target_dir(ReltoolConfig) ->
end. end.
%% %%
%% Look for overlay_vars file reference. The user can override this from the
%% command line (i.e. globals), so we check there first and then fall back to
%% what is present in the reltool.config file
%% Look for overlay_vars file reference. If the user provides an overlay_vars on
%% the command line (i.e. a global), the terms from that file OVERRIDE the one
%% listed in reltool.config. To re-iterate, this means you can specify a
%% variable in the file from reltool.config and then override that value by
%% providing an additional file on the command-line.
%% %%
overlay_vars(ReltoolConfig) ->
case rebar_config:get_global(overlay_vars, undefined) of
undefined ->
case lists:keyfind(overlay_vars, 1, ReltoolConfig) of
{overlay_vars, File} ->
File;
false ->
undefined
end;
File ->
File
overlay_vars(Vars0, ReltoolConfig) ->
BaseVars = load_vars_file(proplists:get_value(overlay_vars, ReltoolConfig)),
OverrideVars = load_vars_file(rebar_config:get_global(overlay_vars, undefined)),
M = fun(_Key, _Base, Override) -> Override end,
dict:merge(M, dict:merge(M, Vars0, BaseVars), OverrideVars).
%%
%% If a filename is provided, construct a dict of terms
%%
load_vars_file(undefined) ->
dict:new();
load_vars_file(File) ->
case file:consult(File) of
{ok, Terms} ->
dict:from_list(Terms);
{error, Reason} ->
?ABORT("Unable to load overlay_vars from ~s: ~p\n", [File, Reason])
end. end.
validate_rel_apps(ReltoolServer, {sys, ReltoolConfig}) -> validate_rel_apps(ReltoolServer, {sys, ReltoolConfig}) ->
case lists:keyfind(rel, 1, ReltoolConfig) of case lists:keyfind(rel, 1, ReltoolConfig) of
false -> false ->
@ -211,22 +220,10 @@ run_reltool(Server, _Config, ReltoolConfig) ->
%% Initialize overlay vars with some basics %% Initialize overlay vars with some basics
%% (that can get overwritten) %% (that can get overwritten)
OverlayVars0 = [{erts_vsn, "erts-" ++ erlang:system_info(version)}],
OverlayVars0 = dict:from_list([{erts_vsn, "erts-" ++ erlang:system_info(version)}]),
%% Load up any variables specified by overlay_vars %% Load up any variables specified by overlay_vars
OverlayVars = case overlay_vars(ReltoolConfig) of
undefined ->
dict:from_list(OverlayVars0);
File ->
case file:consult(File) of
{ok, Terms} ->
dict:from_list(OverlayVars0 ++ Terms);
{error, Reason2} ->
?ABORT("Unable to load overlay_vars "
"from ~s: ~p\n",
[File, Reason2])
end
end,
OverlayVars = overlay_vars(OverlayVars0, ReltoolConfig),
%% Finally, overlay the files specified by the overlay section %% Finally, overlay the files specified by the overlay section
case lists:keyfind(overlay, 1, ReltoolConfig) of case lists:keyfind(overlay, 1, ReltoolConfig) of

正在加载...
取消
保存