Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give more flexibility to del dep by name in overrides #2500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rebar_opts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,26 @@ override_opt(Opts1, Opts2) ->

%% @private
del_dep(OldValue, [Value]) when is_atom(Value) ->
NewValue = lists:keydelete(atom_to_binary(Value, utf8), 1, OldValue),
NewValue = del_dep_by_name(Value, OldValue),
del_dep(NewValue, OldValue, [Value]);
del_dep(OldValue, [{Value, _Version, _Source}]) ->
NewValue = lists:keydelete(atom_to_binary(Value, utf8), 1, OldValue),
NewValue = del_dep_by_name(Value, OldValue),
del_dep(NewValue, OldValue, [{Value, _Version, _Source}]);
del_dep(OldValue, [Value]) ->
del_dep(OldValue, OldValue, [Value]);
del_dep(OldValue, [Value|Values]) ->
NewValue = del_dep(del_dep(OldValue, [Value]), OldValue, [Value]),
del_dep(NewValue, Values).

del_dep_by_name(Name, Deps) ->
DepName = rebar_utils:to_binary(Name),
lists:filter(fun(Dep) -> dep_name(Dep) /= DepName end, Deps).

dep_name(Dep) when is_tuple(Dep) ->
rebar_utils:to_binary(element(1, Dep));
dep_name(Dep) ->
rebar_utils:to_binary(Dep).

%% @private
%% If the initial deletion did not work remove it as always
%% to ensure rebar3 at least maintains its old behaviour.
Expand Down
6 changes: 4 additions & 2 deletions test/rebar_compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,8 @@ override_del_deps(Config) ->
{"dep_b", "0.0.1", []},
{"dep_c", "0.0.1", []}]},
{"other_dep", "0.0.1", [{"dep_c", "0.0.1", []},
{"dep_d", "0.0.1", []}]}]),
{"dep_d", "0.0.1", []},
{"dep_e", "0.0.1", []}]}]),
TopDeps = rebar_test_utils:top_level_deps(Deps),

DepA = {dep_a, "0.0.1", {git, "https://example.org/user/dep_a.git", {tag, "0.0.1"}}},
Expand All @@ -1759,7 +1760,7 @@ override_del_deps(Config) ->
{deps, [DepA, DepB]}
]},
{del, [
{deps, [DepC]}
{deps, [DepC, dep_e]}
]}
]}
],
Expand All @@ -1771,6 +1772,7 @@ override_del_deps(Config) ->
{dep_not_exist, "dep_a"},
{dep_not_exist, "dep_b"},
{dep_not_exist, "dep_c"},
{dep_not_exist, "dep_e"},
{dep, "dep_d"}]}
).

Expand Down