diff options
Diffstat (limited to 'src/rebar_config.erl')
-rw-r--r-- | src/rebar_config.erl | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/rebar_config.erl b/src/rebar_config.erl index c1c4381..76e03ea 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -28,10 +28,12 @@ -export([consult/1 ,consult_file/1 + ,format_error/1 ,merge_locks/2]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). %% =================================================================== %% Public API @@ -77,6 +79,9 @@ merge_locks(Config, [Locks]) -> NewDeps = find_newly_added(ConfigDeps, Locks), [{{locks, default}, Locks}, {{deps, default}, NewDeps++Deps} | Config]. +format_error({bad_dep_name, Dep}) -> + io_lib:format("Dependency name must be an atom, instead found: ~p", [Dep]). + %% =================================================================== %% Internal functions %% =================================================================== @@ -106,21 +111,27 @@ bs(Vars) -> %% Find deps that have been added to the config after the lock was created find_newly_added(ConfigDeps, LockedDeps) -> - [Dep || Dep <- ConfigDeps, - begin - NewDep = ec_cnv:to_binary(element(1, Dep)), - case lists:keyfind(NewDep, 1, LockedDeps) of - false -> - true; - Match -> - case element(3, Match) of - 0 -> - true; - _ -> - ?WARN("Newly added dep ~s is locked at a lower level. " - "If you really want to unlock it, use 'rebar3 upgrade ~s'", - [NewDep, NewDep]), - false - end - end - end]. + rebar_utils:filtermap(fun(Dep) when is_tuple(Dep) -> + check_newly_added(element(1, Dep), LockedDeps); + (Dep) -> + check_newly_added(Dep, LockedDeps) + end, ConfigDeps). + +check_newly_added(Dep, LockedDeps) when is_atom(Dep) -> + NewDep = ec_cnv:to_binary(Dep), + case lists:keyfind(NewDep, 1, LockedDeps) of + false -> + true; + Match -> + case element(3, Match) of + 0 -> + true; + _ -> + ?WARN("Newly added dep ~s is locked at a lower level. " + "If you really want to unlock it, use 'rebar3 upgrade ~s'", + [NewDep, NewDep]), + false + end + end; +check_newly_added(Dep, _) -> + throw(?PRV_ERROR({bad_dep_name, Dep})). |