summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-11-07 20:58:29 -0600
committerTristan Sloughter <t@crashfast.com>2014-11-07 20:58:29 -0600
commite9adf01d0137c02cc8cd22e0e5ffe18bcda79752 (patch)
tree503d36058894eaf41992e0348c0adcbdd021a4cd /src
parent8bd6a7088f2faf7ee14db50fd1880120edbe1c6a (diff)
warn on bad plugin
Diffstat (limited to 'src')
-rw-r--r--src/rebar_plugins.erl71
-rw-r--r--src/rebar_prv_install_deps.erl8
2 files changed, 56 insertions, 23 deletions
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl
index b180ede..3bf9f0b 100644
--- a/src/rebar_plugins.erl
+++ b/src/rebar_plugins.erl
@@ -13,26 +13,53 @@
install(State) ->
State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR),
-
+ expand_plugins(?DEFAULT_PLUGINS_DIR),
Plugins = rebar_state:get(State1, plugins, []),
- {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins),
-
- Apps = rebar_state:get(State2, all_deps, []),
- ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps),
- lists:foreach(fun(AppInfo) ->
- C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
- S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)),
- rebar_prv_compile:build(S, AppInfo)
- end, ToBuild),
-
- PluginProviders = plugin_providers(Plugins),
- {ok, PluginProviders, rebar_state:set(State2, deps_dir, ?DEFAULT_DEPS_DIR)}.
-
-plugin_providers(Plugins) ->
- lists:map(fun({Plugin, _, _}) when is_atom(Plugin) ->
- Plugin;
- ({Plugin, _}) when is_atom(Plugin) ->
- Plugin;
- (Plugin) when is_atom(Plugin) ->
- Plugin
- end, Plugins).
+ PluginProviders = rebar_utils:filtermap(fun(Plugin) ->
+ handle_plugin(Plugin, State1)
+ end, Plugins),
+
+ {ok, PluginProviders, rebar_state:set(State1, deps_dir, ?DEFAULT_DEPS_DIR)}.
+
+handle_plugin(Plugin, State) ->
+ try
+ {ok, State1} = rebar_prv_install_deps:handle_deps(State, [Plugin]),
+ Apps = rebar_state:get(State1, all_deps, []),
+ ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps),
+ lists:foreach(fun(AppInfo) ->
+ C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
+ S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)),
+ rebar_prv_compile:build(S, AppInfo)
+ end, ToBuild),
+ expand_plugins(?DEFAULT_PLUGINS_DIR),
+ plugin_providers(Plugin)
+ catch
+ C:T ->
+ ?DEBUG("~p ~p", [C, T]),
+ ?WARN("Plugin ~p not available. It will not be used.~n", [Plugin]),
+ false
+ end.
+
+plugin_providers({Plugin, _, _}) when is_atom(Plugin) ->
+ validate_plugin(Plugin);
+plugin_providers({Plugin, _}) when is_atom(Plugin) ->
+ validate_plugin(Plugin);
+plugin_providers(Plugin) when is_atom(Plugin) ->
+ validate_plugin(Plugin).
+
+validate_plugin(Plugin) ->
+ Exports = sets:from_list(Plugin:module_info(exports)),
+ Required = sets:from_list([{init,1},
+ {do,1},
+ {format_error,2}]),
+ case sets:is_subset(Required, Exports) of
+ false ->
+ ?WARN("Plugin ~p is not a provider. It will not be used.~n", [Plugin]),
+ false;
+ true ->
+ {true, Plugin}
+ end.
+
+expand_plugins(Dir) ->
+ Apps = filelib:wildcard(filename:join([Dir, "*", "ebin"])),
+ ok = code:add_pathsa(Apps).
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 9fb1630..9d83f18 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -130,7 +130,13 @@ handle_deps(State, Deps, Update) ->
[];
PkgDeps1 ->
%% Find pkg deps needed
- {ok, S} = rlx_depsolver:solve(Graph, PkgDeps1),
+ S = case rlx_depsolver:solve(Graph, PkgDeps1) of
+ {ok, Solution} ->
+ Solution;
+ Reason ->
+ throw({error, {rlx_depsolver, Reason}})
+ end,
+
%% Create app_info record for each pkg dep
[AppInfo || Pkg <- S,
AppInfo <- package_to_app(DepsDir