summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar3.erl6
-rw-r--r--src/rebar_core.erl20
-rw-r--r--src/rebar_provider.erl27
-rw-r--r--src/rebar_prv_app_discovery.erl2
-rw-r--r--src/rebar_prv_compile.erl2
-rw-r--r--src/rebar_prv_deps.erl2
-rw-r--r--src/rebar_prv_do.erl2
-rw-r--r--src/rebar_prv_help.erl2
-rw-r--r--src/rebar_prv_install_deps.erl11
-rw-r--r--src/rebar_prv_lock.erl2
-rw-r--r--src/rebar_prv_new.erl2
-rw-r--r--src/rebar_prv_packages.erl2
-rw-r--r--src/rebar_prv_release.erl2
-rw-r--r--src/rebar_prv_shell.erl2
-rw-r--r--src/rebar_prv_tar.erl2
-rw-r--r--src/rebar_prv_update.erl18
-rw-r--r--src/rebar_prv_version.erl2
-rw-r--r--src/rebar_state.erl8
18 files changed, 67 insertions, 47 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index ba76f80..7c85f26 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -48,6 +48,9 @@ main(Args) ->
ok;
rebar_abort ->
rebar_utils:delayed_halt(1);
+ {error, Error} ->
+ ?ERROR(Error, []),
+ rebar_utils:delayed_halt(1);
Error ->
%% Nothing should percolate up from rebar_core;
%% Dump this error to console
@@ -146,8 +149,7 @@ run_aux(State, Args) ->
State4 = rebar_state:create_logic_providers(Providers++PluginProviders, State3),
Task = rebar_state:get(State4, task, "help"),
- rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)),
- ok.
+ rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)).
%%
%% Parse command line arguments using getopt and also filtering out any
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index ba77dd8..9f2b168 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -31,17 +31,25 @@
-include("rebar.hrl").
+-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}.
process_command(State, Command) ->
%% ? rebar_prv_install_deps:setup_env(State),
TargetProviders = rebar_provider:get_target_providers(Command, State),
+ do(TargetProviders, State).
- lists:foldl(fun(TargetProvider, Conf) ->
- Provider = rebar_provider:get_provider(TargetProvider
- ,rebar_state:providers(Conf)),
- {ok, Conf1} = rebar_provider:do(Provider, Conf),
- Conf1
- end, State, TargetProviders).
+-spec do([atom()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do([], State) ->
+ {ok, State};
+do([ProviderName | Rest], State) ->
+ Provider = rebar_provider:get_provider(ProviderName
+ ,rebar_state:providers(State)),
+ case rebar_provider:do(Provider, State) of
+ {ok, State1} ->
+ do(Rest, State1);
+ {error, Error} ->
+ {error, Error}
+ end.
update_code_path(State) ->
true = rebar_utils:expand_code_path(),
diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl
index 872c2e1..7d78e3b 100644
--- a/src/rebar_provider.erl
+++ b/src/rebar_provider.erl
@@ -23,7 +23,7 @@
-type provider_name() :: atom().
-callback init(rebar_state:t()) -> {ok, rebar_state:t()}.
--callback do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-callback do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
%%%===================================================================
%%% API
@@ -59,20 +59,21 @@ create(Attrs) ->
%%
%% @param Provider the provider object
%% @param State the current state of the system
--spec do(Provider::t(), rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(Provider::t(), rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(Provider, State) ->
{PreHooks, PostHooks} = rebar_state:hooks(State, Provider#provider.name),
- {ok, State1} = run_hook_plugins(PreHooks, State),
- {ok, State2} = (Provider#provider.provider_impl):do(State1),
- run_hook_plugins(PostHooks, State2).
-
--spec run_hook_plugins([t()], rebar_state:t()) -> {ok, rebar_state:t()}.
-run_hook_plugins(Hooks, State) ->
- State1 = lists:foldl(fun(Hook, StateAcc) ->
- {ok, StateAcc1} = rebar_provider:do(Hook, StateAcc),
- StateAcc1
- end, State, Hooks),
- {ok, State1}.
+ run_all([PreHooks++Provider | PostHooks], State).
+
+-spec run_all([t()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+run_all([], State) ->
+ {ok, State};
+run_all([Provider | Rest], State) ->
+ case (Provider#provider.provider_impl):do(State) of
+ {ok, State1} ->
+ run_all(Rest, State1);
+ {error, Error} ->
+ {error, Error}
+ end.
%%% @doc get the name of the module that implements the provider
%%% @param Provider the provider object
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index 897a38d..630f232 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -29,7 +29,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
State1 = rebar_app_discover:do(State, LibDirs),
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 11ee97a..8ec0560 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -27,7 +27,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
ProjectApps = rebar_state:project_apps(State),
Deps = rebar_state:get(State, deps_to_build, []),
diff --git a/src/rebar_prv_deps.erl b/src/rebar_prv_deps.erl
index 111f32f..4612c52 100644
--- a/src/rebar_prv_deps.erl
+++ b/src/rebar_prv_deps.erl
@@ -22,7 +22,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{ok, State}.
diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl
index 435db6f..7216813 100644
--- a/src/rebar_prv_do.erl
+++ b/src/rebar_prv_do.erl
@@ -29,7 +29,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
Tasks = args_to_tasks(rebar_state:command_args(State)),
State1 = lists:foldl(fun(TaskArgs, StateAcc) ->
diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl
index e9d89ca..efc9c3f 100644
--- a/src/rebar_prv_help.erl
+++ b/src/rebar_prv_help.erl
@@ -29,7 +29,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
help(State),
{ok, State}.
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 8071382..0092eaa 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -64,7 +64,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
ProjectApps = rebar_state:project_apps(State),
{ok, State1} = case rebar_state:get(State, locks, []) of
@@ -123,9 +123,9 @@ handle_deps(State, Deps, Update) ->
end, S)
end,
- AllDeps = lists:keymerge(2, lists:keymerge(2
- ,rebar_state:src_apps(State2)
- ,Solved), SrcDeps),
+ AllDeps = lists:ukeymerge(2
+ ,lists:ukeysort(2, rebar_state:src_apps(State2))
+ ,lists:ukeysort(2, Solved)),
%% Sort all apps to build order
State3 = rebar_state:set(State2, all_deps, AllDeps),
@@ -191,7 +191,8 @@ update_src_deps(Level, State, Update) ->
,NewBinaryDeps++BinaryDepsAcc
,rebar_state:src_apps(StateAcc, AppInfo2)};
false ->
- {SrcDepsAcc, BinaryDepsAcc, State}
+ AppInfo1 = rebar_app_info:dep_level(AppInfo, Level),
+ {SrcDepsAcc, BinaryDepsAcc, rebar_state:src_apps(StateAcc, AppInfo1)}
end
end
end, {[], rebar_state:binary_deps(State), State}, SrcDeps) of
diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl
index 441c46d..2265265 100644
--- a/src/rebar_prv_lock.erl
+++ b/src/rebar_prv_lock.erl
@@ -26,7 +26,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
case rebar_state:get(State, locks, []) of
[] ->
diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl
index a3182fd..1c796b6 100644
--- a/src/rebar_prv_new.erl
+++ b/src/rebar_prv_new.erl
@@ -26,7 +26,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
case rebar_state:command_args(State) of
[TemplateName] ->
diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl
index 79c1cd2..3349287 100644
--- a/src/rebar_prv_packages.erl
+++ b/src/rebar_prv_packages.erl
@@ -22,7 +22,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{Packages, _Graph} = rebar_packages:get_packages(State),
print_packages(Packages),
diff --git a/src/rebar_prv_release.erl b/src/rebar_prv_release.erl
index d724490..61c4990 100644
--- a/src/rebar_prv_release.erl
+++ b/src/rebar_prv_release.erl
@@ -29,7 +29,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(Config) ->
relx:main(["release"]),
{ok, Config}.
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index bf37ddf..4bd0886 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -54,7 +54,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(Config) ->
shell(),
{ok, Config}.
diff --git a/src/rebar_prv_tar.erl b/src/rebar_prv_tar.erl
index c40c8df..8e7fb69 100644
--- a/src/rebar_prv_tar.erl
+++ b/src/rebar_prv_tar.erl
@@ -29,7 +29,7 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
relx:main(["release tar"]),
{ok, State}.
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index 5180d4a..c885167 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -29,17 +29,21 @@ init(State) ->
opts = []}),
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
case rebar_state:command_args(State) of
[Name] ->
- ?ERROR("Updating ~s~n", [Name]),
+ ?INFO("Updating ~s~n", [Name]),
Locks = rebar_state:get(State, locks, []),
- {_, _, _, Level} = lists:keyfind(ec_cnv:to_binary(Name), 1, Locks),
- Deps = rebar_state:get(State, deps),
- Dep = lists:keyfind(list_to_atom(Name), 1, Deps),
- rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}),
- {ok, State};
+ case lists:keyfind(ec_cnv:to_binary(Name), 1, Locks) of
+ {_, _, _, Level} ->
+ Deps = rebar_state:get(State, deps),
+ Dep = lists:keyfind(list_to_atom(Name), 1, Deps),
+ rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}),
+ {ok, State};
+ false ->
+ {error, io_lib:format("No such dependency ~s~n", [Name])}
+ end;
[] ->
?INFO("Updating package index...~n", []),
Url = url(State),
diff --git a/src/rebar_prv_version.erl b/src/rebar_prv_version.erl
index 6969e62..e88bf39 100644
--- a/src/rebar_prv_version.erl
+++ b/src/rebar_prv_version.erl
@@ -30,7 +30,7 @@ init(State) ->
{ok, State1}.
--spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
rebar3:version(),
{ok, State}.
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 58d535a..b9ebd70 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -111,7 +111,9 @@ src_deps(#state_t{src_deps=SrcDeps}) ->
src_deps(State=#state_t{src_deps=SrcDeps}, NewSrcDeps) when is_list(SrcDeps) ->
State#state_t{src_deps=NewSrcDeps};
src_deps(State=#state_t{src_deps=SrcDeps}, SrcDep) ->
- State#state_t{src_deps=[SrcDep | SrcDeps]}.
+ Name = rebar_app_info:name(SrcDep),
+ NewSrcDeps = lists:keystore(Name, 2, SrcDeps, SrcDep),
+ State#state_t{src_deps=NewSrcDeps}.
src_apps(#state_t{src_apps=SrcApps}) ->
SrcApps.
@@ -119,7 +121,9 @@ src_apps(#state_t{src_apps=SrcApps}) ->
src_apps(State=#state_t{src_apps=_SrcApps}, NewSrcApps) when is_list(NewSrcApps) ->
State#state_t{src_apps=NewSrcApps};
src_apps(State=#state_t{src_apps=SrcApps}, NewSrcApp) ->
- State#state_t{src_apps=[NewSrcApp | SrcApps]}.
+ Name = rebar_app_info:name(NewSrcApp),
+ NewSrcApps = lists:keystore(Name, 2, SrcApps, NewSrcApp),
+ State#state_t{src_apps=NewSrcApps}.
project_apps(#state_t{project_apps=Apps}) ->
Apps.