summaryrefslogtreecommitdiff
path: root/src/rebar_utils.erl
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2015-05-17 19:51:58 -0500
committerTristan Sloughter <t@crashfast.com>2015-05-18 12:34:30 -0500
commit529025b6fdee96e0d9f487ebc20ce03e387910ca (patch)
treebc15b2499b40ea3049cc9885985ba76047f142e5 /src/rebar_utils.erl
parentcc2c55338bd7cccbd65d3be38f7c2fe636564f04 (diff)
purge loaded code when it conflicts with project apps in tests
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r--src/rebar_utils.erl18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 160d547..ffa29e6 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -47,6 +47,7 @@
deprecated/4,
erl_opts/1,
indent/1,
+ update_code/1,
cleanup_code_path/1,
args_to_tasks/1,
expand_env_variable/3,
@@ -563,6 +564,23 @@ filter_defines([Opt | Rest], Acc) ->
indent(Amount) when erlang:is_integer(Amount) ->
[?ONE_LEVEL_INDENT || _ <- lists:seq(1, Amount)].
+%% Replace code paths with new paths for existing apps and
+%% purge code of the old modules from those apps.
+update_code(Paths) ->
+ lists:foreach(fun(Path) ->
+ Name = filename:basename(Path, "/ebin"),
+ App = list_to_atom(Name),
+ application:load(App),
+ case application:get_key(App, modules) of
+ undefined ->
+ code:add_patha(Path),
+ ok;
+ {ok, Modules} ->
+ code:replace_path(Name, Path),
+ [begin code:purge(M), code:delete(M) end || M <- Modules]
+ end
+ end, Paths).
+
cleanup_code_path(OrigPath) ->
CurrentPath = code:get_path(),
AddedPaths = CurrentPath -- OrigPath,