diff options
-rw-r--r-- | src/rebar_api.erl | 1 | ||||
-rw-r--r-- | src/rebar_app_discover.erl | 9 | ||||
-rw-r--r-- | src/rebar_prv_app_discovery.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_common_test.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_dialyzer.erl | 5 | ||||
-rw-r--r-- | src/rebar_prv_eunit.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 26 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 3 | ||||
-rw-r--r-- | src/rebar_prv_upgrade.erl | 7 | ||||
-rw-r--r-- | src/rebar_prv_xref.erl | 3 | ||||
-rw-r--r-- | test/rebar_install_deps_SUITE.erl | 43 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 22 |
12 files changed, 95 insertions, 33 deletions
diff --git a/src/rebar_api.erl b/src/rebar_api.erl index c217b85..a01391d 100644 --- a/src/rebar_api.erl +++ b/src/rebar_api.erl @@ -2,6 +2,7 @@ %%% that can be used by plugin builders. -module(rebar_api). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -export([abort/0, abort/2, console/2, debug/2, info/2, warn/2, error/2]). diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 63cf703..0799313 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -48,7 +48,9 @@ merge_deps(AppInfo, State) -> State1 = lists:foldl(fun(Profile, StateAcc) -> AppProfDeps = rebar_state:get(AppState, {deps, Profile}, []), TopLevelProfDeps = rebar_state:get(StateAcc, {deps, Profile}, []), - ProfDeps2 = lists:keymerge(1, TopLevelProfDeps, AppProfDeps), + ProfDeps2 = dedup(lists:keymerge(1, + lists:keysort(1, TopLevelProfDeps), + lists:keysort(1, AppProfDeps))), rebar_state:set(StateAcc, {deps, Profile}, ProfDeps2) end, State, lists:reverse(CurrentProfiles)), @@ -166,3 +168,8 @@ create_app_info(AppDir, AppFile) -> _ -> error end. + +dedup([]) -> []; +dedup([A]) -> [A]; +dedup([H,H|T]) -> dedup([H|T]); +dedup([H|T]) -> [H|dedup(T)]. diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl index 5e304cb..31c0f59 100644 --- a/src/rebar_prv_app_discovery.erl +++ b/src/rebar_prv_app_discovery.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, app_discovery). -define(DEPS, []). @@ -38,7 +39,7 @@ do(State) -> {ok, State1} catch throw:{error, Error}-> - {error, {?MODULE, Error}} + ?PRV_ERROR(Error) end. -spec format_error(any()) -> iolist(). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index c49f4c5..f4085c5 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, ct). -define(DEPS, [compile]). @@ -46,7 +47,7 @@ do(State) -> {ok, CTOpts} -> run_test(State, RawOpts, CTOpts); {error, Reason} -> - {error, {?MODULE, Reason}} + ?PRV_ERROR(Reason) end. run_test(State, RawOpts, CTOpts) -> diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index 24e276d..ef6a64c 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, dialyzer). -define(DEPS, [compile]). @@ -70,9 +71,9 @@ do(State) -> do(State, Plt, Apps) catch throw:{dialyzer_error, Error} -> - {error, {?MODULE, {error_processing_apps, Error}}}; + ?PRV_ERROR({error_processing_apps, Error}); throw:{dialyzer_warnings, Warnings} -> - {error, {?MODULE, {dialyzer_warnings, Warnings}}} + ?PRV_ERROR({dialyzer_warnings, Warnings}) end. -spec format_error(any()) -> iolist(). diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 8763344..0e0e937 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, eunit). -define(DEPS, [compile]). @@ -46,7 +47,7 @@ do(State) -> ok = rebar_prv_cover:maybe_write_coverdata(State, ?PROVIDER), case handle_results(Result) of {error, Reason} -> - {error, {?MODULE, Reason}}; + ?PRV_ERROR(Reason); ok -> {ok, State} end. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 1c269fb..48402da 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -189,7 +189,7 @@ update_pkg_deps(Profile, Packages, PkgDeps, Graph, Upgrade, Seen, State) -> {ok, Solution, []} -> Solution; {ok, Solution, Discarded} -> - [warn_skip_pkg(Pkg) || Pkg <- Discarded], + [warn_skip_pkg(Pkg, State) || Pkg <- Discarded], Solution end, update_pkg_deps(Profile, S, Packages, Upgrade, Seen, State) @@ -287,7 +287,7 @@ update_seen_src_dep(AppInfo, Level, SrcDeps, PkgDeps, SrcApps, State, Upgrade, S %% If seen from lock file don't print warning about skipping case lists:keymember(Name, 1, BaseLocks) of false -> - warn_skip_deps(AppInfo); + warn_skip_deps(AppInfo, State); true -> ok end, @@ -513,13 +513,21 @@ parse_goal(Name, Constraint) -> fail end. -warn_skip_deps(AppInfo) -> - ?WARN("Skipping ~s (from ~p) as an app of the same name " +warn_skip_deps(AppInfo, State) -> + Msg = "Skipping ~s (from ~p) as an app of the same name " "has already been fetched~n", - [rebar_app_info:name(AppInfo), - rebar_app_info:source(AppInfo)]). + Args = [rebar_app_info:name(AppInfo), + rebar_app_info:source(AppInfo)], + case rebar_state:get(State, deps_error_on_conflict, false) of + false -> ?WARN(Msg, Args); + true -> ?ERROR(Msg, Args), ?FAIL + end. -warn_skip_pkg({Name, Source}) -> - ?WARN("Skipping ~s (version ~s from package index) as an app of the same " +warn_skip_pkg({Name, Source}, State) -> + Msg = "Skipping ~s (version ~s from package index) as an app of the same " "name has already been fetched~n", - [Name, Source]). + Args = [Name, Source], + case rebar_state:get(State, deps_error_on_conflict, false) of + false -> ?WARN(Msg, Args); + true -> ?ERROR(Msg, Args), ?FAIL + end. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index d0bdd1b..e851f7b 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, update). -define(DEPS, []). @@ -48,7 +49,7 @@ do(State) -> ok catch _E:_C -> - throw({error, {?MODULE, package_index_write}}) + ?PRV_ERROR(package_index_write) end, {ok, State}. diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index 1cae5aa..37914a7 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, upgrade). -define(DEPS, []). @@ -95,7 +96,7 @@ prepare_locks([Name|Names], Deps, Locks, Unlocks) -> AtomName = binary_to_atom(Name, utf8), case lists:keyfind(AtomName, 1, Deps) of false -> - {error, {?MODULE, {unknown_dependency, Name}}}; + ?PRV_ERROR({unknown_dependency, Name}); Dep -> Source = case Dep of {_, Src} -> Src; @@ -108,9 +109,9 @@ prepare_locks([Name|Names], Deps, Locks, Unlocks) -> [{Name, Source, 0} | NewUnlocks ++ Unlocks]) end; {_, _, Level} when Level > 0 -> - {error, {?MODULE, {transitive_dependency,Name}}}; + ?PRV_ERROR({transitive_dependency, Name}); false -> - {error, {?MODULE, {unknown_dependency,Name}}} + ?PRV_ERROR({unknown_dependency, Name}) end. top_level_deps(Deps, Locks) -> diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index 142f8fd..cc33f51 100644 --- a/src/rebar_prv_xref.erl +++ b/src/rebar_prv_xref.erl @@ -10,6 +10,7 @@ format_error/1]). -include("rebar.hrl"). +-include_lib("providers/include/providers.hrl"). -define(PROVIDER, xref). -define(DEPS, [compile]). @@ -51,7 +52,7 @@ do(State) -> true -> {ok, State}; false -> - {error, {?MODULE, {xref_issues, XrefResults, QueryResults}}} + ?PRV_ERROR({xref_issues, XrefResults, QueryResults}) end. -spec format_error(any()) -> iolist(). diff --git a/test/rebar_install_deps_SUITE.erl b/test/rebar_install_deps_SUITE.erl index 28cc277..aebd3e3 100644 --- a/test/rebar_install_deps_SUITE.erl +++ b/test/rebar_install_deps_SUITE.erl @@ -8,7 +8,8 @@ all() -> [{group, git}, {group, pkg}]. groups() -> [{all, [], [flat, pick_highest_left, pick_highest_right, pick_smallest1, pick_smallest2, - circular1, circular2, circular_skip]}, + circular1, circular2, circular_skip, + fail_conflict]}, {git, [], [{group, all}]}, {pkg, [], [{group, all}]}]. @@ -33,7 +34,7 @@ init_per_testcase(Case, Config) -> {Deps, Warnings, Expect} = deps(Case), Expected = case Expect of {ok, List} -> {ok, format_expected_deps(List)}; - {error, Reason} -> {error, Reason} + Other -> Other end, DepsType = ?config(deps_type, Config), mock_warnings(), @@ -108,13 +109,36 @@ deps(circular_skip) -> {[{"B", [{"C", "2", [{"B", []}]}]}, {"C", "1", [{"D",[]}]}], [{"C","2"}], - {ok, ["B", {"C","1"}, "D"]}}. + {ok, ["B", {"C","1"}, "D"]}}; +deps(fail_conflict) -> + {[{"B", [{"C", "2", []}]}, + {"C", "1", []}], + [{"C","2"}], + rebar_abort}. +setup_project(fail_conflict, Config0, Deps) -> + DepsType = ?config(deps_type, Config0), + Config = rebar_test_utils:init_rebar_state( + Config0, + "fail_conflict_"++atom_to_list(DepsType)++"_" + ), + AppDir = ?config(apps, Config), + rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]), + TopDeps = rebar_test_utils:top_level_deps(Deps), + RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}, + {deps_error_on_conflict, true}]), + case DepsType of + git -> + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]); + pkg -> + mock_pkg_resource:mock([{pkgdeps, rebar_test_utils:flat_pkgdeps(Deps)}]) + end, + [{rebarconfig, RebarConf} | Config]; setup_project(Case, Config0, Deps) -> DepsType = ?config(deps_type, Config0), Config = rebar_test_utils:init_rebar_state( Config0, - atom_to_list(Case)++"_"++atom_to_list(DepsType)++"_" + atom_to_list(Case)++"_installdeps_"++atom_to_list(DepsType)++"_" ), AppDir = ?config(apps, Config), rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]), @@ -143,6 +167,13 @@ circular1(Config) -> run(Config). circular2(Config) -> run(Config). circular_skip(Config) -> run(Config). +fail_conflict(Config) -> + {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + rebar_test_utils:run_and_check( + Config, RebarConfig, ["install_deps"], ?config(expect, Config) + ), + check_warnings(error_calls(), ?config(warnings, Config), ?config(deps_type, Config)). + run(Config) -> {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), rebar_test_utils:run_and_check( @@ -154,6 +185,10 @@ warning_calls() -> History = meck:history(rebar_log), [{Str, Args} || {_, {rebar_log, log, [warn, Str, Args]}, _} <- History]. +error_calls() -> + History = meck:history(rebar_log), + [{Str, Args} || {_, {rebar_log, log, [error, Str, Args]}, _} <- History]. + check_warnings(_, [], _) -> ok; check_warnings(Warns, [{Name, Vsn} | Rest], Type) -> diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 8d999b4..7c52a18 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -48,15 +48,19 @@ run_and_check(Config, RebarConfig, Command, Expect) -> %% Assumes init_rebar_state has run first AppDir = ?config(apps, Config), State = ?config(state, Config), - Res = rebar3:run(rebar_state:new(State, RebarConfig, AppDir), Command), - case Expect of - {error, Reason} -> - ?assertEqual({error, Reason}, Res); - {ok, Expected} -> - {ok, _} = Res, - check_results(AppDir, Expected); - return -> - Res + try + Res = rebar3:run(rebar_state:new(State, RebarConfig, AppDir), Command), + case Expect of + {error, Reason} -> + ?assertEqual({error, Reason}, Res); + {ok, Expected} -> + {ok, _} = Res, + check_results(AppDir, Expected); + return -> + Res + end + catch + rebar_abort when Expect =:= rebar_abort -> rebar_abort end. %% @doc Creates a dummy application including: |