mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Refactor shared error reporting code
This commit is contained in:
parent
0716cf708c
commit
8a2274b8b4
3 changed files with 24 additions and 21 deletions
|
@ -29,7 +29,7 @@
|
|||
-include("rebar.hrl").
|
||||
|
||||
-export([run/4, run/7, run/8,
|
||||
format_errors/2, format_warnings/2, format_warnings/3]).
|
||||
ok_tuple/2, error_tuple/4]).
|
||||
|
||||
|
||||
%% ===================================================================
|
||||
|
@ -80,18 +80,11 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
|
|||
simple_compile_wrapper(S, Target, Compile3Fn, C, CheckLastMod)
|
||||
end).
|
||||
|
||||
format_errors(Source, Errors) ->
|
||||
format_errors(Source, "", Errors).
|
||||
ok_tuple(Source, Ws) ->
|
||||
{ok, format_warnings(Source, Ws)}.
|
||||
|
||||
format_warnings(Source, Warnings) ->
|
||||
format_warnings(Source, Warnings, []).
|
||||
|
||||
format_warnings(Source, Warnings, Opts) ->
|
||||
Prefix = case lists:member(warnings_as_errors, Opts) of
|
||||
true -> "";
|
||||
false -> "Warning: "
|
||||
end,
|
||||
format_errors(Source, Prefix, Warnings).
|
||||
error_tuple(Source, Es, Ws, Opts) ->
|
||||
{error, format_errors(Source, Es), format_warnings(Source, Ws, Opts)}.
|
||||
|
||||
%% ===================================================================
|
||||
%% Internal functions
|
||||
|
@ -218,6 +211,19 @@ compile_worker(QueuePid, Config, CompileFn) ->
|
|||
ok
|
||||
end.
|
||||
|
||||
format_errors(Source, Errors) ->
|
||||
format_errors(Source, "", Errors).
|
||||
|
||||
format_warnings(Source, Warnings) ->
|
||||
format_warnings(Source, Warnings, []).
|
||||
|
||||
format_warnings(Source, Warnings, Opts) ->
|
||||
Prefix = case lists:member(warnings_as_errors, Opts) of
|
||||
true -> "";
|
||||
false -> "Warning: "
|
||||
end,
|
||||
format_errors(Source, Prefix, Warnings).
|
||||
|
||||
maybe_report([{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}]) ->
|
||||
maybe_report(ErrorsAndWarnings);
|
||||
maybe_report({error, Es, Ws}) ->
|
||||
|
|
|
@ -262,10 +262,9 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
|
|||
{ok, _Mod} ->
|
||||
ok;
|
||||
{ok, _Mod, Ws} ->
|
||||
{ok, rebar_base_compiler:format_warnings(Source, Ws)};
|
||||
rebar_base_compiler:ok_tuple(Source, Ws);
|
||||
{error, Es, Ws} ->
|
||||
{error, rebar_base_compiler:format_errors(Source, Es),
|
||||
rebar_base_compiler:format_warnings(Source, Ws, Opts)}
|
||||
rebar_base_compiler:error_tuple(Source, Es, Ws, Opts)
|
||||
end;
|
||||
false ->
|
||||
skipped
|
||||
|
@ -310,10 +309,9 @@ compile_xrl_yrl(Source, Target, Opts, Mod) ->
|
|||
{ok, _} ->
|
||||
ok;
|
||||
{ok, _Mod, Ws} ->
|
||||
{ok, rebar_base_compiler:format_warnings(Source, Ws)};
|
||||
rebar_base_compiler:ok_tuple(Source, Ws);
|
||||
{error, Es, Ws} ->
|
||||
{error, rebar_base_compiler:format_errors(Source, Es),
|
||||
rebar_base_compiler:format_warnings(Source, Ws, Opts)}
|
||||
rebar_base_compiler:error_tuple(Source, Es, Ws, Opts)
|
||||
end;
|
||||
false ->
|
||||
skipped
|
||||
|
|
|
@ -63,10 +63,9 @@ compile_lfe(Source, _Target, Config) ->
|
|||
++ rebar_config:get_list(Config, erl_opts, []),
|
||||
case lfe_comp:file(Source, Opts) of
|
||||
{ok, _Mod, Ws} ->
|
||||
{ok, rebar_base_compiler:format_warnings(Source, Ws)};
|
||||
rebar_base_compiler:ok_tuple(Source, Ws);
|
||||
{error, Es, Ws} ->
|
||||
{error, rebar_base_compiler:format_errors(Source, Es),
|
||||
rebar_base_compiler:format_warnings(Source, Ws, Opts)};
|
||||
rebar_base_compiler:error_tuple(Source, Es, Ws, Opts);
|
||||
_ ->
|
||||
?ABORT
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue