diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index ec6fe31e7..0949c8f2b 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -51,7 +51,7 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) -> ?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []), throw(?PRV_ERROR({bad_provider, Type, Command, ProviderName})); {ok, State2} -> - rebar_utils:remove_from_code_path(PluginDepsPaths), + rebar_utils:remove_from_code_path(PluginDepsPaths, State), State2 end end. diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index edb2d82cc..a30ec6efa 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -39,7 +39,7 @@ do(State) -> IsDepsOnly = is_deps_only(State), DepsPaths = rebar_state:code_paths(State, all_deps), PluginDepsPaths = rebar_state:code_paths(State, all_plugin_deps), - rebar_utils:remove_from_code_path(PluginDepsPaths), + rebar_utils:remove_from_code_path(PluginDepsPaths, State), code:add_pathsa(DepsPaths), Providers = rebar_state:providers(State), @@ -163,7 +163,7 @@ compile(State, Providers, AppInfo) -> code:add_pathsa(PluginDepsPaths), AppFileCompileResult = rebar_otp_app:compile(State, AppInfo4), %% Clean up after ourselves, leave things as they were. - rebar_utils:remove_from_code_path(PluginDepsPaths), + rebar_utils:remove_from_code_path(PluginDepsPaths, State), case AppFileCompileResult of {ok, AppInfo5} -> diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 995d2124b..6635a3c5d 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -49,6 +49,7 @@ update_code/1, update_code/2, remove_from_code_path/1, + remove_from_code_path/2, cleanup_code_path/1, args_to_tasks/1, expand_env_variable/3, @@ -785,6 +786,21 @@ update_code(Paths, Opts) -> end end, Paths). +-spec remove_from_code_path(Paths, State) -> Res when + Paths :: list(string()), + State :: rebar_state:t(), + Res :: ok. +remove_from_code_path(Paths, State) -> + case unload_plugins(State) of + true -> + remove_from_code_path(Paths); + false -> + ok + end. + +-spec remove_from_code_path(Paths) -> Res when + Paths :: list(string()), + Res :: ok. remove_from_code_path(Paths) -> lists:foreach(fun(Path) -> Name = filename:basename(Path, "/ebin"), @@ -807,6 +823,12 @@ remove_from_code_path(Paths) -> code:del_path(Path) end, lists:usort(Paths)). +-spec unload_plugins(State) -> Res when + State :: rebar_state:t(), + Res :: boolean(). +unload_plugins(State) -> + rebar_state:get(State, unload_plugins, true). + %% @doc Revert to only having the beams necessary for running rebar3 and %% plugins in the path -spec cleanup_code_path([string()]) -> true | {error, term()}.