Browse Source

install plugins to plugins/

pull/3/head
Tristan Sloughter 10 years ago
parent
commit
f4f96a356f
3 changed files with 32 additions and 18 deletions
  1. +3
    -2
      src/rebar3.erl
  2. +8
    -1
      src/rebar_plugins.erl
  3. +21
    -15
      src/rebar_prv_install_deps.erl

+ 3
- 2
src/rebar3.erl View File

@ -140,8 +140,9 @@ run_aux(State, Args) ->
%% Process each command, resetting any state between each one %% Process each command, resetting any state between each one
State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))), State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))),
{ok, Providers} = application:get_env(rebar, providers), {ok, Providers} = application:get_env(rebar, providers),
Plugins = rebar_state:get(State2, plugins, []),
State3 = rebar_state:create_logic_providers(Providers++Plugins, State2),
rebar_plugins:install(State2),
State3 = rebar_state:create_logic_providers(Providers, State2),
Task = rebar_state:get(State3, task, "help"), Task = rebar_state:get(State3, task, "help"),
rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)), rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)),
ok. ok.

+ 8
- 1
src/rebar_plugins.erl View File

@ -3,10 +3,17 @@
-module(rebar_plugins). -module(rebar_plugins).
-export([]).
-export([install/1]).
-include("rebar.hrl"). -include("rebar.hrl").
%% =================================================================== %% ===================================================================
%% Public API %% Public API
%% =================================================================== %% ===================================================================
install(State) ->
BaseDir = rebar_state:get(State, base_dir, ""),
State1 = rebar_state:set(State, base_dir, "plugins"),
Plugins = rebar_state:get(State1, plugins, []),
{ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins),
{ok, rebar_state:set(State2, base_dir, BaseDir)}.

+ 21
- 15
src/rebar_prv_install_deps.erl View File

@ -33,7 +33,8 @@
-include("rebar.hrl"). -include("rebar.hrl").
-export([setup_env/1]).
-export([setup_env/1,
handle_deps/2]).
%% for internal use only %% for internal use only
-export([get_deps_dir/1]). -export([get_deps_dir/1]).
@ -65,12 +66,18 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
do(State) -> do(State) ->
case rebar_state:get(State, locks, []) of
[] ->
handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, [])));
Locks ->
handle_deps(State, ordsets:from_list(Locks))
end.
ProjectApps = rebar_state:project_apps(State),
{ok, State1} = case rebar_state:get(State, locks, []) of
[] ->
handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, [])));
Locks ->
handle_deps(State, ordsets:from_list(Locks))
end,
Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State1)),
{ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)),
{ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}.
%% set REBAR_DEPS_DIR and ERL_LIBS environment variables %% set REBAR_DEPS_DIR and ERL_LIBS environment variables
setup_env(State) -> setup_env(State) ->
@ -99,17 +106,12 @@ get_deps_dir(State) ->
get_deps_dir(DepsDir, App) -> get_deps_dir(DepsDir, App) ->
filename:join(DepsDir, App). filename:join(DepsDir, App).
%% ===================================================================
%% Internal functions
%% ===================================================================
-spec handle_deps(rebar_state:t(), [dep()]) -> {ok, rebar_state:t()}. -spec handle_deps(rebar_state:t(), [dep()]) -> {ok, rebar_state:t()}.
handle_deps(State, []) -> handle_deps(State, []) ->
{ok, State}; {ok, State};
handle_deps(State, Deps) -> handle_deps(State, Deps) ->
%% Read in package index and dep graph %% Read in package index and dep graph
{Packages, Graph} = rebar_packages:get_packages(State), {Packages, Graph} = rebar_packages:get_packages(State),
ProjectApps = rebar_state:project_apps(State),
%% Split source deps form binary deps, needed to keep backwards compatibility %% Split source deps form binary deps, needed to keep backwards compatibility
DepsDir = get_deps_dir(State), DepsDir = get_deps_dir(State),
@ -136,14 +138,18 @@ handle_deps(State, Deps) ->
end, S) end, S)
end, end,
Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State2)),
AllDeps = ordsets:union([ordsets:to_list(rebar_state:src_deps(State2)) AllDeps = ordsets:union([ordsets:to_list(rebar_state:src_deps(State2))
,ordsets:from_list(Solved)]), ,ordsets:from_list(Solved)]),
%% Sort all apps to build order %% Sort all apps to build order
State3 = rebar_state:set(State2, all_deps, AllDeps), State3 = rebar_state:set(State2, all_deps, AllDeps),
{ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)),
{ok, rebar_state:set(State3, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}.
{ok, State3}.
%% ===================================================================
%% Internal functions
%% ===================================================================
-spec is_valid(rebar_app_info:t()) -> boolean(). -spec is_valid(rebar_app_info:t()) -> boolean().
is_valid(App) -> is_valid(App) ->

Loading…
Cancel
Save