瀏覽代碼

handle transitive deps being promoted

pull/368/head
Fred Hebert 10 年之前
父節點
當前提交
5d1634448c
共有 2 個檔案被更改,包括 33 行新增13 行删除
  1. +20
    -11
      src/rebar_prv_upgrade.erl
  2. +13
    -2
      test/rebar_upgrade_SUITE.erl

+ 20
- 11
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)].

+ 13
- 2
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]),

Loading…
取消
儲存