diff options
author | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-06-01 00:04:01 +0200 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-06-11 19:40:59 +0200 |
commit | dff60918cbc3f7410bd47200bc82ed11bebc2a34 (patch) | |
tree | 87ad695a267c1603df14b0acb5268df5b59a2187 | |
parent | 4e64e0c675bff255011fd8f03b79997339a57555 (diff) |
Share format_errors/format_warnings functions
-rw-r--r-- | src/rebar_base_compiler.erl | 17 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 24 |
2 files changed, 22 insertions, 19 deletions
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl index 220cbd5..3939c97 100644 --- a/src/rebar_base_compiler.erl +++ b/src/rebar_base_compiler.erl @@ -28,7 +28,8 @@ -include("rebar.hrl"). --export([run/4, run/7, run/8]). +-export([run/4, run/7, run/8, + format_errors/2, format_warnings/2]). %% =================================================================== @@ -79,6 +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). + +format_warnings(Source, Warnings) -> + format_errors(Source, "Warning: ", Warnings). %% =================================================================== %% Internal functions @@ -215,3 +221,12 @@ maybe_report(_) -> report(Messages) -> lists:foreach(fun(Msg) -> io:format("~s~n", [Msg]) end, Messages). + +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]). diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 42fecc9..b3b5305 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -262,27 +262,15 @@ internal_erl_compile(Source, Config, Outdir, ErlOpts) -> {ok, _Mod} -> ok; {ok, _Mod, Ws} -> - {ok, format_errors(Source, "Warning: ", Ws)}; + {ok, rebar_base_compiler:format_warnings(Source, Ws)}; {error, Es, Ws} -> - {error, format_errors(Source, Es), - format_errors(Source, "Warning: ", Ws)} + {error, rebar_base_compiler:format_errors(Source, Es), + rebar_base_compiler:format_warnings(Source, Ws)} end; false -> skipped 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(), Config::rebar_config:config()) -> 'ok'. compile_mib(Source, Target, Config) -> @@ -322,10 +310,10 @@ compile_xrl_yrl(Source, Target, Opts, Mod) -> {ok, _} -> ok; {ok, _Mod, Ws} -> - {ok, format_errors(Source, "Warning: ", Ws)}; + {ok, rebar_base_compiler:format_warnings(Source, Ws)}; {error, Es, Ws} -> - {error, format_errors(Source, Es), - format_errors(Source, "Warning: ", Ws)} + {error, rebar_base_compiler:format_errors(Source, Es), + rebar_base_compiler:format_warnings(Source, Ws)} end; false -> skipped |