mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Abort if xref emits warnings
This commit is contained in:
parent
d7f5016920
commit
862ae1f192
1 changed files with 26 additions and 21 deletions
|
@ -61,54 +61,59 @@ xref(Config, _) ->
|
||||||
undefined_function_calls]),
|
undefined_function_calls]),
|
||||||
|
|
||||||
%% Look for exports that are unused by anything
|
%% Look for exports that are unused by anything
|
||||||
case lists:member(exports_not_used, XrefChecks) of
|
ExportsNoWarn =
|
||||||
true ->
|
case lists:member(exports_not_used, XrefChecks) of
|
||||||
check_exports_not_used(Config);
|
true ->
|
||||||
false ->
|
check_exports_not_used();
|
||||||
ok
|
false ->
|
||||||
end,
|
true
|
||||||
|
end,
|
||||||
|
|
||||||
%% Look for calls to undefined functions
|
%% Look for calls to undefined functions
|
||||||
case lists:member(undefined_function_calls, XrefChecks) of
|
UndefNoWarn =
|
||||||
true ->
|
case lists:member(undefined_function_calls, XrefChecks) of
|
||||||
check_undefined_function_calls(Config);
|
true ->
|
||||||
false ->
|
check_undefined_function_calls();
|
||||||
ok
|
false ->
|
||||||
end,
|
true
|
||||||
|
end,
|
||||||
%% Restore the original code path
|
%% Restore the original code path
|
||||||
true = code:set_path(OrigPath),
|
true = code:set_path(OrigPath),
|
||||||
|
|
||||||
%% Stop xref
|
%% Stop xref
|
||||||
stopped = xref:stop(xref),
|
stopped = xref:stop(xref),
|
||||||
|
|
||||||
ok.
|
case lists:all(fun(NoWarn) -> NoWarn end, [ExportsNoWarn, UndefNoWarn]) of
|
||||||
|
true ->
|
||||||
|
ok;
|
||||||
|
false ->
|
||||||
|
?FAIL
|
||||||
|
end.
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
check_exports_not_used(_Config) ->
|
check_exports_not_used() ->
|
||||||
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
|
{ok, UnusedExports0} = xref:analyze(xref, exports_not_used),
|
||||||
UnusedExports = filter_away_ignored(UnusedExports0),
|
UnusedExports = filter_away_ignored(UnusedExports0),
|
||||||
|
|
||||||
%% Report all the unused functions
|
%% Report all the unused functions
|
||||||
display_mfas(UnusedExports, "is unused export (Xref)"),
|
display_mfas(UnusedExports, "is unused export (Xref)"),
|
||||||
ok.
|
UnusedExports =:= [].
|
||||||
|
|
||||||
check_undefined_function_calls(_Config) ->
|
check_undefined_function_calls() ->
|
||||||
{ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls),
|
{ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls),
|
||||||
UndefinedCalls =
|
UndefinedCalls =
|
||||||
[{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)} ||
|
[{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)}
|
||||||
{Caller, Target} <- UndefinedCalls0],
|
|| {Caller, Target} <- UndefinedCalls0],
|
||||||
|
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({{Source, Line}, FunStr, Target}) ->
|
fun({{Source, Line}, FunStr, Target}) ->
|
||||||
?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n",
|
?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n",
|
||||||
[Source, Line, FunStr, Target])
|
[Source, Line, FunStr, Target])
|
||||||
end, UndefinedCalls),
|
end, UndefinedCalls),
|
||||||
ok.
|
UndefinedCalls =:= [].
|
||||||
|
|
||||||
|
|
||||||
code_path() ->
|
code_path() ->
|
||||||
[P || P <- code:get_path(),
|
[P || P <- code:get_path(),
|
||||||
|
|
Loading…
Reference in a new issue