summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_base_compiler.erl31
-rw-r--r--src/rebar_erlc_compiler.erl46
2 files changed, 39 insertions, 38 deletions
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index 2f67f25..6b8c7ca 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -32,7 +32,11 @@
run/7,
run/8,
ok_tuple/2,
- error_tuple/4]).
+ error_tuple/4,
+ format_error_source/2]).
+
+-define(DEFAULT_COMPILER_SOURCE_FORMAT, relative).
+
%% ===================================================================
%% Public API
@@ -76,6 +80,28 @@ error_tuple(Source, Es, Ws, Opts) ->
{error, format_errors(Source, Es),
format_warnings(Source, Ws, Opts)}.
+format_error_source(Path, Opts) ->
+ Type = case rebar_opts:get(Opts, compiler_source_format,
+ ?DEFAULT_COMPILER_SOURCE_FORMAT) of
+ V when V == absolute; V == relative; V == build ->
+ V;
+ Other ->
+ ?WARN("Invalid argument ~p for compiler_source_format - "
+ "assuming ~s~n", [Other, ?DEFAULT_COMPILER_SOURCE_FORMAT]),
+ ?DEFAULT_COMPILER_SOURCE_FORMAT
+ end,
+ case Type of
+ absolute -> resolve_linked_source(Path);
+ build -> Path;
+ relative ->
+ Cwd = rebar_dir:get_cwd(),
+ rebar_dir:make_relative_path(resolve_linked_source(Path), Cwd)
+ end.
+
+resolve_linked_source(Src) ->
+ {Dir, Base} = rebar_file_utils:split_dirname(Src),
+ filename:join(rebar_file_utils:resolve_link(Dir), Base).
+
%% ===================================================================
%% Internal functions
%% ===================================================================
@@ -114,7 +140,8 @@ compile_each([Source | Rest], Config, CompileFn) ->
skipped ->
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]);
Error ->
- ?ERROR("Compiling ~s failed", [Source]),
+ NewSource = format_error_source(Source, Config),
+ ?ERROR("Compiling ~s failed", [NewSource]),
maybe_report(Error),
?DEBUG("Compilation failed: ~p", [Error]),
?FAIL
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index a2eb2e2..7875449 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -54,9 +54,6 @@
-define(DEFAULT_OUTDIR, "ebin").
-define(RE_PREFIX, "^[^._]").
--type compiler_source_format() :: absolute | relative | build.
--define(DEFAULT_COMPILER_SOURCE_FORMAT, build).
-
%% ===================================================================
%% Public API
%% ===================================================================
@@ -511,43 +508,20 @@ internal_erl_compile(Opts, Dir, Module, OutDir, ErlOpts) ->
{ok, _Mod} ->
ok;
{ok, _Mod, Ws} ->
- rebar_base_compiler:ok_tuple(Module, Ws);
+ FormattedWs = format_error_sources(Ws, Opts),
+ rebar_base_compiler:ok_tuple(Module, FormattedWs);
{error, Es, Ws} ->
- error_tuple(Module, Es, Ws, AllOpts, source_format(Opts))
+ error_tuple(Module, Es, Ws, AllOpts, Opts)
end.
--spec source_format(rebar_dict()) -> compiler_source_format().
-source_format(Opts) ->
- case rebar_opts:get(Opts, compiler_source_format,
- ?DEFAULT_COMPILER_SOURCE_FORMAT) of
- V when V == absolute;
- V == relative;
- V == build -> V;
- Other ->
- ?WARN("Invalid argument ~p for compiler_source_format - "
- "assuming ~s~n", [Other, ?DEFAULT_COMPILER_SOURCE_FORMAT]),
- ?DEFAULT_COMPILER_SOURCE_FORMAT
- end.
+error_tuple(Module, Es, Ws, AllOpts, Opts) ->
+ FormattedEs = format_error_sources(Es, Opts),
+ FormattedWs = format_error_sources(Ws, Opts),
+ rebar_base_compiler:error_tuple(Module, FormattedEs, FormattedWs, AllOpts).
-error_tuple(Module, Es, Ws, Opts, SourceFormat) ->
- Cwd = rebar_dir:get_cwd(),
- FormattedEs = format_error_sources(Es, SourceFormat, Cwd),
- FormattedWs = format_error_sources(Ws, SourceFormat, Cwd),
- rebar_base_compiler:error_tuple(Module, FormattedEs, FormattedWs, Opts).
-
-format_error_sources(Es, Format, Cwd) ->
- [{format_error_source(Src, Format, Cwd), Desc} || {Src, Desc} <- Es].
-
-format_error_source(Src, absolute, _Cwd) ->
- resolve_linked_source(Src);
-format_error_source(Src, relative, Cwd) ->
- rebar_dir:make_relative_path(resolve_linked_source(Src), Cwd);
-format_error_source(Src, build, _Cwd) ->
- Src.
-
-resolve_linked_source(Src) ->
- {Dir, Base} = rebar_file_utils:split_dirname(Src),
- filename:join(rebar_file_utils:resolve_link(Dir), Base).
+format_error_sources(Es, Opts) ->
+ [{rebar_base_compiler:format_error_source(Src, Opts), Desc}
+ || {Src, Desc} <- Es].
target_base(OutDir, Source) ->
filename:join(OutDir, filename:basename(Source, ".erl")).