diff options
-rw-r--r-- | src/rebar_prv_install_deps.erl | 51 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 12 |
2 files changed, 47 insertions, 16 deletions
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 1c3049c..2498215 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -92,7 +92,7 @@ get_deps_dir(DepsDir, App) -> handle_deps(State, Deps) -> handle_deps(State, Deps, false). --spec handle_deps(rebar_state:t(), [dep()], boolean()) -> {ok, rebar_state:t()}. +-spec handle_deps(rebar_state:t(), [dep()], false | {true, integer()}) -> {ok, rebar_state:t()}. handle_deps(State, [], _) -> {ok, State}; handle_deps(State, Deps, Update) -> @@ -160,16 +160,35 @@ update_src_deps(Level, State, Update) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), 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} + Name = rebar_app_info:name(AppInfo), + Locks = rebar_state:get(State, locks, []), + {_, _, _, DepLevel} = lists:keyfind(Name, 1, Locks), + case Update of + {true, UpdateName, UpdateLevel} when UpdateLevel < DepLevel + ; Name =:= UpdateName -> + case maybe_fetch(AppInfo, true) 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; + _ -> + case maybe_fetch(AppInfo, false) 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 end, {[], rebar_state:binary_deps(State), State}, SrcDeps) of {NewSrcDeps, NewBinaryDeps, State1} when length(SrcDeps) =:= length(NewSrcDeps) -> @@ -232,6 +251,16 @@ parse_deps(DepsDir, Deps) -> rebar_app_info:new(Name, Vsn, Dir) end, Dep1 = rebar_app_info:source(Dep, Source), + {[Dep1 | SrcDepsAcc], BinaryDepsAcc}; + ({Name, Vsn, Source, _Level}, {SrcDepsAcc, BinaryDepsAcc}) when is_tuple (Source) -> + Dir = ec_cnv:to_list(get_deps_dir(DepsDir, Name)), + {ok, Dep} = case rebar_app_info:discover(Dir) of + {ok, App} -> + {ok, App}; + not_found -> + rebar_app_info:new(Name, Vsn, Dir) + end, + Dep1 = rebar_app_info:source(Dep, Source), {[Dep1 | SrcDepsAcc], BinaryDepsAcc} end, {[], []}, Deps). diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index b599266..5180d4a 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -11,7 +11,7 @@ -include("rebar.hrl"). -define(PROVIDER, update). --define(DEPS, [install_deps]). +-define(DEPS, [lock]). %% =================================================================== %% Public API @@ -33,10 +33,12 @@ init(State) -> do(State) -> case rebar_state:command_args(State) of [Name] -> - ?ERROR("NOT IMPLEMENTED: Updating ~s~n", [Name]), - AllDeps = rebar_state:get(State, all_deps, []), - {ok, _App} = rebar_app_utils:find(list_to_binary(Name), AllDeps), - rebar_prv_install_deps:handle_deps(State, [list_to_atom(Name)], true), + ?ERROR("Updating ~s~n", [Name]), + Locks = rebar_state:get(State, locks, []), + {_, _, _, Level} = lists:keyfind(ec_cnv:to_binary(Name), 1, Locks), + Deps = rebar_state:get(State, deps), + Dep = lists:keyfind(list_to_atom(Name), 1, Deps), + rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}), {ok, State}; [] -> ?INFO("Updating package index...~n", []), |