Browse Source

Merge pull request #1450 from ferd/relative-dialyzer-paths

Relative dialyzer paths
pull/1451/head
alisdair sullivan 8 years ago
committed by GitHub
parent
commit
6a1cfaf948
5 changed files with 53 additions and 34 deletions
  1. +1
    -0
      src/rebar.hrl
  2. +1
    -23
      src/rebar_base_compiler.erl
  3. +9
    -7
      src/rebar_dialyzer_format.erl
  4. +38
    -1
      src/rebar_dir.erl
  5. +4
    -3
      src/rebar_prv_dialyzer.erl

+ 1
- 0
src/rebar.hrl View File

@ -27,6 +27,7 @@
-define(REMOTE_PACKAGE_DIR, "tarballs"). -define(REMOTE_PACKAGE_DIR, "tarballs").
-define(REMOTE_REGISTRY_FILE, "registry.ets.gz"). -define(REMOTE_REGISTRY_FILE, "registry.ets.gz").
-define(LOCK_FILE, "rebar.lock"). -define(LOCK_FILE, "rebar.lock").
-define(DEFAULT_COMPILER_SOURCE_FORMAT, relative).
-define(PACKAGE_INDEX_VERSION, 3). -define(PACKAGE_INDEX_VERSION, 3).
-define(PACKAGE_TABLE, package_index). -define(PACKAGE_TABLE, package_index).

+ 1
- 23
src/rebar_base_compiler.erl View File

@ -35,7 +35,6 @@
error_tuple/4, error_tuple/4,
format_error_source/2]). format_error_source/2]).
-define(DEFAULT_COMPILER_SOURCE_FORMAT, relative).
-type desc() :: term(). -type desc() :: term().
-type loc() :: {line(), col()} | line(). -type loc() :: {line(), col()} | line().
-type line() :: integer(). -type line() :: integer().
@ -138,28 +137,7 @@ error_tuple(Source, Es, Ws, Opts) ->
-spec format_error_source(file:filename(), rebar_dict() | [{_,_}]) -> -spec format_error_source(file:filename(), rebar_dict() | [{_,_}]) ->
file:filename(). file:filename().
format_error_source(Path, 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.
%% @private takes a filename and canonicalizes its path if it is a link.
-spec resolve_linked_source(file:filename()) -> file:filename().
resolve_linked_source(Src) ->
{Dir, Base} = rebar_file_utils:split_dirname(Src),
filename:join(rebar_file_utils:resolve_link(Dir), Base).
rebar_dir:format_source_file_name(Path, Opts).
%% =================================================================== %% ===================================================================
%% Internal functions %% Internal functions

+ 9
- 7
src/rebar_dialyzer_format.erl View File

@ -16,18 +16,19 @@
-include("rebar.hrl"). -include("rebar.hrl").
-export([format_warnings/1]).
-export([format_warnings/2]).
%% Formats a list of warnings in a nice per file way. Note that we reverse %% Formats a list of warnings in a nice per file way. Note that we reverse
%% the list at the end to 'undo' the reversal by foldl %% the list at the end to 'undo' the reversal by foldl
format_warnings(Warnings) ->
{_, Res} = lists:foldl(fun format_warning_/2, {undefined, []}, Warnings),
format_warnings(Opts, Warnings) ->
Fold = fun(Warning, Acc) -> format_warning_(Opts, Warning, Acc) end,
{_, Res} = lists:foldl(Fold, {undefined, []}, Warnings),
lists:reverse(Res). lists:reverse(Res).
%% If the last seen file is and the file of this warning are the same %% If the last seen file is and the file of this warning are the same
%% we skip the file header %% we skip the file header
format_warning_(Warning = {_Tag, {File, Line}, Msg}, {File, Acc}) ->
format_warning_(_Opts, Warning = {_Tag, {File, Line}, Msg}, {File, Acc}) ->
try try
String = message_to_string(Msg), String = message_to_string(Msg),
{File, [lists:flatten(fmt("~!c~4w~!!: ~s", [Line, String])) | Acc]} {File, [lists:flatten(fmt("~!c~4w~!!: ~s", [Line, String])) | Acc]}
@ -39,8 +40,9 @@ format_warning_(Warning = {_Tag, {File, Line}, Msg}, {File, Acc}) ->
end; end;
%% With a new file detencted we also write a file header. %% With a new file detencted we also write a file header.
format_warning_(Warning = {_Tag, {File, Line}, Msg}, {_LastFile, Acc}) ->
format_warning_(Opts, Warning = {_Tag, {SrcFile, Line}, Msg}, {_LastFile, Acc}) ->
try try
File = rebar_dir:format_source_file_name(SrcFile, Opts),
Base = filename:basename(File), Base = filename:basename(File),
Dir = filename:dirname(File), Dir = filename:dirname(File),
Root = filename:rootname(Base), Root = filename:rootname(Base),
@ -49,12 +51,12 @@ format_warning_(Warning = {_Tag, {File, Line}, Msg}, {_LastFile, Acc}) ->
Base1 = fmt("~!_c~s~!!~!__~s", [Root, Ext]), Base1 = fmt("~!_c~s~!!~!__~s", [Root, Ext]),
F = fmt("~!__~s", [filename:join(Path, Base1)]), F = fmt("~!__~s", [filename:join(Path, Base1)]),
String = message_to_string(Msg), String = message_to_string(Msg),
{File, [lists:flatten(fmt("~n~s~n~!c~4w~!!: ~s", [F, Line, String])) | Acc]}
{SrcFile, [lists:flatten(fmt("~n~s~n~!c~4w~!!: ~s", [F, Line, String])) | Acc]}
catch catch
Error:Reason -> Error:Reason ->
?DEBUG("Failed to pretty format warning: ~p:~p~n~p", ?DEBUG("Failed to pretty format warning: ~p:~p~n~p",
[Error, Reason, erlang:get_stacktrace()]), [Error, Reason, erlang:get_stacktrace()]),
{File, [dialyzer:format_warning(Warning, fullpath) | Acc]}
{SrcFile, [dialyzer:format_warning(Warning, fullpath) | Acc]}
end. end.
fmt(Fmt) -> fmt(Fmt) ->

+ 38
- 1
src/rebar_dir.erl View File

@ -26,7 +26,8 @@
src_dir_opts/2, recursive/2, src_dir_opts/2, recursive/2,
extra_src_dirs/1, extra_src_dirs/2, extra_src_dirs/1, extra_src_dirs/2,
all_src_dirs/1, all_src_dirs/3, all_src_dirs/1, all_src_dirs/3,
retarget_path/2]).
retarget_path/2,
format_source_file_name/2]).
-include("rebar.hrl"). -include("rebar.hrl").
@ -334,3 +335,39 @@ retarget_path(State, Path, [App|Rest]) ->
{ok, NewPath} -> filename:join([rebar_app_info:out_dir(App), NewPath]); {ok, NewPath} -> filename:join([rebar_app_info:out_dir(App), NewPath]);
{error, badparent} -> retarget_path(State, Path, Rest) {error, badparent} -> retarget_path(State, Path, Rest)
end. end.
format_source_file_name(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_source_format_once(Other)
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.
%% @private displays a warning for the compiler source format option
%% only once
-spec warn_source_format_once(term()) -> ok.
warn_source_format_once(Format) ->
Warn = application:get_env(rebar, warn_source_format) =/= {ok, false},
application:set_env(rebar, warn_source_format, false),
case Warn of
false ->
ok;
true ->
?WARN("Invalid argument ~p for compiler_source_format - "
"assuming ~s~n", [Format, ?DEFAULT_COMPILER_SOURCE_FORMAT])
end.
%% @private takes a filename and canonicalizes its path if it is a link.
-spec resolve_linked_source(file:filename()) -> file:filename().
resolve_linked_source(Src) ->
{Dir, Base} = rebar_file_utils:split_dirname(Src),
filename:join(rebar_file_utils:resolve_link(Dir), Base).

+ 4
- 3
src/rebar_prv_dialyzer.erl View File

@ -478,7 +478,8 @@ run_dialyzer(State, Opts, Output) ->
{check_plt, false} | {check_plt, false} |
Opts], Opts],
?DEBUG("Running dialyzer with options: ~p~n", [Opts2]), ?DEBUG("Running dialyzer with options: ~p~n", [Opts2]),
Warnings = format_warnings(Output, dialyzer:run(Opts2)),
Warnings = format_warnings(rebar_state:opts(State),
Output, dialyzer:run(Opts2)),
{Warnings, State}; {Warnings, State};
false -> false ->
Opts2 = [{warnings, no_warnings()}, Opts2 = [{warnings, no_warnings()},
@ -497,8 +498,8 @@ legacy_warnings(Warnings) ->
Warnings Warnings
end. end.
format_warnings(Output, Warnings) ->
Warnings1 = rebar_dialyzer_format:format_warnings(Warnings),
format_warnings(Opts, Output, Warnings) ->
Warnings1 = rebar_dialyzer_format:format_warnings(Opts, Warnings),
console_warnings(Warnings1), console_warnings(Warnings1),
file_warnings(Output, Warnings), file_warnings(Output, Warnings),
length(Warnings). length(Warnings).

Loading…
Cancel
Save