summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-04-23 22:02:05 -0500
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-04-23 22:02:05 -0500
commit557de99d6c9893504d32dbd870f2ca12651c44d6 (patch)
tree78f60d0538217cc452b109631059196bff05e2c6
parente79397eaebb04159fb4bdfaaecfd99c65cb93139 (diff)
parent5d1634448cb89cd4c0b6f49e757ef281d5e71205 (diff)
Merge pull request #368 from ferd/fix-upgrade-promote
handle transitive deps being promoted
-rw-r--r--src/rebar_prv_upgrade.erl31
-rw-r--r--test/rebar_upgrade_SUITE.erl15
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]),