Skip to content
Browse files

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

  • Loading branch information...
1 parent fc83f4b commit b3e9e76f57c9b9efbfe26e3a7330b27ff13c8c20 @uwiger uwiger committed with tuncer Feb 10, 2012
Showing with 56 additions and 11 deletions.
  1. +41 −4 src/rebar_config.erl
  2. +15 −7 src/rebar_rel_utils.erl
View
45 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);
View
22 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 ->

0 comments on commit b3e9e76

Please sign in to comment.
Something went wrong with that request. Please try again.