Browse Source

reset default profile app plugins to empty if at the top level (#1885)

top level default profile plugins are installed in the run_aux
function. This commit removes the plugins from the plugin opts
of an application that is also at the top level and skips the
default profile when installing top level plugins in
project_apps_install so they aren't handled twice.

Additionally, before handling a plugin the state's list of
known plugin apps is checked and the plugin is skipped if it
has already been handled.
pull/1888/head
Tristan Sloughter 6 years ago
committed by GitHub
parent
commit
cd858a45e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 23 deletions
  1. +21
    -14
      src/rebar_app_discover.erl
  2. +24
    -9
      src/rebar_plugins.erl

+ 21
- 14
src/rebar_app_discover.erl View File

@ -98,8 +98,7 @@ merge_deps(AppInfo, State) ->
%% the State and at the top level, not as part of an application.
CurrentProfiles = rebar_state:current_profiles(State),
Default = reset_hooks(rebar_state:default(State), CurrentProfiles),
{C, State1} = project_app_config(AppInfo, State),
AppInfo0 = rebar_app_info:update_opts(AppInfo, Default, C),
{AppInfo0, State1} = project_app_config(AppInfo, Default, State),
Name = rebar_app_info:name(AppInfo0),
@ -154,28 +153,36 @@ parse_profile_deps(Profile, Name, Deps, Opts, State) ->
%% @doc Find the app-level config and return the state updated
%% with the relevant app-level data.
-spec project_app_config(rebar_app_info:t(), rebar_state:t()) ->
-spec project_app_config(rebar_app_info:t(), rebar_dict(), rebar_state:t()) ->
{Config, rebar_state:t()} when
Config :: [any()].
project_app_config(AppInfo, State) ->
project_app_config(AppInfo, Default, State) ->
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
AppInfo1 = rebar_app_info:update_opts(AppInfo, Default, C),
{AppInfo2, State1} = maybe_reset_hooks_plugins(AppInfo1, State),
{AppInfo2, State1}.
-spec maybe_reset_hooks_plugins(AppInfo, State) -> {AppInfo, State} when
AppInfo :: rebar_app_info:t(),
State :: rebar_state:t().
maybe_reset_hooks_plugins(AppInfo, State) ->
Dir = rebar_app_info:dir(AppInfo),
Opts = maybe_reset_hooks(Dir, rebar_state:opts(State), State),
{C, rebar_state:opts(State, Opts)}.
%% @private Check if the app is at the root of the project.
%% If it is, then drop the hooks from the config so they aren't run twice
-spec maybe_reset_hooks(file:filename(), Opts, rebar_state:t()) -> Opts when
Opts :: rebar_dict().
maybe_reset_hooks(Dir, Opts, State) ->
case ec_file:real_dir_path(rebar_dir:root_dir(State)) of
Dir ->
CurrentProfiles = rebar_state:current_profiles(State),
reset_hooks(Opts, CurrentProfiles);
Opts = reset_hooks(rebar_state:opts(State), CurrentProfiles),
State1 = rebar_state:opts(State, Opts),
%% set plugins to empty since this is an app at the top level
%% and top level plugins are installed in run_aux
AppInfo1 = rebar_app_info:set(rebar_app_info:set(AppInfo, {plugins,default}, []), plugins, []),
{AppInfo1, State1};
_ ->
Opts
{AppInfo, State}
end.
%% @doc make the hooks empty for a given set of options
-spec reset_hooks(Opts, Profiles) ->
Opts when

+ 24
- 9
src/rebar_plugins.erl View File

@ -39,13 +39,18 @@ project_apps_install(State) ->
Profiles = rebar_state:current_profiles(State),
ProjectApps = rebar_state:project_apps(State),
lists:foldl(fun(Profile, StateAcc) ->
Plugins = rebar_state:get(State, {plugins, Profile}, []),
StateAcc1 = handle_plugins(Profile, Plugins, StateAcc),
StateAcc1 = case Profile of
default ->
%% default profile top level plugins
%% are installed in run_aux
StateAcc;
_ ->
Plugins = rebar_state:get(State, {plugins, Profile}, []),
handle_plugins(Profile, Plugins, StateAcc)
end,
lists:foldl(fun(AppInfo, StateAcc2) ->
C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
AppInfo0 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C),
Plugins2 = rebar_app_info:get(AppInfo0, {plugins, Profile}, []),
Plugins2 = rebar_app_info:get(AppInfo, {plugins, Profile}, []),
handle_plugins(Profile, Plugins2, StateAcc2)
end, StateAcc1, ProjectApps)
end, State, Profiles).
@ -62,12 +67,25 @@ install(State, AppInfo) ->
State2 = lists:foldl(fun(Profile, StateAcc) ->
Plugins = rebar_app_info:get(AppInfo, {plugins, Profile}, []),
handle_plugins(Profile, Plugins, StateAcc)
Plugins1 = filter_existing_plugins(Plugins, StateAcc),
handle_plugins(Profile, Plugins1, StateAcc)
end, State1, Profiles),
%% Reset the overrides after processing the dep
rebar_state:set(State2, overrides, StateOverrides).
filter_existing_plugins(Plugins, State) ->
PluginNames = lists:zip(Plugins, rebar_state:deps_names(Plugins)),
AllPlugins = rebar_state:all_plugin_deps(State),
lists:filtermap(fun({Plugin, PluginName}) ->
case rebar_app_utils:find(PluginName, AllPlugins) of
{ok, _} ->
false;
_ ->
{true, Plugin}
end
end, PluginNames).
handle_plugins(Profile, Plugins, State) ->
handle_plugins(Profile, Plugins, State, false).
@ -76,7 +94,6 @@ handle_plugins(Profile, Plugins, State, Upgrade) ->
Locks = rebar_state:lock(State),
DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR),
State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR),
%% Install each plugin individually so if one fails to install it doesn't effect the others
{_PluginProviders, State2} =
lists:foldl(fun(Plugin, {PluginAcc, StateAcc}) ->
@ -122,8 +139,6 @@ handle_plugin(Profile, Plugin, State, Upgrade) ->
build_plugin(AppInfo, Apps, State) ->
Providers = rebar_state:providers(State),
%Providers1 = rebar_state:providers(rebar_app_info:state(AppInfo)),
%rebar_app_info:state_or_new(State, AppInfo)
S = rebar_state:all_deps(State, Apps),
S1 = rebar_state:set(S, deps_dir, ?DEFAULT_PLUGINS_DIR),
rebar_prv_compile:compile(S1, Providers, AppInfo).

Loading…
Cancel
Save