diff options
-rw-r--r-- | src/rebar_prv_upgrade.erl | 31 | ||||
-rw-r--r-- | test/rebar_upgrade_SUITE.erl | 15 |
2 files changed, 33 insertions, 13 deletions
diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index 37914a7..d7d2921 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -91,29 +91,38 @@ parse_names(Bin, Locks) -> prepare_locks([], _, Locks, Unlocks) -> {Locks, Unlocks}; prepare_locks([Name|Names], Deps, Locks, Unlocks) -> + AtomName = binary_to_atom(Name, utf8), case lists:keyfind(Name, 1, Locks) of {_, _, 0} = Lock -> - AtomName = binary_to_atom(Name, utf8), case lists:keyfind(AtomName, 1, Deps) of false -> ?PRV_ERROR({unknown_dependency, Name}); Dep -> - Source = case Dep of - {_, Src} -> Src; - {_, _, Src} -> Src - end, - {NewLocks, NewUnlocks} = unlock_higher_than(0, Locks -- [Lock]), - prepare_locks(Names, - Deps, - NewLocks, + {Source, NewLocks, NewUnlocks} = prepare_lock(Dep, Lock, Locks), + prepare_locks(Names, Deps, NewLocks, + [{Name, Source, 0} | NewUnlocks ++ Unlocks]) + end; + {_, _, Level} = Lock when Level > 0 -> + case lists:keyfind(AtomName, 1, Deps) of + false -> + ?PRV_ERROR({transitive_dependency, Name}); + Dep -> % Dep has been promoted + {Source, NewLocks, NewUnlocks} = prepare_lock(Dep, Lock, Locks), + prepare_locks(Names, Deps, NewLocks, [{Name, Source, 0} | NewUnlocks ++ Unlocks]) end; - {_, _, Level} when Level > 0 -> - ?PRV_ERROR({transitive_dependency, Name}); false -> ?PRV_ERROR({unknown_dependency, Name}) end. +prepare_lock(Dep, Lock, Locks) -> + Source = Source = case Dep of + {_, Src} -> Src; + {_, _, Src} -> Src + end, + {NewLocks, NewUnlocks} = unlock_higher_than(0, Locks -- [Lock]), + {Source, NewLocks, NewUnlocks}. + top_level_deps(Deps, Locks) -> [Dep || Dep <- Deps, lists:keymember(0, 3, Locks)]. diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl index 14186be..1dc0af2 100644 --- a/test/rebar_upgrade_SUITE.erl +++ b/test/rebar_upgrade_SUITE.erl @@ -10,7 +10,7 @@ groups() -> pair_a, pair_b, pair_ab, pair_c, pair_all, triplet_a, triplet_b, triplet_c, tree_a, tree_b, tree_c, tree_c2, tree_ac, tree_all, - delete_d]}, + delete_d, promote]}, {git, [], [{group, all}]}, {pkg, [], [{group, all}]}]. @@ -351,7 +351,17 @@ upgrades(delete_d) -> ], ["A","B", "C"], %% upgrade vs. new tree - {"", [{"A","2"}, "B", "C"]}}. + {"", [{"A","2"}, "B", "C"]}}; +upgrades(promote) -> + {[{"A", "1", [{"C", "1", []}]}, + {"B", "1", [{"D", "1", []}]} + ], + [{"A", "2", [{"C", "2", []}]}, + {"B", "2", [{"D", "2", []}]}, + {"C", "3", []} + ], + ["A","B","C","D"], + {"C", [{"A","1"},{"C","3"},{"B","1"},{"D","1"}]}}. %% TODO: add a test that verifies that unlocking files and then %% running the upgrade code is enough to properly upgrade things. @@ -414,6 +424,7 @@ tree_c(Config) -> run(Config). tree_c2(Config) -> run(Config). tree_ac(Config) -> run(Config). tree_all(Config) -> run(Config). +promote(Config) -> run(Config). delete_d(Config) -> meck:new(rebar_log, [no_link, passthrough]), |