diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_app_info.erl | 9 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 63 | ||||
-rw-r--r-- | src/rebar_prv_lock.erl | 3 | ||||
-rw-r--r-- | src/rebar_state.erl | 14 |
4 files changed, 59 insertions, 30 deletions
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 008bfd2..44394b3 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -21,6 +21,8 @@ ebin_dir/1, deps/1, deps/2, + dep_level/1, + dep_level/2, dir/1, dir/2, source/1, @@ -37,6 +39,7 @@ original_vsn :: string(), app_details=[] :: list(), deps=[] :: list(), + dep_level :: integer(), dir :: file:name(), source :: string() | undefined, valid :: boolean()}). @@ -166,6 +169,12 @@ deps(#app_info_t{deps=Deps}) -> deps(AppInfo=#app_info_t{}, Deps) -> AppInfo#app_info_t{deps=Deps}. +dep_level(AppInfo=#app_info_t{}, Level) -> + AppInfo#app_info_t{dep_level=Level}. + +dep_level(AppInfo=#app_info_t{dep_level=Level}) -> + Level. + -spec dir(t()) -> file:name(). dir(#app_info_t{dir=Dir}) -> Dir. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 3b78fd1..03dfce4 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -69,13 +69,13 @@ do(State) -> ProjectApps = rebar_state:project_apps(State), {ok, State1} = case rebar_state:get(State, locks, []) of [] -> - handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, []))); + handle_deps(State, rebar_state:get(State, deps, [])); Locks -> - handle_deps(State, ordsets:from_list(Locks)) + handle_deps(State, Locks) end, - Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State1)), - {ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)), + Source = ProjectApps ++ rebar_state:src_deps(State1), + {ok, Sort} = rebar_topo:sort_apps(Source), {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}. -spec get_deps_dir(rebar_state:t()) -> file:filename_all(). @@ -106,7 +106,7 @@ handle_deps(State, Deps, Update) -> SrcDeps), %% Fetch transitive src deps - State2 = update_src_deps(State1, Update), + State2 = update_src_deps(0, State1, Update), Solved = case rebar_state:binary_deps(State2) of [] -> %% No binary deps []; @@ -124,9 +124,10 @@ handle_deps(State, Deps, Update) -> end, S) end, - AllDeps = ordsets:union([ordsets:to_list(rebar_state:src_deps(State2)) - ,ordsets:from_list(Solved)]), - + AllDeps = lists:keymerge(2 + ,rebar_state:src_apps(State2) + ,Solved), + io:format("All ~p~n", [AllDeps]), %% Sort all apps to build order State3 = rebar_state:set(State2, all_deps, AllDeps), {ok, State3}. @@ -154,21 +155,28 @@ package_to_app(DepsDir, Packages, Name, Vsn) -> rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, <<Name/binary, "-", FmtVsn/binary>>)), rebar_app_info:source(AppInfo2, Link). --spec update_src_deps(rebar_state:t(), boolean()) -> rebat_state:t(). -update_src_deps(State, Update) -> +-spec update_src_deps(integer(), rebar_state:t(), boolean()) -> rebat_state:t(). +update_src_deps(Level, State, Update) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), - case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> - ok = maybe_fetch(AppInfo, Update), - {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), - {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) - ,NewBinaryDeps++BinaryDepsAcc} - end, {ordsets:new(), rebar_state:binary_deps(State)}, SrcDeps) of - {NewSrcDeps, NewBinaryDeps} when length(SrcDeps) =:= length(NewSrcDeps) -> - rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps); - {NewSrcDeps, NewBinaryDeps} -> - State1 = rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps), - update_src_deps(State1, Update) + case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc, StateAcc}) -> + case maybe_fetch(AppInfo, Update) of + true -> + {AppInfo1, NewSrcDeps, NewBinaryDeps} = + handle_dep(DepsDir, AppInfo), + AppInfo2 = rebar_app_info:dep_level(AppInfo1, Level), + {NewSrcDeps ++ SrcDepsAcc + ,NewBinaryDeps++BinaryDepsAcc + ,rebar_state:src_apps(StateAcc, AppInfo2)}; + false -> + {SrcDepsAcc, BinaryDepsAcc, State} + end + end, {[], rebar_state:binary_deps(State), State}, SrcDeps) of + {NewSrcDeps, NewBinaryDeps, State1} when length(SrcDeps) =:= length(NewSrcDeps) -> + rebar_state:src_deps(rebar_state:binary_deps(State1, NewBinaryDeps), NewSrcDeps); + {NewSrcDeps, NewBinaryDeps, State1} -> + State2 = rebar_state:src_deps(rebar_state:binary_deps(State1, NewBinaryDeps), NewSrcDeps), + update_src_deps(Level+1, State2, Update) end. -spec handle_dep(binary(), rebar_state:t()) -> {[rebar_app_info:t()], [binary_dep()]}. @@ -180,7 +188,7 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, BinaryDeps}. --spec maybe_fetch(rebar_app_info:t(), boolean()) -> ok. +-spec maybe_fetch(rebar_app_info:t(), boolean()) -> boolean(). maybe_fetch(AppInfo, Update) -> AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), %Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), @@ -201,12 +209,13 @@ maybe_fetch(AppInfo, Update) -> true -> ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source); + rebar_fetch:download_source(AppDir, Source), + true; _ -> - ok + false end. --spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. +-spec parse_deps(binary(), [dep()]) -> {[rebar_app_info:t()], [binary_dep()]}. parse_deps(DepsDir, Deps) -> lists:foldl(fun({Name, Vsn}, {SrcDepsAcc, BinaryDepsAcc}) -> {SrcDepsAcc, [parse_goal(ec_cnv:to_binary(Name) @@ -222,8 +231,8 @@ parse_deps(DepsDir, Deps) -> rebar_app_info:new(Name, Vsn, Dir) end, Dep1 = rebar_app_info:source(Dep, Source), - {ordsets:add_element(Dep1, SrcDepsAcc), BinaryDepsAcc} - end, {ordsets:new(), []}, Deps). + {[Dep1 | SrcDepsAcc], BinaryDepsAcc} + end, {[], []}, Deps). -spec parse_goal(binary(), binary()) -> binary_dep(). parse_goal(Name, Constraint) -> diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl index b4a7d8d..441c46d 100644 --- a/src/rebar_prv_lock.erl +++ b/src/rebar_prv_lock.erl @@ -40,7 +40,8 @@ do(State) -> Source when is_tuple(Source) -> {rebar_app_info:name(Dep) ,rebar_app_info:original_vsn(Dep) - ,rebar_fetch:lock_source(Dir, Source)}; + ,rebar_fetch:lock_source(Dir, Source) + ,rebar_app_info:dep_level(Dep)}; _Source -> {rebar_app_info:name(Dep) ,rebar_app_info:original_vsn(Dep)} diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 706c528..ac6684d 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -13,6 +13,7 @@ deps_names/1, binary_deps/1, binary_deps/2, src_deps/1, src_deps/2, + src_apps/1, src_apps/2, prepend_hook/3, append_hook/3, hooks/2, providers/1, providers/2, add_provider/2]). @@ -35,9 +36,10 @@ envs = new_env() :: rebar_dict(), command_args = [] :: list(), - src_deps = ordsets:new() :: ordsets:ordset(rebar_app_info:t()), + src_deps = [] :: [rebar_app_info:t()], + src_apps = [] :: dict:dict(), binary_deps = [], - project_apps = ordsets:new() :: ordsets:ordset(rebar_app_info:t()), + project_apps = [] :: [rebar_app_info:t()], providers = [], hooks = [], @@ -139,6 +141,14 @@ src_deps(State=#state_t{src_deps=SrcDeps}, NewSrcDeps) when is_list(SrcDeps) -> src_deps(State=#state_t{src_deps=SrcDeps}, SrcDep) -> State#state_t{src_deps=[SrcDep | SrcDeps]}. +src_apps(#state_t{src_apps=SrcApps}) -> + SrcApps. + +src_apps(State=#state_t{src_apps=SrcApps}, NewSrcApps) when is_list(NewSrcApps) -> + State#state_t{src_apps=NewSrcApps}; +src_apps(State=#state_t{src_apps=SrcApps}, NewSrcApp) -> + State#state_t{src_apps=[NewSrcApp | SrcApps]}. + project_apps(#state_t{project_apps=Apps}) -> Apps. |