summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Merritt <ericbmerritt@gmail.com>2012-09-07 15:47:23 -0500
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-09-07 22:53:50 +0200
commiteaad535e316c7719babe42faa011a08e1e8675cb (patch)
treecb88aea9129f4ef09746e25d2fc0e03c2ff73268
parente0bc55db33e14da9492b26ffc6001871390a9ab9 (diff)
Allow script to be evaluated when app file is loaded
This allows an <app-name>.app.src.script to be defined and evaluated when <app-name>.app.src or <app-name>.app are loaded. This allows the user to add project specific manipulations to app metadata.
-rw-r--r--src/rebar_app_utils.erl24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index c0df97f..8158eb6 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -138,7 +138,7 @@ load_app_file(Config, Filename) ->
AppFile = {app_file, Filename},
case rebar_config:get_xconf(Config, {appfile, AppFile}, undefined) of
undefined ->
- case file:consult(Filename) of
+ case consult_app_file(Filename) of
{ok, [{application, AppName, AppData}]} ->
Config1 = rebar_config:set_xconf(Config,
{appfile, AppFile},
@@ -153,6 +153,28 @@ load_app_file(Config, Filename) ->
{ok, Config, AppName, AppData}
end.
+%% In the case of *.app.src we want to give the user the ability to
+%% dynamically script the application resource file (think dynamic version
+%% string, etc.), in a way similar to what can be done with the rebar
+%% config. However, in the case of *.app, rebar should not manipulate
+%% that file. This enforces that dichotomy between app and app.src.
+consult_app_file(Filename) ->
+ case lists:suffix(".app.src", Filename) of
+ false ->
+ file:consult(Filename);
+ true ->
+ %% TODO: EXPERIMENTAL For now let's warn the user if a
+ %% script is going to be run.
+ case filelib:is_regular([Filename, ".script"]) of
+ true ->
+ ?CONSOLE("NOTICE: Using experimental *.app.src.script "
+ "functionality on ~s ~n", [Filename]);
+ _ ->
+ ok
+ end,
+ rebar_config:consult_file(Filename)
+ end.
+
get_value(Key, AppInfo, AppFile) ->
case proplists:get_value(Key, AppInfo) of
undefined ->