mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Optimize list ops and error reporting in sh/2
This commit is contained in:
parent
a9a7d7c02b
commit
d9ef6fbd53
1 changed files with 11 additions and 11 deletions
|
@ -102,8 +102,8 @@ sh(Command0, Options0) ->
|
||||||
case sh_loop(Port, OutputHandler, []) of
|
case sh_loop(Port, OutputHandler, []) of
|
||||||
{ok, _Output} = Ok ->
|
{ok, _Output} = Ok ->
|
||||||
Ok;
|
Ok;
|
||||||
{error, Rc} ->
|
{error, Err} ->
|
||||||
ErrorHandler(Command, Rc)
|
ErrorHandler(Command, Err)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% We need a bash shell to execute on windows
|
%% We need a bash shell to execute on windows
|
||||||
|
@ -182,12 +182,12 @@ expand_code_path() ->
|
||||||
|
|
||||||
expand_sh_flag(return_on_error) ->
|
expand_sh_flag(return_on_error) ->
|
||||||
{error_handler,
|
{error_handler,
|
||||||
fun(_Command, Rc) ->
|
fun(_Command, Err) ->
|
||||||
{error, Rc}
|
{error, Err}
|
||||||
end};
|
end};
|
||||||
expand_sh_flag({abort_on_error, Message}) ->
|
expand_sh_flag({abort_on_error, Message}) ->
|
||||||
{error_handler,
|
{error_handler,
|
||||||
fun(_Command, _Rc) ->
|
fun(_Command, _Err) ->
|
||||||
?ABORT(Message, [])
|
?ABORT(Message, [])
|
||||||
end};
|
end};
|
||||||
expand_sh_flag(abort_on_error) ->
|
expand_sh_flag(abort_on_error) ->
|
||||||
|
@ -197,12 +197,12 @@ expand_sh_flag(use_stdout) ->
|
||||||
{output_handler,
|
{output_handler,
|
||||||
fun(Line, Acc) ->
|
fun(Line, Acc) ->
|
||||||
?CONSOLE("~s", [Line]),
|
?CONSOLE("~s", [Line]),
|
||||||
[Acc | Line]
|
[Line | Acc]
|
||||||
end};
|
end};
|
||||||
expand_sh_flag({use_stdout, false}) ->
|
expand_sh_flag({use_stdout, false}) ->
|
||||||
{output_handler,
|
{output_handler,
|
||||||
fun(Line, Acc) ->
|
fun(Line, Acc) ->
|
||||||
[Acc | Line]
|
[Line | Acc]
|
||||||
end};
|
end};
|
||||||
expand_sh_flag({cd, _CdArg} = Cd) ->
|
expand_sh_flag({cd, _CdArg} = Cd) ->
|
||||||
{port_settings, Cd};
|
{port_settings, Cd};
|
||||||
|
@ -210,8 +210,8 @@ expand_sh_flag({env, _EnvArg} = Env) ->
|
||||||
{port_settings, Env}.
|
{port_settings, Env}.
|
||||||
|
|
||||||
-spec log_and_abort(string(), integer()) -> no_return().
|
-spec log_and_abort(string(), integer()) -> no_return().
|
||||||
log_and_abort(Command, Rc) ->
|
log_and_abort(Command, {Rc, Output}) ->
|
||||||
?ABORT("~s failed with error: ~w\n", [Command, Rc]).
|
?ABORT("~s failed with error: ~w and output:~n~s~n", [Command, Rc, Output]).
|
||||||
|
|
||||||
sh_loop(Port, Fun, Acc) ->
|
sh_loop(Port, Fun, Acc) ->
|
||||||
receive
|
receive
|
||||||
|
@ -226,9 +226,9 @@ sh_loop(Port, Fun, Acc) ->
|
||||||
{Port, {data, {noeol, Line}}} ->
|
{Port, {data, {noeol, Line}}} ->
|
||||||
sh_loop(Port, Fun, Fun(Line, Acc));
|
sh_loop(Port, Fun, Fun(Line, Acc));
|
||||||
{Port, {exit_status, 0}} ->
|
{Port, {exit_status, 0}} ->
|
||||||
{ok, lists:flatten(Acc)};
|
{ok, lists:flatten(lists:reverse(Acc))};
|
||||||
{Port, {exit_status, Rc}} ->
|
{Port, {exit_status, Rc}} ->
|
||||||
{error, Rc}
|
{error, {Rc, lists:flatten(lists:reverse(Acc))}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
beam_to_mod(Dir, Filename) ->
|
beam_to_mod(Dir, Filename) ->
|
||||||
|
|
Loading…
Reference in a new issue