Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use file:script if a .config.script file present #210

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/rebar_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 15 additions & 7 deletions src/rebar_rel_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}| _]) ->
Expand Down Expand Up @@ -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 ->
Expand Down