diff options
author | Tristan Sloughter <t@crashfast.com> | 2014-11-29 17:05:21 -0600 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2014-11-29 17:05:21 -0600 |
commit | 9afd6e89b2dde0f8261bfd9eb371ffd33af0d889 (patch) | |
tree | 42c8e6670831e3d469c5667d069e35603762bc26 /src | |
parent | bdd5d902d9e66cd466a86c94d9484e68d637f888 (diff) |
global plugins install to global config directory
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar3.erl | 19 | ||||
-rw-r--r-- | src/rebar_packages.erl | 3 | ||||
-rw-r--r-- | src/rebar_plugins.erl | 10 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 5 | ||||
-rw-r--r-- | src/rebar_state.erl | 7 | ||||
-rw-r--r-- | src/rebar_utils.erl | 14 |
6 files changed, 38 insertions, 20 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index 5ea62e6..c2161b7 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -74,7 +74,7 @@ main(Args) -> run(BaseState, Command) -> _ = application:load(rebar), BaseState1 = rebar_state:set(BaseState, task, Command), - run_aux(BaseState1, [Command]). + run_aux(BaseState1, [], [Command]). %% ==================================================================== %% Internal functions @@ -82,7 +82,7 @@ run(BaseState, Command) -> run(RawArgs) -> _ = application:load(rebar), - BaseConfig = init_config(), + {GlobalPluginProviders, BaseConfig} = init_config(), case erlang:system_info(version) of "6.1" -> @@ -93,9 +93,9 @@ run(RawArgs) -> end, {BaseConfig1, _Args1} = set_options(BaseConfig, {[], []}), - run_aux(BaseConfig1, RawArgs). + run_aux(BaseConfig1, GlobalPluginProviders, RawArgs). -run_aux(State, RawArgs) -> +run_aux(State, GlobalPluginProviders, RawArgs) -> %% Make sure crypto is running case crypto:start() of ok -> ok; @@ -116,7 +116,8 @@ run_aux(State, RawArgs) -> {ok, PluginProviders, State3} = rebar_plugins:install(State2), rebar_core:update_code_path(State3), - State4 = rebar_state:create_logic_providers(Providers++PluginProviders, State3), + AllProviders = Providers++PluginProviders++GlobalPluginProviders, + State4 = rebar_state:create_logic_providers(AllProviders, State3), {Task, Args} = parse_args(RawArgs), rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)). @@ -147,9 +148,11 @@ init_config() -> true -> ?DEBUG("Load global config file ~p", [GlobalConfigFile]), - GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)), - rebar_state:new(GlobalConfig, Config1); + GlobalConfig = rebar_state:new(global, rebar_config:consult_file(GlobalConfigFile)), + {ok, PluginProviders, GlobalConfig1} = rebar_plugins:install(GlobalConfig), + rebar_state:new(GlobalConfig1, Config1); false -> + PluginProviders = [], rebar_state:new(Config1) end, @@ -165,7 +168,7 @@ init_config() -> %% TODO: Do we need this still? I think it may still be used. %% Initialize vsn cache - rebar_state:set(State1, vsn_cache, dict:new()). + {PluginProviders, rebar_state:set(State1, vsn_cache, dict:new())}. %% %% Parse command line arguments using getopt and also filtering out any diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index a0d1a9d..a2a7203 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -12,8 +12,7 @@ -spec get_packages(rebar_state:t()) -> {rebar_dict(), rebar_digraph()}. get_packages(State) -> - Home = rebar_utils:home_dir(), - RebarDir = rebar_state:get(State, global_rebar_dir, filename:join(Home, ?CONFIG_DIR)), + RebarDir = rebar_utils:global_config_dir(State), PackagesFile = filename:join(RebarDir, "packages"), case ec_file:exists(PackagesFile) of true -> diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 1877751..b6bf39b 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -13,19 +13,21 @@ install(State) -> %% Set deps_dir to a different dir for plugin so they don't collide - DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), + OldDepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR), - expand_plugins(?DEFAULT_PLUGINS_DIR), + DepsDir = rebar_utils:deps_dir(State1), + expand_plugins(DepsDir), Plugins = rebar_state:get(State1, plugins, []), PluginProviders = rebar_utils:filtermap(fun(Plugin) -> handle_plugin(Plugin, State1) end, Plugins), - {ok, PluginProviders, rebar_state:set(State1, deps_dir, DepsDir)}. + State2 = rebar_state:set(State1, deps_dir, OldDepsDir), + {ok, PluginProviders, State2}. handle_plugin(Plugin, State) -> try - {ok, State1} = rebar_prv_install_deps:handle_deps(State, [Plugin]), + {ok, _, State1} = rebar_prv_install_deps:handle_deps(State, [Plugin]), Apps = rebar_state:all_deps(State1), ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps), lists:foreach(fun(AppInfo) -> diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 44d0804..fd99d83 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -91,12 +91,13 @@ do(State) -> format_error(Reason) -> io_lib:format("~p", [Reason]). --spec handle_deps(rebar_state:t(), [dep()]) -> {ok, rebar_state:t()}. +-spec handle_deps(rebar_state:t(), [dep()]) -> + {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. handle_deps(State, Deps) -> handle_deps(State, Deps, false). -spec handle_deps(rebar_state:t(), [dep()], boolean() | {true, binary(), integer()}) - -> {ok, rebar_state:t()} | {error, string()}. + -> {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. handle_deps(State, [], _) -> {ok, State}; handle_deps(State, Deps, Update) -> diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 4b2d872..8b793a2 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -54,7 +54,12 @@ new(Config) when is_list(Config) -> #state_t { dir = rebar_utils:get_cwd(), opts = dict:from_list(Config) }. --spec new(t(), list()) -> t(). +-spec new(t() | atom(), list()) -> t(). +new(Profile, Config) when is_atom(Profile) + , is_list(Config) -> + #state_t { dir = rebar_utils:get_cwd(), + current_profile = Profile, + opts = dict:from_list(Config) }; new(ParentState=#state_t{}, Config) -> %% Load terms from rebar.config, if it exists Dir = rebar_utils:get_cwd(), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index d28d761..c84dcf2 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -36,6 +36,7 @@ default_profile_dir/1, default_profile_deps/1, home_dir/0, + global_config_dir/1, droplast/1, filtermap/2, @@ -108,10 +109,13 @@ lib_dirs(State) -> default_profile_dir(State) -> filename:join(base_dir(State), "default"). --spec profile_dir(rebar_state:t()) -> file:filename_all(). profile_dir(State) -> - Profile = rebar_state:current_profile(State), - filename:join(base_dir(State), atom_to_list(Profile)). + case rebar_state:current_profile(State) of + global -> + global_config_dir(State); + Profile -> + filename:join(base_dir(State), atom_to_list(Profile)) + end. -spec default_profile_deps(rebar_state:t()) -> file:filename_all(). default_profile_deps(State) -> @@ -121,6 +125,10 @@ home_dir() -> {ok, [[Home]]} = init:get_argument(home), Home. +global_config_dir(State) -> + Home = home_dir(), + rebar_state:get(State, global_rebar_dir, filename:join(Home, ?CONFIG_DIR)). + droplast(L) -> lists:reverse(tl(lists:reverse(L))). |