summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2015-04-05 08:52:57 -0500
committerTristan Sloughter <t@crashfast.com>2015-04-05 08:52:57 -0500
commit79e2d6006c989a241d4599d048ff39f094f9e886 (patch)
treee7caacaba07013911b2b2ad4bff400812dd02a70
parent019152e1d5e23e60f734e8d14309ea7ed45b01fc (diff)
install each deps plugins after handling dep, instead of at the end
-rw-r--r--src/rebar3.erl18
-rw-r--r--src/rebar_plugins.erl36
-rw-r--r--src/rebar_prv_install_deps.erl14
3 files changed, 33 insertions, 35 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index f853411..461206d 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -77,7 +77,7 @@ run(BaseState, Commands) ->
_ = application:load(rebar),
BaseState1 = rebar_state:set(BaseState, task, Commands),
BaseState2 = rebar_state:set(BaseState1, caller, api),
- run_aux(BaseState2, [], Commands).
+ run_aux(BaseState2, Commands).
%% ====================================================================
%% Internal functions
@@ -86,7 +86,7 @@ run(BaseState, Commands) ->
run(RawArgs) ->
_ = application:load(rebar),
- {GlobalPluginProviders, BaseState} = init_config(),
+ BaseState = init_config(),
BaseState1 = rebar_state:set(BaseState, caller, command_line),
case erlang:system_info(version) of
@@ -98,9 +98,9 @@ run(RawArgs) ->
end,
{BaseState2, _Args1} = set_options(BaseState1, {[], []}),
- run_aux(BaseState2, GlobalPluginProviders, RawArgs).
+ run_aux(BaseState2, RawArgs).
-run_aux(State, GlobalPluginProviders, RawArgs) ->
+run_aux(State, RawArgs) ->
%% Make sure crypto is running
case crypto:start() of
ok -> ok;
@@ -126,11 +126,10 @@ run_aux(State, GlobalPluginProviders, RawArgs) ->
{ok, Providers} = application:get_env(rebar, providers),
{ok, Resources} = application:get_env(rebar, resources),
State4 = rebar_state:resources(State3, Resources),
- {ok, PluginProviders, State5} = rebar_plugins:install(State4),
+ State5 = rebar_plugins:install(State4),
%% Providers can modify profiles stored in opts, so set default after initializing providers
- AllProviders = Providers++PluginProviders++GlobalPluginProviders,
- State6 = rebar_state:create_logic_providers(AllProviders, State5),
+ State6 = rebar_state:create_logic_providers(Providers, State5),
State7 = rebar_state:default(State6, rebar_state:opts(State6)),
{Task, Args} = parse_args(RawArgs),
@@ -158,10 +157,9 @@ init_config() ->
?DEBUG("Load global config file ~p",
[GlobalConfigFile]),
GlobalConfig = rebar_state:new(global, rebar_config:consult_file(GlobalConfigFile)),
- {ok, PluginProviders, GlobalConfig1} = rebar_plugins:install(GlobalConfig),
+ GlobalConfig1 = rebar_plugins:install(GlobalConfig),
rebar_state:new(GlobalConfig1, Config1);
false ->
- PluginProviders = [],
rebar_state:new(Config1)
end,
@@ -177,7 +175,7 @@ init_config() ->
%% TODO: Do we need this still? I think it may still be used.
%% Initialize vsn cache
- {PluginProviders, rebar_state:set(State1, vsn_cache, dict:new())}.
+ rebar_state:set(State1, vsn_cache, dict:new()).
parse_args([]) ->
parse_args(["help"]);
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl
index 45321e8..a9550ff 100644
--- a/src/rebar_plugins.erl
+++ b/src/rebar_plugins.erl
@@ -3,7 +3,7 @@
-module(rebar_plugins).
--export([install/1]).
+-export([install/1, handle_plugins/2]).
-include("rebar.hrl").
@@ -11,12 +11,10 @@
%% Public API
%% ===================================================================
+-spec install(rebar_state:t()) -> rebar_state:t().
install(State) ->
DepsDir = rebar_dir:deps_dir(State),
- %% Set deps_dir to a different dir for plugin so they don't collide
- OldDepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
- State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR),
- Plugins = rebar_state:get(State1, plugins, []),
+ Plugins = rebar_state:get(State, plugins, []),
ProjectApps = rebar_state:project_apps(State),
DepApps = rebar_app_discover:find_apps([DepsDir], all),
@@ -28,20 +26,22 @@ install(State) ->
rebar_state:get(S, plugins, [])
end, ProjectApps++DepApps),
- PluginProviders = lists:flatten(rebar_utils:filtermap(fun(Plugin) ->
- handle_plugin(Plugin, State1)
- end, Plugins++OtherPlugins)),
+ handle_plugins(Plugins++OtherPlugins, State).
- State2 = rebar_state:set(State1, deps_dir, OldDepsDir),
+-spec handle_plugins([rebar_prv_install_deps:dep()], rebar_state:t()) -> rebar_state:t().
+handle_plugins(Plugins, State) ->
+ PluginProviders = lists:flatmap(fun(Plugin) ->
+ handle_plugin(Plugin, State)
+ end, Plugins),
+ rebar_state:create_logic_providers(PluginProviders, State).
- {ok, PluginProviders, State2}.
-
--spec handle_plugin(rebar_prv_install_deps:dep(), rebar_state:t()) -> {true, any()} | false.
handle_plugin(Plugin, State) ->
try
- {ok, _, State1} = rebar_prv_install_deps:handle_deps(default, State, [Plugin]),
+ %% Set deps dir to plugins dir so apps are installed there
+ State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR),
+ {ok, _, State2} = rebar_prv_install_deps:handle_deps(default, State1, [Plugin]),
- Apps = rebar_state:all_deps(State1),
+ Apps = rebar_state:all_deps(State2),
ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps),
[build_plugin(AppInfo) || AppInfo <- ToBuild],
plugin_providers(Plugin)
@@ -49,7 +49,7 @@ handle_plugin(Plugin, State) ->
C:T ->
?DEBUG("~p ~p", [C, T]),
?WARN("Plugin ~p not available. It will not be used.", [Plugin]),
- false
+ []
end.
build_plugin(AppInfo) ->
@@ -70,14 +70,14 @@ validate_plugin(Plugin) ->
_ = application:load(Plugin),
case application:get_env(Plugin, providers) of
{ok, Providers} ->
- {true, Providers};
+ Providers;
undefined ->
Exports = Plugin:module_info(exports),
case lists:member({init,1}, Exports) of
false ->
?WARN("Plugin ~p does not export init/1. It will not be used.", [Plugin]),
- false;
+ [];
true ->
- {true, Plugin}
+ [Plugin]
end
end.
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 851cbf2..db2b036 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -85,10 +85,7 @@ do(State) ->
no_cycle ->
case compile_order(Source, ProjectApps) of
{ok, ToCompile} ->
- %% Deps may have plugins to install. Find and intall here.
- {ok, PluginProviders, State2} = rebar_plugins:install(State1),
- State3 = rebar_state:create_logic_providers(PluginProviders, State2),
- {ok, rebar_state:deps_to_build(State3, ToCompile)};
+ {ok, rebar_state:deps_to_build(State1, ToCompile)};
{error, Error} ->
{error, Error}
end
@@ -339,13 +336,13 @@ handle_upgrade(AppInfo, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) ->
handle_dep(AppInfo, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) ->
DepsDir = rebar_dir:deps_dir(State),
- {AppInfo1, NewSrcDeps, NewPkgDeps, NewLocks} =
+ {AppInfo1, NewSrcDeps, NewPkgDeps, NewLocks, State1} =
handle_dep(State, DepsDir, AppInfo, Locks, Level),
AppInfo2 = rebar_app_info:dep_level(AppInfo1, Level),
{NewSrcDeps ++ SrcDeps
,NewPkgDeps++PkgDeps
,[AppInfo2 | SrcApps]
- ,State
+ ,State1
,NewLocks}.
-spec handle_dep(rebar_state:t(), file:filename_all(), rebar_app_info:t(), list(), integer()) ->
@@ -362,13 +359,16 @@ handle_dep(State, DepsDir, AppInfo, Locks, Level) ->
S3 = rebar_state:apply_overrides(S2, Name),
AppInfo1 = rebar_app_info:state(AppInfo, S3),
+ %% Dep may have plugins to install. Find and install here.
+ State1 = rebar_plugins:handle_plugins(rebar_state:get(S3, plugins, []), State),
+
Deps = rebar_state:get(S3, deps, []),
%% Upgrade lock level to be the level the dep will have in this dep tree
NewLocks = [{DepName, Source, LockLevel+Level} ||
{DepName, Source, LockLevel} <- rebar_state:get(S3, {locks, default}, [])],
AppInfo2 = rebar_app_info:deps(AppInfo1, rebar_state:deps_names(Deps)),
{SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps, S3, Locks, Level),
- {AppInfo2, SrcDeps, PkgDeps, Locks++NewLocks}.
+ {AppInfo2, SrcDeps, PkgDeps, Locks++NewLocks, State1}.
-spec maybe_fetch(rebar_app_info:t(), boolean() | {true, binary(), integer()},
sets:set(binary()), rebar_state:t()) -> boolean().