From d9ef6fbd536225482fefef7838eec5fc2520c08e Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 18 Jul 2011 18:46:15 +0200 Subject: [PATCH] Optimize list ops and error reporting in sh/2 --- src/rebar_utils.erl | 22 +++++++++++----------- 1 file 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) ->