From 97c9fdf31acad6c38a02e6433787749d7ac143ab Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sat, 11 Jan 2014 22:10:50 +0100 Subject: Fix basho/rebar#388 If the syntax error is in a .hrl file, then the reported error message is not as useful because it's not clear which .erl file was being compiled. We can fix that easily by first printing what source file was being processed. We don't change the actual error message, so this will still work with your editor of choice for jumping to the right line. Before ------ Success: Compiled src/foo.erl Failure: include/foo.hrl:10: syntax error [...] After ----- Success: Compiled src/foo.erl Failure: Compiling src/foo.erl failed: include/foo.hrl:10: syntax error [...] --- src/rebar_base_compiler.erl | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl index a0dec30..2050771 100644 --- a/src/rebar_base_compiler.erl +++ b/src/rebar_base_compiler.erl @@ -49,7 +49,7 @@ run(Config, FirstFiles, RestFiles, CompileFn) -> Jobs = rebar:get_jobs(Config), ?DEBUG("Starting ~B compile worker(s)~n", [Jobs]), Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)], - compile_queue(Pids, RestFiles) + compile_queue(Config, Pids, RestFiles) end. run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, @@ -139,27 +139,31 @@ compile_each([Source | Rest], Config, CompileFn) -> skipped -> ?INFO("Skipped ~s\n", [Source]); Error -> + ?CONSOLE("Compiling ~s failed:\n", + [maybe_absname(Config, Source)]), maybe_report(Error), ?DEBUG("Compilation failed: ~p\n", [Error]), ?FAIL end, compile_each(Rest, Config, CompileFn). -compile_queue([], []) -> +compile_queue(_Config, [], []) -> ok; -compile_queue(Pids, Targets) -> +compile_queue(Config, Pids, Targets) -> receive {next, Worker} -> case Targets of [] -> Worker ! empty, - compile_queue(Pids, Targets); + compile_queue(Config, Pids, Targets); [Source | Rest] -> Worker ! {compile, Source}, - compile_queue(Pids, Rest) + compile_queue(Config, Pids, Rest) end; - {fail, Error} -> + {fail, [_, {source, Source}}=Error] -> + ?CONSOLE("Compiling ~s failed:\n", + [maybe_absname(Config, Source)]), maybe_report(Error), ?DEBUG("Worker compilation failed: ~p\n", [Error]), ?FAIL; @@ -167,20 +171,20 @@ compile_queue(Pids, Targets) -> {compiled, Source, Warnings} -> report(Warnings), ?CONSOLE("Compiled ~s\n", [Source]), - compile_queue(Pids, Targets); + compile_queue(Config, Pids, Targets); {compiled, Source} -> ?CONSOLE("Compiled ~s\n", [Source]), - compile_queue(Pids, Targets); + compile_queue(Config, Pids, Targets); {skipped, Source} -> ?INFO("Skipped ~s\n", [Source]), - compile_queue(Pids, Targets); + compile_queue(Config, Pids, Targets); {'DOWN', Mref, _, Pid, normal} -> ?DEBUG("Worker exited cleanly\n", []), Pids2 = lists:delete({Pid, Mref}, Pids), - compile_queue(Pids2, Targets); + compile_queue(Config, Pids2, Targets); {'DOWN', _Mref, _, _Pid, Info} -> ?DEBUG("Worker failed: ~p\n", [Info]), @@ -239,12 +243,7 @@ report(Messages) -> format_errors(Config, _MainSource, Extra, Errors) -> [begin - AbsSource = case rebar_utils:processing_base_dir(Config) of - true -> - Source; - false -> - filename:absname(Source) - end, + AbsSource = maybe_absname(Config, Source), [format_error(AbsSource, Extra, Desc) || Desc <- Descs] end || {Source, Descs} <- Errors]. @@ -258,3 +257,11 @@ format_error(AbsSource, Extra, {Line, Mod, Desc}) -> format_error(AbsSource, Extra, {Mod, Desc}) -> ErrorDesc = Mod:format_error(Desc), ?FMT("~s: ~s~s~n", [AbsSource, Extra, ErrorDesc]). + +maybe_absname(Config, Filename) -> + case rebar_utils:processing_base_dir(Config) of + true -> + Filename; + false -> + filename:absname(Filename) + end. -- cgit v1.1 From 2f2e7c48894f58c4268d8191f42fad806c419b4b Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sat, 11 Jan 2014 22:21:31 +0100 Subject: rebar_base_compiler: replace fixed size list with a tuple --- src/rebar_base_compiler.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl index 2050771..1957070 100644 --- a/src/rebar_base_compiler.erl +++ b/src/rebar_base_compiler.erl @@ -161,7 +161,7 @@ compile_queue(Config, Pids, Targets) -> compile_queue(Config, Pids, Rest) end; - {fail, [_, {source, Source}}=Error] -> + {fail, {_, {source, Source}}=Error} -> ?CONSOLE("Compiling ~s failed:\n", [maybe_absname(Config, Source)]), maybe_report(Error), @@ -206,8 +206,7 @@ compile_worker(QueuePid, Config, CompileFn) -> QueuePid ! {skipped, Source}, compile_worker(QueuePid, Config, CompileFn); Error -> - QueuePid ! {fail, [{error, Error}, - {source, Source}]}, + QueuePid ! {fail, {{error, Error}, {source, Source}}}, ok end; @@ -228,7 +227,7 @@ format_warnings(Config, Source, Warnings, Opts) -> end, format_errors(Config, Source, Prefix, Warnings). -maybe_report([{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}]) -> +maybe_report({{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}}) -> maybe_report(ErrorsAndWarnings); maybe_report([{error, E}, {source, S}]) -> report(["unexpected error compiling " ++ S, io_lib:fwrite("~n~p~n", [E])]); -- cgit v1.1