summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Ionescu <vlad@lshift.net>2009-09-02 20:01:38 +0100
committerVlad Ionescu <vlad@lshift.net>2009-09-02 20:01:38 +0100
commitb45448edcab38ae2c9a3ca52c450106a1ecf2634 (patch)
treec858d4c92f879c99cf370d17580a35b39e2fd5a7
parentf6768066d5c604ced90def93d78541f0eb25a492 (diff)
downloadrabbitmq-server-b45448edcab38ae2c9a3ca52c450106a1ecf2634.tar.gz
moving dialyzer stuff to src/rabbit_dialyzer.erl
-rw-r--r--Makefile37
-rw-r--r--src/rabbit_dialyzer.erl93
2 files changed, 104 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 1174f1a9..dab3ba94 100644
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,8 @@ AMQP_SPEC_JSON_PATH=$(AMQP_CODEGEN_DIR)/amqp-0.8.json
ERL_CALL=erl_call -sname $(RABBITMQ_NODENAME) -e
+ERL_RABBIT_DIALYZER=erl -noinput -eval "code:load_abs(\"$(EBIN_DIR)/rabbit_dialyzer\")."
+
all: $(TARGETS)
$(EBIN_DIR)/rabbit.app: $(EBIN_DIR)/rabbit_app.in $(BEAM_TARGETS) generate_app
@@ -72,38 +74,21 @@ $(PLT): $(BEAM_TARGETS)
DIALYZER_INPUT_FILES="$?"; \
else \
cp $(BASIC_PLT) $@ && \
+ rm -f .last_valid_dialysis && \
DIALYZER_INPUT_FILES="$(BEAM_TARGETS)"; \
fi; \
- DIALYZER_OUTPUT=$$(dialyzer --plt $@ --add_to_plt -c $$DIALYZER_INPUT_FILES); \
- echo "$$DIALYZER_OUTPUT"; \
- echo "$$DIALYZER_OUTPUT" | grep "done (passed successfully)"
+ $(ERL_RABBIT_DIALYZER) -eval \
+ "rabbit_dialyzer:update_plt(\"$@\", \"$$DIALYZER_INPUT_FILES\"), halt()."
.last_valid_dialysis: $(BEAM_TARGETS)
- DIALYZER_OUTPUT=$$(erl -noinput -eval \
- "{ok, Files} = regexp:split(\"$?\", \" \"), \
- lists:foreach( \
- fun(Warning) -> io:format(\"~s\", [dialyzer:format_warning(Warning)]) end, \
- dialyzer:run([{init_plt, \"$(PLT)\"}, {files, Files}])), \
- halt()."); \
- if [ ! "$$DIALYZER_OUTPUT" ]; then \
- echo "Ok, dialyzer returned no warnings." && \
- touch .last_valid_dialysis; \
- else \
- echo "dialyzer returned the following warnings:" && \
- echo "$$DIALYZER_OUTPUT" && \
- false; \
- fi
+ $(ERL_RABBIT_DIALYZER) -eval \
+ "rabbit_dialyzer:dialyze_files(\"$(PLT)\", \"$?\"), halt()." && \
+ touch $@
$(BASIC_PLT):
- erl -noinput -eval \
- "OptsRecord = dialyzer_options:build([ \
- {analysis_type, plt_build}, \
- {init_plt, \"$(BASIC_PLT)\"}, \
- {files_rec, lists:map( \
- fun(App) -> code:lib_dir(App) ++ \"/ebin\" end, \
- [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl])}]), \
- dialyzer_cl:start(OptsRecord), \
- halt()."
+ $(MAKE) $(EBIN_DIR)/rabbit_dialyzer.beam
+ $(ERL_RABBIT_DIALYZER) -eval \
+ "rabbit_dialyzer:create_basic_plt(\"$@\"), halt()."
clean:
rm -f $(EBIN_DIR)/*.beam
diff --git a/src/rabbit_dialyzer.erl b/src/rabbit_dialyzer.erl
new file mode 100644
index 00000000..cc3aaf12
--- /dev/null
+++ b/src/rabbit_dialyzer.erl
@@ -0,0 +1,93 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License at
+%% http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+%% License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developers of the Original Code are LShift Ltd,
+%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
+%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
+%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
+%% Technologies LLC, and Rabbit Technologies Ltd.
+%%
+%% Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
+%% Ltd. Portions created by Cohesive Financial Technologies LLC are
+%% Copyright (C) 2007-2009 Cohesive Financial Technologies
+%% LLC. Portions created by Rabbit Technologies Ltd are Copyright
+%% (C) 2007-2009 Rabbit Technologies Ltd.
+%%
+%% All Rights Reserved.
+%%
+%% Contributor(s): ______________________________________.
+%%
+
+-module(rabbit_dialyzer).
+-include("rabbit.hrl").
+
+-export([create_basic_plt/1, update_plt/2, dialyze_files/2]).
+
+%%----------------------------------------------------------------------------
+
+-ifdef(use_specs).
+
+-spec(create_basic_plt/1 :: (string()) -> 'ok').
+-spec(update_plt/2 :: (string(), string()) -> 'ok').
+-spec(dialyze_files/2 :: (string(), string()) -> 'ok').
+
+-endif.
+
+%%----------------------------------------------------------------------------
+
+create_basic_plt(BasicPltPath) ->
+ OptsRecord = dialyzer_options:build([
+ {analysis_type, plt_build},
+ {init_plt, BasicPltPath},
+ {files_rec, otp_apps_dependencies_paths()}]),
+ dialyzer_cl:start(OptsRecord),
+ ok.
+
+update_plt(PltPath, ModifiedFiles) ->
+ {ok, Files} = regexp:split(ModifiedFiles, " "),
+ DialyzerWarnings = dialyzer:run([
+ {analysis_type, plt_add},
+ {init_plt, PltPath},
+ {files, Files}]),
+ print_warnings(DialyzerWarnings),
+ ok.
+
+dialyze_files(PltPath, ModifiedFiles) ->
+ {ok, Files} = regexp:split(ModifiedFiles, " "),
+ DialyzerWarnings = dialyzer:run([
+ {init_plt, PltPath},
+ {files, Files}]),
+ case DialyzerWarnings of
+ [] ->
+ io:format("Ok, dialyzer returned no warnings.~n", []),
+ ok;
+ _ ->
+ io:format("~nFAILED! dialyzer returned the following warnings:~n", []),
+ print_warnings(DialyzerWarnings),
+ erlang:error({dialyzer_warnings, DialyzerWarnings})
+ end.
+
+print_warnings(DialyzerWarnings) ->
+ lists:foreach(
+ fun
+ (Warning) -> io:format("~s", [dialyzer:format_warning(Warning)])
+ end,
+ DialyzerWarnings),
+ io:format("~n", []),
+ ok.
+
+otp_apps_dependencies_paths() ->
+ lists:map(
+ fun(App) -> code:lib_dir(App, ebin) end,
+ [stdlib, kernel, mnesia, os_mon, ssl, eunit, tools, sasl]).