From c283dd2c69174586e5964654a5fec8eeb66f6b6c Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Mon, 23 Feb 2015 22:57:34 +0000 Subject: Add tests and fixes for packages upgrades - Track level of packages properly, they're not level 0 anymore (this could yield an issue where a src dep takes precedence over a pkg dep) - Proper stable sort of vertices in the digraph module - PkgDeps no longer 'see themselves' when fetching and upgrading after locking themselves - Pkg Locks are added to pkg deps rather than source deps - Updating test cases to support pkg mocking on top of src mocking --- src/rebar_digraph.erl | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/rebar_digraph.erl') diff --git a/src/rebar_digraph.erl b/src/rebar_digraph.erl index 3f942ef..129ea35 100644 --- a/src/rebar_digraph.erl +++ b/src/rebar_digraph.erl @@ -71,29 +71,36 @@ restore_graph({Vs, Es}) -> cull_deps(Graph, Vertices) -> cull_deps(Graph, Vertices, + 1, + lists:foldl(fun({Key, _}, Levels) -> dict:store(Key, 0, Levels) end, + dict:new(), Vertices), lists:foldl(fun({Key, _}=N, Solution) -> dict:store(Key, N, Solution) end, dict:new(), Vertices), []). -cull_deps(_Graph, [], Solution, Discarded) -> +cull_deps(_Graph, [], _Level, Levels, Solution, Discarded) -> {_, Vertices} = lists:unzip(dict:to_list(Solution)), - {ok, Vertices, Discarded}; -cull_deps(Graph, Vertices, Solution, Discarded) -> - {NV, NS, DS} = - lists:foldl(fun(V, {NewVertices, SolutionAcc, DiscardedAcc}) -> - OutNeighbors = digraph:out_neighbours(Graph, V), - lists:foldl(fun({Key, _}=N, {NewVertices1, SolutionAcc1, DiscardedAcc1}) -> + LvlVertices = [{App,Vsn,dict:fetch(App,Levels)} || {App,Vsn} <- Vertices], + {ok, LvlVertices, Discarded}; +cull_deps(Graph, Vertices, Level, Levels, Solution, Discarded) -> + {NV, NS, LS, DS} = + lists:foldl(fun(V, {NewVertices, SolutionAcc, LevelsAcc, DiscardedAcc}) -> + OutNeighbors = lists:keysort(1, digraph:out_neighbours(Graph, V)), + lists:foldl(fun({Key, _}=N, {NewVertices1, SolutionAcc1, LevelsAcc1, DiscardedAcc1}) -> case dict:find(Key, SolutionAcc1) of {ok, N} -> % already seen - {NewVertices1, SolutionAcc1, DiscardedAcc1}; + {NewVertices1, SolutionAcc1, LevelsAcc, DiscardedAcc1}; {ok, _} -> % conflict resolution! - {NewVertices1, SolutionAcc1, [N|DiscardedAcc1]}; + {NewVertices1, SolutionAcc1, LevelsAcc, [N|DiscardedAcc1]}; error -> - {[N | NewVertices1], dict:store(Key, N, SolutionAcc1), DiscardedAcc1} + {[N | NewVertices1], + dict:store(Key, N, SolutionAcc1), + dict:store(Key, Level, LevelsAcc1), + DiscardedAcc1} end - end, {NewVertices, SolutionAcc, DiscardedAcc}, OutNeighbors) - end, {[], Solution, Discarded}, lists:sort(Vertices)), - cull_deps(Graph, NV, NS, DS). + end, {NewVertices, SolutionAcc, LevelsAcc, DiscardedAcc}, OutNeighbors) + end, {[], Solution, Levels, Discarded}, lists:keysort(1, Vertices)), + cull_deps(Graph, NV, Level+1, LS, NS, DS). subgraph(Graph, Vertices) -> digraph_utils:subgraph(Graph, Vertices). -- cgit v1.1