summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_config.erl45
-rw-r--r--src/rebar_rel_utils.erl22
2 files changed, 56 insertions, 11 deletions
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 2da3191..31788b1 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -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);
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl
index 81ddbfb..e502743 100644
--- a/src/rebar_rel_utils.erl
+++ b/src/rebar_rel_utils.erl
@@ -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 ->