Manually report errors/warnings with absolute path

This commit is contained in:
Tuncer Ayaz 2012-05-22 18:13:38 +02:00
parent 8d81b322ed
commit 50fbabda68
3 changed files with 52 additions and 31 deletions

View file

@ -116,23 +116,29 @@ compile(Source, Config, CompileFn) ->
ok -> ok ->
ok; ok;
skipped -> skipped ->
skipped skipped;
Error ->
Error
end. end.
compile_each([], _Config, _CompileFn) -> compile_each([], _Config, _CompileFn) ->
ok; ok;
compile_each([Source | Rest], Config, CompileFn) -> compile_each([Source | Rest], Config, CompileFn) ->
case compile(Source, Config, CompileFn) of case compile(Source, Config, CompileFn) of
ok -> ok ->
?CONSOLE("Compiled ~s\n", [Source]); ?CONSOLE("Compiled ~s\n", [Source]);
{ok, Warnings} ->
report(Warnings),
?CONSOLE("Compiled ~s\n", [Source]);
skipped -> skipped ->
?INFO("Skipped ~s\n", [Source]) ?INFO("Skipped ~s\n", [Source]);
Error ->
maybe_report(Error),
?DEBUG("Compilation failed: ~p\n", [Error]),
?ABORT
end, end,
compile_each(Rest, Config, CompileFn). compile_each(Rest, Config, CompileFn).
compile_queue([], []) -> compile_queue([], []) ->
ok; ok;
compile_queue(Pids, Targets) -> compile_queue(Pids, Targets) ->
@ -148,9 +154,15 @@ compile_queue(Pids, Targets) ->
end; end;
{fail, Error} -> {fail, Error} ->
maybe_report(Error),
?DEBUG("Worker compilation failed: ~p\n", [Error]), ?DEBUG("Worker compilation failed: ~p\n", [Error]),
?ABORT; ?ABORT;
{compiled, Source, Warnings} ->
report(Warnings),
?CONSOLE("Compiled ~s\n", [Source]),
compile_queue(Pids, Targets);
{compiled, Source} -> {compiled, Source} ->
?CONSOLE("Compiled ~s\n", [Source]), ?CONSOLE("Compiled ~s\n", [Source]),
compile_queue(Pids, Targets); compile_queue(Pids, Targets);
@ -174,6 +186,9 @@ compile_worker(QueuePid, Config, CompileFn) ->
receive receive
{compile, Source} -> {compile, Source} ->
case catch(compile(Source, Config, CompileFn)) of case catch(compile(Source, Config, CompileFn)) of
{ok, Ws} ->
QueuePid ! {compiled, Source, Ws},
compile_worker(QueuePid, Config, CompileFn);
ok -> ok ->
QueuePid ! {compiled, Source}, QueuePid ! {compiled, Source},
compile_worker(QueuePid, Config, CompileFn); compile_worker(QueuePid, Config, CompileFn);
@ -189,3 +204,14 @@ compile_worker(QueuePid, Config, CompileFn) ->
empty -> empty ->
ok ok
end. end.
maybe_report([{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}]) ->
maybe_report(ErrorsAndWarnings);
maybe_report({error, Es, Ws}) ->
report(Es),
report(Ws);
maybe_report(_) ->
ok.
report(Messages) ->
lists:foreach(fun(Msg) -> io:format("~s~n", [Msg]) end, Messages).

View file

@ -119,17 +119,6 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
DirSet; DirSet;
true -> true ->
AbsDir = filename:absname(Dir),
ShouldPrintDir = not (is_skip_dir(Dir)
orelse processing_base_dir(Dir)),
case ShouldPrintDir of
true ->
?CONSOLE("==> Entering directory `~s'\n", [AbsDir]);
_ ->
ok
end,
ok = file:set_cwd(Dir), ok = file:set_cwd(Dir),
Config = maybe_load_local_config(Dir, ParentConfig), Config = maybe_load_local_config(Dir, ParentConfig),
@ -144,17 +133,8 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
%% to process this dir. %% to process this dir.
{ok, AvailModuleSets} = application:get_env(rebar, modules), {ok, AvailModuleSets} = application:get_env(rebar, modules),
ModuleSet = choose_module_set(AvailModuleSets, Dir), ModuleSet = choose_module_set(AvailModuleSets, Dir),
Res = maybe_process_dir(ModuleSet, Config, CurrentCodePath, maybe_process_dir(ModuleSet, Config, CurrentCodePath,
Dir, Command, DirSet), Dir, Command, DirSet)
case ShouldPrintDir of
true ->
?CONSOLE("==> Leaving directory `~s'\n", [AbsDir]);
false ->
ok
end,
Res
end. end.
maybe_process_dir({[], undefined}=ModuleSet, Config, CurrentCodePath, maybe_process_dir({[], undefined}=ModuleSet, Config, CurrentCodePath,

View file

@ -257,17 +257,32 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) ->
case needs_compile(Source, Target, Hrls) of case needs_compile(Source, Target, Hrls) of
true -> true ->
Opts = [{outdir, filename:dirname(Target)}] ++ Opts = [{outdir, filename:dirname(Target)}] ++
ErlOpts ++ [{i, "include"}, report], ErlOpts ++ [{i, "include"}, return],
case compile:file(Source, Opts) of case compile:file(Source, Opts) of
{ok, _} -> {ok, _Mod} ->
ok; ok;
_ -> {ok, _Mod, Ws} ->
?ABORT {ok, format_errors(Source, "Warning: ", Ws)};
{error, Es, Ws} ->
{error, format_errors(Source, Es),
format_errors(Source, "Warning: ", Ws)}
end; end;
false -> false ->
skipped skipped
end. end.
format_errors(Source, Errors) ->
format_errors(Source, "", Errors).
format_errors(Source, Extra, Errors) ->
AbsSource = filename:absname(Source),
[lists:append([format_error(AbsSource, Extra, Desc) || Desc <- Descs])
|| {_, Descs} <- Errors].
format_error(AbsSource, Extra, {Line, Mod, Desc}) ->
ErrorDesc = Mod:format_error(Desc),
?FMT("~s:~b: ~s~s", [AbsSource, Line, Extra, ErrorDesc]).
-spec compile_mib(Source::file:filename(), Target::file:filename(), -spec compile_mib(Source::file:filename(), Target::file:filename(),
Config::rebar_config:config()) -> 'ok'. Config::rebar_config:config()) -> 'ok'.
compile_mib(Source, Target, Config) -> compile_mib(Source, Target, Config) ->