diff options
-rw-r--r-- | src/rebar_prv_install_deps.erl | 20 | ||||
-rw-r--r-- | src/rebar_prv_upgrade.erl | 50 |
2 files changed, 36 insertions, 34 deletions
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 49aa65c..094fae0 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -254,10 +254,9 @@ update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen, {SeenAcc1, StateAcc1} = maybe_lock(Profile, AppInfo, SeenAcc, StateAcc, Level), {SrcDepsAcc1, PkgDepsAcc1, SrcAppsAcc1, StateAcc2, LocksAcc1} = case Update of - {true, UpdateName, UpdateLevel} -> + true -> + %{true, UpdateName, UpdateLevel} -> handle_update(AppInfo - ,UpdateName - ,UpdateLevel ,SrcDepsAcc ,PkgDepsAcc ,SrcAppsAcc @@ -285,14 +284,15 @@ update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen, update_src_deps(Profile, Level+1, NewSrcDeps, NewPkgDeps, NewSrcApps, State1, Update, Seen1, NewLocks) end. -handle_update(AppInfo, UpdateName, UpdateLevel, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) -> +handle_update(AppInfo, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) -> Name = rebar_app_info:name(AppInfo), - {_, _, DepLevel} = lists:keyfind(Name, 1, Locks), - case UpdateLevel < DepLevel - orelse Name =:= UpdateName of - true -> + ct:pal("update ~p", [Name]), + case lists:keyfind(Name, 1, Locks) of + false -> + ct:pal("in lock"), case maybe_fetch(AppInfo, true, []) of true -> + ct:pal("fetch!"), handle_dep(AppInfo ,SrcDeps ,PkgDeps @@ -302,9 +302,11 @@ handle_update(AppInfo, UpdateName, UpdateLevel, SrcDeps, PkgDeps, SrcApps, Level ,Locks); false -> + ct:pal("nofetch"), {SrcDeps, PkgDeps, SrcApps, State, Locks} end; - false -> + _StillLocked -> + ct:pal("stillocked"), {SrcDeps, PkgDeps, SrcApps, State, Locks} end. diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index 4609f57..207d36a 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -12,7 +12,7 @@ -include("rebar.hrl"). -define(PROVIDER, upgrade). --define(DEPS, [lock]). +-define(DEPS, []). %% Also only upgrade top-level (0) deps. Transitive deps shouldn't be %% upgradable -- if the user wants this, they should declare it at the %% top level and then upgrade. @@ -41,38 +41,38 @@ init(State) -> do(State) -> {Args, _} = rebar_state:command_parsed_args(State), Name = ec_cnv:to_binary(proplists:get_value(package, Args)), - Locks = rebar_state:lock(State), - %% TODO: optimize by running the find + unlock in one sweep - case find_app(Name, Locks) of - {AppInfo, 0} -> - %% Unlock the app and all those with a lock level higher than - %% it has - NewLocks = unlock_higher_than(0, Locks -- [AppInfo]), - {ok, rebar_state:lock(State, NewLocks)}; - {_AppInfo, Level} when Level > 0 -> + Locks = rebar_state:get(State, {locks, default}, []), + case lists:keyfind(Name, 1, Locks) of + {_, _, 0} = Lock -> + Deps = rebar_state:get(State, deps), + case lists:keyfind(binary_to_atom(Name, utf8), 1, Deps) of + false -> + {error, unknown_dependency}; + Dep -> + Source = case Dep of + {_, Src} -> Src; + {_, _, Src} -> Src + end, + NewLocks = unlock_higher_than(0, Locks -- [Lock]), + State1 = rebar_state:set(State, {deps, default}, [{Name, Source, 0} | NewLocks]), + State2 = rebar_state:set(State1, {locks, default}, NewLocks), + rebar_prv_install_deps:do(State2) + end; + {_, _, Level} when Level > 0 -> {error, transitive_dependency}; false -> - {error, unknown_dependency} + ct:pal("deps: ~p", [{Name,Locks}]), + {error, unlocked_dependency} end. -find_app(_Name, []) -> false; -find_app(Name, [App|Apps]) -> - case rebar_app_info:name(App) of - Name -> {App, rebar_app_info:dep_level(App)}; - _ -> find_app(Name, Apps) - end. -%% Because we operate on a lock list, removing the app from the list -%% unlocks it. unlock_higher_than(_, []) -> []; -unlock_higher_than(Level, [App | Apps]) -> - case rebar_app_info:dep_level(App) of - N when N > Level -> - unlock_higher_than(Level, Apps); - N when N =< Level -> - [App | unlock_higher_than(Level, Apps)] +unlock_higher_than(Level, [App = {_,_,AppLevel} | Apps]) -> + if AppLevel > Level -> unlock_higher_than(Level, Apps); + AppLevel =< Level -> [App | unlock_higher_than(Level, Apps)] end. -spec format_error(any()) -> iolist(). format_error(Reason) -> io_lib:format("~p", [Reason]). + |