summaryrefslogtreecommitdiff
path: root/src/rebar_app_discover.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_app_discover.erl')
-rw-r--r--src/rebar_app_discover.erl39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 16dcf24..73401bc 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -37,12 +37,13 @@ merge_deps(AppInfo, State) ->
Default = rebar_state:default(State),
CurrentProfiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo),
- C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
+ C = project_app_config(AppInfo, State),
%% We reset the opts here to default so no profiles are applied multiple times
AppState = rebar_state:apply_overrides(
rebar_state:apply_profiles(
- rebar_state:new(rebar_state:opts(State, Default), C, rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
+ rebar_state:new(reset_hooks(rebar_state:opts(State, Default)), C,
+ rebar_app_info:dir(AppInfo)), CurrentProfiles), Name),
AppInfo1 = rebar_app_info:state(AppInfo, AppState),
State1 = lists:foldl(fun(Profile, StateAcc) ->
@@ -56,6 +57,27 @@ merge_deps(AppInfo, State) ->
{AppInfo1, State1}.
+project_app_config(AppInfo, State) ->
+ C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
+ Dir = rebar_app_info:dir(AppInfo),
+ maybe_reset_hooks(C, Dir, State).
+
+%% Here we check if the app is at the root of the project.
+%% If it is, then drop the hooks from the config so they aren't run twice
+maybe_reset_hooks(C, Dir, State) ->
+ case filename:dirname(rebar_dir:root_dir(State)) of
+ Dir ->
+ C1 = proplists:delete(provider_hooks, C),
+ proplists:delete(hooks, C1);
+ _ ->
+ C
+ end.
+
+reset_hooks(State) ->
+ lists:foldl(fun(Key, StateAcc) ->
+ rebar_state:set(StateAcc, Key, [])
+ end, State, [post_hooks, pre_hooks, provider_hooks]).
+
-spec all_app_dirs(list(file:name())) -> list(file:name()).
all_app_dirs(LibDirs) ->
lists:flatmap(fun(LibDir) ->
@@ -137,7 +159,12 @@ find_app(AppDir, Validate) ->
case Validate of
V when V =:= invalid ; V =:= all ->
AppInfo = create_app_info(AppDir, File),
- {true, rebar_app_info:app_file_src(AppInfo, File)};
+ case AppInfo of
+ {error, Reason} ->
+ throw({error, {invalid_app_file, File, Reason}});
+ _ ->
+ {true, rebar_app_info:app_file_src(AppInfo, File)}
+ end;
valid ->
false
end;
@@ -153,7 +180,7 @@ find_app(AppDir, Validate) ->
app_dir(AppFile) ->
filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))).
--spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | error.
+-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | {error, term()}.
create_app_info(AppDir, AppFile) ->
case file:consult(AppFile) of
{ok, [{application, AppName, AppDetails}]} ->
@@ -171,8 +198,8 @@ create_app_info(AppDir, AppFile) ->
false
end,
rebar_app_info:dir(rebar_app_info:valid(AppInfo1, Valid), AppDir);
- _ ->
- error
+ {error, Reason} ->
+ {error, Reason}
end.
dedup([]) -> [];