Kaynağa Gözat

install plugins to plugins/

pull/3/head
Tristan Sloughter 10 yıl önce
ebeveyn
işleme
51f1cf4aae
6 değiştirilmiş dosya ile 53 ekleme ve 47 silme
  1. +2
    -1
      include/rebar.hrl
  2. +8
    -8
      priv/templates/plugin.erl.dtl
  3. +6
    -4
      src/rebar3.erl
  4. +12
    -8
      src/rebar_core.erl
  5. +21
    -3
      src/rebar_plugins.erl
  6. +4
    -23
      src/rebar_prv_install_deps.erl

+ 2
- 1
include/rebar.hrl Dosyayı Görüntüle

@ -23,6 +23,7 @@
opts :: list()}). % The list of options that the task requires/understands
-define(DEFAULT_LIB_DIRS, ["apps", "libs", "."]).
-define(DEFAULT_DEPS_DIRS, ["deps"]).
-define(DEFAULT_DEPS_DIR, "deps").
-define(DEFAULT_PLUGINS_DIR, "plugins").
-define(DEFAULT_CONFIG_FILE, "rebar.config").
-define(LOCK_FILE, "rebar.lock").

+ 8
- 8
priv/templates/plugin.erl.dtl Dosyayı Görüntüle

@ -14,14 +14,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
State1 = rebar_state:(State, rebar_provider:create([{name, ?PROVIDER},
{provider_impl, ?MODULE},
{bare, false},
{deps, ?DEPS},
{example, "rebar {{appid}}"},
{short_desc, "{{appid}} plugin."},
{desc, ""},
{opts, []}])),
State1 = rebar_state:add_provider(State, rebar_provider:create([{name, ?PROVIDER},
{provider_impl, ?MODULE},
{bare, false},
{deps, ?DEPS},
{example, "rebar {{appid}}"},
{short_desc, "{{appid}} plugin."},
{desc, ""},
{opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()}.

+ 6
- 4
src/rebar3.erl Dosyayı Görüntüle

@ -141,10 +141,12 @@ run_aux(State, Args) ->
State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))),
{ok, Providers} = application:get_env(rebar, providers),
rebar_plugins:install(State2),
State3 = rebar_state:create_logic_providers(Providers, State2),
Task = rebar_state:get(State3, task, "help"),
rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)),
{ok, PluginProviders, State3} = rebar_plugins:install(State2),
rebar_core:update_code_path(State),
State4 = rebar_state:create_logic_providers(Providers++PluginProviders, State3),
Task = rebar_state:get(State4, task, "help"),
rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)),
ok.
%%

+ 12
- 8
src/rebar_core.erl Dosyayı Görüntüle

@ -26,16 +26,12 @@
%% -------------------------------------------------------------------
-module(rebar_core).
-export([process_command/2]).
-export([process_command/2
,update_code_path/1]).
-include("rebar.hrl").
process_command(State, Command) ->
true = rebar_utils:expand_code_path(),
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIRS),
_UpdatedCodePaths = update_code_path([DepsDir | LibDirs]),
%% ? rebar_prv_install_deps:setup_env(State),
TargetProviders = rebar_provider:get_target_providers(Command, State),
@ -47,13 +43,21 @@ process_command(State, Command) ->
Conf1
end, State, TargetProviders).
update_code_path(State) ->
true = rebar_utils:expand_code_path(),
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
PluginsDir = rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR),
_UpdatedCodePaths = update_code_path_([DepsDir, PluginsDir | LibDirs]).
%% ===================================================================
%% Internal functions
%% ===================================================================
update_code_path([]) ->
update_code_path_([]) ->
no_change;
update_code_path(Paths) ->
update_code_path_(Paths) ->
LibPaths = expand_lib_dirs(Paths, rebar_utils:get_cwd(), []),
ok = code:add_pathsa(LibPaths),
%% track just the paths we added, so we can remove them without

+ 21
- 3
src/rebar_plugins.erl Dosyayı Görüntüle

@ -12,8 +12,26 @@
%% ===================================================================
install(State) ->
BaseDir = rebar_state:get(State, base_dir, ""),
State1 = rebar_state:set(State, base_dir, "plugins"),
State1 = rebar_state:set(State, deps_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)}.
Apps = rebar_state:get(State2, all_deps),
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, Apps),
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).

+ 4
- 23
src/rebar_prv_install_deps.erl Dosyayı Görüntüle

@ -33,8 +33,7 @@
-include("rebar.hrl").
-export([setup_env/1,
handle_deps/2]).
-export([handle_deps/2]).
%% for internal use only
-export([get_deps_dir/1]).
@ -78,29 +77,11 @@ do(State) ->
{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
setup_env(State) ->
DepsDir = get_deps_dir(State),
%% include rebar's DepsDir in ERL_LIBS
Separator = case os:type() of
{win32, nt} ->
";";
_ ->
":"
end,
ERL_LIBS = case os:getenv("ERL_LIBS") of
false ->
{"ERL_LIBS", DepsDir};
PrevValue ->
{"ERL_LIBS", DepsDir ++ Separator ++ PrevValue}
end,
[{"REBAR_DEPS_DIR", DepsDir}, ERL_LIBS].
-spec get_deps_dir(rebar_state:t()) -> file:filename_all().
get_deps_dir(State) ->
BaseDir = rebar_state:get(State, base_dir, ""),
get_deps_dir(BaseDir, "deps").
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
get_deps_dir(BaseDir, DepsDir).
-spec get_deps_dir(file:filename_all(), rebar_state:t()) -> file:filename_all().
get_deps_dir(DepsDir, App) ->
@ -113,7 +94,7 @@ handle_deps(State, Deps) ->
%% Read in package index and dep graph
{Packages, Graph} = rebar_packages:get_packages(State),
%% Split source deps form binary deps, needed to keep backwards compatibility
%% Split source deps from binary deps, needed to keep backwards compatibility
DepsDir = get_deps_dir(State),
{SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps),
State1 = rebar_state:src_deps(rebar_state:binary_deps(State, BinaryDeps),

Yükleniyor…
İptal
Kaydet