summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-19 10:58:27 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2010-08-19 10:58:27 +0100
commitf8fd96b082fc72a25ec19b1756e1eeb4247b0cad (patch)
tree1513640820f7bdb8a128522636f6317f40d30423
parent31b148634e10d34a3774ee028c4d86d01101b2dc (diff)
downloadrabbitmq-server-f8fd96b082fc72a25ec19b1756e1eeb4247b0cad.tar.gz
added xref check for undefined, unused and deprecated functions
-rw-r--r--Makefile8
-rw-r--r--src/rabbit_dialyzer.erl32
2 files changed, 29 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index e060c804..746d5a3c 100644
--- a/Makefile
+++ b/Makefile
@@ -112,7 +112,13 @@ $(SOURCE_DIR)/rabbit_framing_amqp_0_8.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_c
dialyze: $(BEAM_TARGETS) $(BASIC_PLT)
$(ERL_EBIN) -eval \
- "rabbit_dialyzer:halt_with_code(rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\"))."
+ "rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\")." \
+ -eval \
+ "rabbit_dialyzer:xref_dir(\"$(EBIN_DIR)\")." \
+ -eval \
+ "init:stop()."
+
+
# rabbit.plt is used by rabbitmq-erlang-client's dialyze make target
create-plt: $(RABBIT_PLT)
diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl
index e5aa74b7..026a8c45 100644
--- a/src/rabbit_dialyzer.erl
+++ b/src/rabbit_dialyzer.erl
@@ -32,7 +32,7 @@
-module(rabbit_dialyzer).
-export([create_basic_plt/1, add_to_plt/2, dialyze_files/2,
- halt_with_code/1]).
+ halt_with_code/1, xref_dir/1]).
%%----------------------------------------------------------------------------
@@ -41,6 +41,7 @@
-spec(create_basic_plt/1 :: (file:filename()) -> 'ok').
-spec(add_to_plt/2 :: (file:filename(), string()) -> 'ok').
-spec(dialyze_files/2 :: (file:filename(), string()) -> 'ok').
+-spec(xref_dir/1 :: (file:filename()) -> 'ok').
-spec(halt_with_code/1 :: (atom()) -> no_return()).
-endif.
@@ -61,7 +62,7 @@ add_to_plt(PltPath, FilesString) ->
{init_plt, PltPath},
{output_plt, PltPath},
{files, Files}]),
- print_warnings(DialyzerWarnings),
+ print_warnings(DialyzerWarnings, fun dialyzer:format_warning/1),
ok.
dialyze_files(PltPath, ModifiedFiles) ->
@@ -71,19 +72,30 @@ dialyze_files(PltPath, ModifiedFiles) ->
{warnings, [underspecs, behaviours,
race_conditions]}]),
case DialyzerWarnings of
- [] -> io:format("~nOk~n"),
- ok;
+ [] -> io:format("~nOk~n");
_ -> io:format("~n~nFAILED with the following ~p warnings:~n~n",
[length(DialyzerWarnings)]),
- print_warnings(DialyzerWarnings),
- fail
- end.
+ print_warnings(DialyzerWarnings, fun dialyzer:format_warning/1)
+ end,
+ ok.
-print_warnings(Warnings) ->
- [io:format("~s~n", [dialyzer:format_warning(W)]) || W <- Warnings],
- io:format("~n"),
+xref_dir(EbinDir) ->
+ XrefErrors = xref:d(EbinDir),
+ [case proplists:get_value(W, XrefErrors, []) of
+ [] -> ok;
+ Problems -> io:format("~p functions:~n", [W]),
+ print_warnings(Problems, fun show_function/1)
+ end
+ || W <- [deprecated, undefined, unused]],
ok.
+show_function({{Mod,Fun,Ar},{PMod,PFun,PAr}}) ->
+ io_lib:format("~s:~s/~p called by ~s:~s/~p", [PMod, PFun, PAr,
+ Mod, Fun, Ar]).
+print_warnings(Warnings, FormatFun) ->
+ [io:format("~s~n", [FormatFun(W)]) || W <- Warnings],
+ io:format("~n").
+
otp_apps_dependencies_paths() ->
[code:lib_dir(App, ebin) ||
App <- [kernel, stdlib, sasl, mnesia, os_mon, ssl, eunit, tools]].