summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2011-07-18 18:46:15 +0200
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-07-18 18:58:20 +0200
commitd9ef6fbd536225482fefef7838eec5fc2520c08e (patch)
tree6fc6444c10e6c98658781326a79b0a12d77a0a22
parenta9a7d7c02b45af1bddec4d6133e98007a364dd9c (diff)
Optimize list ops and error reporting in sh/2
-rw-r--r--src/rebar_utils.erl22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index f18621b..2d82040 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -102,8 +102,8 @@ sh(Command0, Options0) ->
case sh_loop(Port, OutputHandler, []) of
{ok, _Output} = Ok ->
Ok;
- {error, Rc} ->
- ErrorHandler(Command, Rc)
+ {error, Err} ->
+ ErrorHandler(Command, Err)
end.
%% We need a bash shell to execute on windows
@@ -182,12 +182,12 @@ expand_code_path() ->
expand_sh_flag(return_on_error) ->
{error_handler,
- fun(_Command, Rc) ->
- {error, Rc}
+ fun(_Command, Err) ->
+ {error, Err}
end};
expand_sh_flag({abort_on_error, Message}) ->
{error_handler,
- fun(_Command, _Rc) ->
+ fun(_Command, _Err) ->
?ABORT(Message, [])
end};
expand_sh_flag(abort_on_error) ->
@@ -197,12 +197,12 @@ expand_sh_flag(use_stdout) ->
{output_handler,
fun(Line, Acc) ->
?CONSOLE("~s", [Line]),
- [Acc | Line]
+ [Line | Acc]
end};
expand_sh_flag({use_stdout, false}) ->
{output_handler,
fun(Line, Acc) ->
- [Acc | Line]
+ [Line | Acc]
end};
expand_sh_flag({cd, _CdArg} = Cd) ->
{port_settings, Cd};
@@ -210,8 +210,8 @@ expand_sh_flag({env, _EnvArg} = Env) ->
{port_settings, Env}.
-spec log_and_abort(string(), integer()) -> no_return().
-log_and_abort(Command, Rc) ->
- ?ABORT("~s failed with error: ~w\n", [Command, Rc]).
+log_and_abort(Command, {Rc, Output}) ->
+ ?ABORT("~s failed with error: ~w and output:~n~s~n", [Command, Rc, Output]).
sh_loop(Port, Fun, Acc) ->
receive
@@ -226,9 +226,9 @@ sh_loop(Port, Fun, Acc) ->
{Port, {data, {noeol, Line}}} ->
sh_loop(Port, Fun, Fun(Line, Acc));
{Port, {exit_status, 0}} ->
- {ok, lists:flatten(Acc)};
+ {ok, lists:flatten(lists:reverse(Acc))};
{Port, {exit_status, Rc}} ->
- {error, Rc}
+ {error, {Rc, lists:flatten(lists:reverse(Acc))}}
end.
beam_to_mod(Dir, Filename) ->