Use file:script if a .config.script file present

This commit is contained in:
Ulf Wiger 2012-02-10 15:07:24 +01:00 committed by Tuncer Ayaz
parent fc83f4b961
commit b3e9e76f57
2 changed files with 56 additions and 11 deletions

View file

@ -26,7 +26,7 @@
%% -------------------------------------------------------------------
-module(rebar_config).
-export([new/0, new/1, base_config/1,
-export([new/0, new/1, base_config/1, consult_file/1,
get/3, get_local/3, get_list/3,
get_all/2,
set/3,
@ -128,13 +128,50 @@ is_verbose() ->
get_jobs() ->
get_global(jobs, 3).
consult_file(File) ->
case filename:extension(File) of
".script" ->
consult_and_eval(remove_script_ext(File), File);
_ ->
Script = File ++ ".script",
case filelib:is_regular(Script) of
true ->
consult_and_eval(File, Script);
false ->
?DEBUG("Consult config file ~p~n", [File]),
file:consult(File)
end
end.
%% ===================================================================
%% Internal functions
%% ===================================================================
consult_file(File) ->
?DEBUG("Consult config file ~p~n", [File]),
file:consult(File).
consult_and_eval(File, Script) ->
?DEBUG("Evaluating config script ~p~n", [Script]),
ConfigData = try_consult(File),
file:script(File, bs([{'CONFIG', ConfigData}, {'SCRIPT', File}])).
remove_script_ext(F) ->
"tpircs." ++ Rev = lists:reverse(F),
lists:reverse(Rev).
try_consult(File) ->
case file:consult(File) of
{ok, Terms} ->
?DEBUG("Consult config file ~p~n", [File]),
Terms;
{error, enoent} -> [];
{error, Reason} ->
?ABORT("Failed to read config file ~s: ~p~n", [File, Reason])
end.
bs(Vars) ->
lists:foldl(fun({K,V}, Bs) ->
erl_eval:add_binding(K, V, Bs)
end, erl_eval:new_bindings(), Vars).
local_opts([], Acc) ->
lists:reverse(Acc);

View file

@ -48,12 +48,20 @@ is_rel_dir() ->
is_rel_dir(Dir) ->
Fname = filename:join([Dir, "reltool.config"]),
case filelib:is_regular(Fname) of
true ->
{true, Fname};
false ->
false
end.
Scriptname = Fname ++ ".script",
Res = case filelib:is_regular(Scriptname) of
true ->
{true, Scriptname};
false ->
case filelib:is_regular(Fname) of
true ->
{true, Fname};
false ->
false
end
end,
?DEBUG("is_rel_dir(~s) -> ~p~n", [Dir, Res]),
Res.
%% Get release name and version from a reltool.config
get_reltool_release_info([{sys, Config}| _]) ->
@ -116,7 +124,7 @@ get_previous_release_path() ->
%% Load terms from reltool.config
%%
load_config(ReltoolFile) ->
case file:consult(ReltoolFile) of
case rebar_config:consult_file(ReltoolFile) of
{ok, Terms} ->
expand_version(Terms, filename:dirname(ReltoolFile));
Other ->