Browse Source

rename functions to be clearer

pull/16/head
Tristan Sloughter 10 years ago
parent
commit
6ec98e0b69
3 changed files with 15 additions and 11 deletions
  1. +12
    -8
      src/rebar_digraph.erl
  2. +2
    -2
      src/rebar_prv_install_deps.erl
  3. +1
    -1
      src/rebar_prv_test_deps.erl

+ 12
- 8
src/rebar_digraph.erl View File

@ -1,14 +1,15 @@
-module(rebar_digraph). -module(rebar_digraph).
-export([sort_apps/1
-export([compile_order/1
,restore_graph/1 ,restore_graph/1
,solve/2
,cull_deps/2
,subgraph/2 ,subgraph/2
,format_error/1]). ,format_error/1]).
-include("rebar.hrl"). -include("rebar.hrl").
sort_apps(Apps) ->
%% Sort apps with topological sort to get proper build order
compile_order(Apps) ->
Graph = digraph:new(), Graph = digraph:new(),
lists:foreach(fun(App) -> lists:foreach(fun(App) ->
Name = rebar_app_info:name(App), Name = rebar_app_info:name(App),
@ -50,15 +51,18 @@ restore_graph({Vs, Es}) ->
end, Es), end, Es),
Graph. Graph.
solve(Graph, Vertices) ->
solve(Graph, Vertices, lists:foldl(fun({Key, _}=N, Solution) ->
%% Pick packages to fullfill dependencies
%% The first dep while traversing the graph is chosen and any conflicting
%% dep encountered later on is ignored.
cull_deps(Graph, Vertices) ->
cull_deps(Graph, Vertices, lists:foldl(fun({Key, _}=N, Solution) ->
dict:store(Key, N, Solution) dict:store(Key, N, Solution)
end, dict:new(), Vertices)). end, dict:new(), Vertices)).
solve(_Graph, [], Solution) ->
cull_deps(_Graph, [], Solution) ->
{_, Vertices} = lists:unzip(dict:to_list(Solution)), {_, Vertices} = lists:unzip(dict:to_list(Solution)),
{ok, Vertices}; {ok, Vertices};
solve(Graph, Vertices, Solution) ->
cull_deps(Graph, Vertices, Solution) ->
{NV, NS} = {NV, NS} =
lists:foldl(fun(V, {NewVertices, SolutionAcc}) -> lists:foldl(fun(V, {NewVertices, SolutionAcc}) ->
OutNeighbors = digraph:out_neighbours(Graph, V), OutNeighbors = digraph:out_neighbours(Graph, V),
@ -71,7 +75,7 @@ solve(Graph, Vertices, Solution) ->
end end
end, {NewVertices, SolutionAcc}, OutNeighbors) end, {NewVertices, SolutionAcc}, OutNeighbors)
end, {[], Solution}, Vertices), end, {[], Solution}, Vertices),
solve(Graph, NV, NS).
cull_deps(Graph, NV, NS).
subgraph(Graph, Vertices) -> subgraph(Graph, Vertices) ->
digraph_utils:subgraph(Graph, Vertices). digraph_utils:subgraph(Graph, Vertices).

+ 2
- 2
src/rebar_prv_install_deps.erl View File

@ -77,7 +77,7 @@ do(State) ->
end, end,
Source = ProjectApps ++ rebar_state:src_apps(State1), Source = ProjectApps ++ rebar_state:src_apps(State1),
case rebar_digraph:sort_apps(Source) of
case rebar_digraph:compile_order(Source) of
{ok, Sort} -> {ok, Sort} ->
{ok, rebar_state:set(State1, deps_to_build, {ok, rebar_state:set(State1, deps_to_build,
lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps))}; lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps))};
@ -130,7 +130,7 @@ handle_deps(State, Deps, Update) ->
[]; [];
PkgDeps1 -> PkgDeps1 ->
%% Find pkg deps needed %% Find pkg deps needed
S = case rebar_digraph:solve(Graph, PkgDeps1) of
S = case rebar_digraph:cull_deps(Graph, PkgDeps1) of
{ok, []} -> {ok, []} ->
throw({rebar_digraph, no_solution}); throw({rebar_digraph, no_solution});
{ok, Solution} -> {ok, Solution} ->

+ 1
- 1
src/rebar_prv_test_deps.erl View File

@ -43,7 +43,7 @@ do(State) ->
AllDeps = rebar_state:get(State2, all_deps, []), AllDeps = rebar_state:get(State2, all_deps, []),
State3 = rebar_state:set(State2, deps_dir, DepsDir), State3 = rebar_state:set(State2, deps_dir, DepsDir),
case rebar_digraph:sort_apps(ProjectApps1++AllDeps) of
case rebar_digraph:compile_order(ProjectApps1++AllDeps) of
{ok, Sort} -> {ok, Sort} ->
ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps1), ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps1),
State4 = rebar_state:set(State3, deps_to_build, ToBuild), State4 = rebar_state:set(State3, deps_to_build, ToBuild),

Loading…
Cancel
Save