diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2014-12-06 18:56:47 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2014-12-06 18:56:47 -0500 |
commit | fb98dde7ecb894fe74055449dcaea77aa237115b (patch) | |
tree | 95feb148cd7c33f46b15ec7fa60edd02ae46cfa0 /src | |
parent | d5907ad9b932feaf7fdf1cdbb4319226ef22ea78 (diff) | |
parent | be39ab9e7bd1553132def2a1e89f1ce38f6f2fcc (diff) |
Merge pull request #44 from rebar/fix-circular-deps
Partial fix to circular deps (#40)
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_digraph.erl | 10 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/rebar_digraph.erl b/src/rebar_digraph.erl index bb031cb..dbcf649 100644 --- a/src/rebar_digraph.erl +++ b/src/rebar_digraph.erl @@ -18,7 +18,15 @@ compile_order(Apps) -> end, Apps), case digraph_utils:topsort(Graph) of false -> - {error, no_sort}; + case digraph_utils:is_acyclic(Graph) of + true -> + {error, no_sort}; + false -> + Cycles = lists:sort( + [lists:sort(Comp) || Comp <- digraph_utils:strong_components(Graph), + length(Comp)>1]), + {error, {cycles, Cycles}} + end; V -> {ok, names_to_apps(lists:reverse(V), Apps)} end. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index a3ffc66..1be094c 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -81,6 +81,8 @@ do(State) -> {ok, rebar_state:deps_to_build(State1, lists:dropwhile(fun rebar_app_info:valid/1 , Sort -- ProjectApps))}; + {error, {cycles, Cycles}} -> + {error, {?MODULE, {cycles, Cycles}}}; {error, Error} -> {error, Error} end @@ -91,6 +93,12 @@ do(State) -> end. -spec format_error(any()) -> iolist(). +format_error({cycles, Cycles}) -> + Prints = [["applications: ", + [io_lib:format("~s ", [Dep]) || Dep <- Cycle], + "depend on each other~n"] + || Cycle <- Cycles], + ["Dependency cycle(s) detected:~n", Prints]; format_error(Reason) -> io_lib:format("~p", [Reason]). @@ -151,7 +159,7 @@ update_pkg_deps(Pkgs, Packages, Update, Seen, State) -> ,Packages ,Pkg), {SeenAcc1, StateAcc1} = maybe_lock(AppInfo, SeenAcc, StateAcc), - case maybe_fetch(StateAcc1, AppInfo, Update, SeenAcc) of + case maybe_fetch(StateAcc1, AppInfo, Update, SeenAcc1) of true -> {[AppInfo | Acc], SeenAcc1, StateAcc1}; false -> @@ -167,7 +175,7 @@ maybe_lock(AppInfo, Seen, State) -> {sets:add_element(Name, Seen), rebar_state:lock(State, AppInfo)}; true -> - {sets:add_element(Name, Seen), State} + {Seen, State} end. package_to_app(DepsDir, Packages, {Name, Vsn}) -> @@ -204,7 +212,7 @@ update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> ,Level ,StateAcc1); _ -> - maybe_fetch(StateAcc, AppInfo, false, SeenAcc), + maybe_fetch(StateAcc, AppInfo, false, SeenAcc1), handle_dep(AppInfo ,SrcDepsAcc ,PkgDepsAcc |