Explorar el Código

Cull default dep names in non-default upgrade

Prevents showing false upgrade messages when upgrading in a non-default
profile. Also shows an info message explaining default deps don't get
updated in a non-default upgrade.
pull/1540/head
Fred Hebert hace 8 años
padre
commit
0ce1a4f5fe
Se han modificado 2 ficheros con 54 adiciones y 12 borrados
  1. +28
    -10
      src/rebar_prv_upgrade.erl
  2. +26
    -2
      test/rebar_upgrade_SUITE.erl

+ 28
- 10
src/rebar_prv_upgrade.erl Ver fichero

@ -70,16 +70,9 @@ do(State) ->
is_atom(Dep) orelse is_atom(element(1, Dep))],
Names = parse_names(ec_cnv:to_binary(proplists:get_value(package, Args, <<"">>)), Locks),
DepsDict = deps_dict(rebar_state:all_deps(State)),
%% Find alternative deps in non-default profiles since they may
%% need to be passed through (they are never locked)
AltProfiles = rebar_state:current_profiles(State) -- [default],
AltProfileDeps = lists:append([
rebar_state:get(State, {deps, Profile}, []) || Profile <- AltProfiles]
),
AltDeps = [Dep || Dep <- AltProfileDeps,
is_atom(Dep) orelse is_atom(element(1, Dep))
andalso not lists:member(Dep, Deps)],
case prepare_locks(Names, Deps, Locks, [], DepsDict, AltDeps) of
AltDeps = find_non_default_deps(Deps, State),
FilteredNames = cull_default_names_if_profiles(Names, Deps, State),
case prepare_locks(FilteredNames, Deps, Locks, [], DepsDict, AltDeps) of
{error, Reason} ->
{error, Reason};
{Locks0, _Unlocks0} ->
@ -124,6 +117,31 @@ parse_names(Bin, Locks) ->
Other -> Other
end.
%% Find alternative deps in non-default profiles since they may
%% need to be passed through (they are never locked)
find_non_default_deps(Deps, State) ->
AltProfiles = rebar_state:current_profiles(State) -- [default],
AltProfileDeps = lists:append([
rebar_state:get(State, {deps, Profile}, []) || Profile <- AltProfiles]
),
[Dep || Dep <- AltProfileDeps,
is_atom(Dep) orelse is_atom(element(1, Dep))
andalso not lists:member(Dep, Deps)].
%% If any alt profiles are used, remove the default profiles from
%% the upgrade list and warn about it.
cull_default_names_if_profiles(Names, Deps, State) ->
case rebar_state:current_profiles(State) of
[default] ->
Names;
_ ->
?INFO("Dependencies in the default profile will not be upgraded", []),
lists:filter(fun(Name) ->
AtomName = binary_to_atom(Name, utf8),
rebar_utils:tup_find(AtomName, Deps) == false
end, Names)
end.
prepare_locks([], _, Locks, Unlocks, _Dict, _AltDeps) ->
{Locks, Unlocks};
prepare_locks([Name|Names], Deps, Locks, Unlocks, Dict, AltDeps) ->

+ 26
- 2
test/rebar_upgrade_SUITE.erl Ver fichero

@ -11,7 +11,8 @@ groups() ->
triplet_a, triplet_b, triplet_c,
tree_a, tree_b, tree_c, tree_c2, tree_cj, tree_ac, tree_all,
delete_d, promote, stable_lock, fwd_lock,
compile_upgrade_parity, umbrella_config, profiles]},
compile_upgrade_parity, umbrella_config,
profiles, profiles_exclusion]},
{git, [], [{group, all}]},
{pkg, [], [{group, all}]}].
@ -78,7 +79,8 @@ setup_project(Case=umbrella_config, Config0, Deps, UpDeps) ->
[{rebarconfig, TopConf},
{rebarumbrella, RebarConf},
{next_top_deps, rebar_test_utils:top_level_deps(UpDeps)} | Config];
setup_project(Case=profiles, Config0, Deps, UpDeps) ->
setup_project(Case, Config0, Deps, UpDeps) when Case == profiles;
Case == profiles_exclusion ->
DepsType = ?config(deps_type, Config0),
NameRoot = atom_to_list(Case)++"_"++atom_to_list(DepsType),
Config = rebar_test_utils:init_rebar_state(Config0, NameRoot++"_"),
@ -489,6 +491,26 @@ upgrades(profiles) ->
{"I",[]}]}],
["A","B","C","E","F","H"],
{"C", [{"A","1"}, "D", {"E","3"},
{"B","2"}, {"F","2"}, "G",
{"C","1"}, {"H","4"}, "I"]}};
upgrades(profiles_exclusion) ->
%% Ensure that we can unlock deps under a given profile;
%% B and C should both be in a custom profile
%% and must not be locked.
{[{"A", "1", [{"D",[]},
{"E","3",[]}]},
{"B", "1", [{"F","1",[]},
{"G",[]}]},
{"C", "0", [{"H","3",[]},
{"I",[]}]}],
[{"A", "2", [{"D",[]},
{"E","2",[]}]},
{"B", "2", [{"F","2",[]},
{"G",[]}]},
{"C", "1", [{"H","4",[]},
{"I",[]}]}],
["A","B","C","E","F","H"],
{"A", [{"A","1"}, "D", {"E","3"},
{"B","2"}, {"F","2"}, "G",
{"C","1"}, {"H","4"}, "I"]}}.
@ -678,6 +700,8 @@ profiles(Config) ->
),
meck:unload(rebar_prv_app_discovery).
profiles_exclusion(Config) -> profiles(Config).
run(Config) ->
apply(?config(mock, Config), []),
ConfigPath = ?config(rebarconfig, Config),

Cargando…
Cancelar
Guardar