Skip to content

Commit 978685e

Browse files
author
Matthias Radestock
committed
merge bug21023 into default
2 parents 14b0e58 + a140342 commit 978685e

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ syntax: regexp
1111
^include/rabbit_framing\.hrl$
1212
^src/rabbit_framing\.erl$
1313
^rabbit\.plt$
14+
^basic.plt$
1415
^ebin/rabbit\.(app|rel|boot|script)$
1516
^plugins/
1617
^priv/plugins/

Makefile

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ SOURCE_DIR=src
1111
EBIN_DIR=ebin
1212
INCLUDE_DIR=include
1313
SOURCES=$(wildcard $(SOURCE_DIR)/*.erl)
14-
BEAM_TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES))
14+
BEAM_TARGETS=$(EBIN_DIR)/rabbit_framing.beam $(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam, $(SOURCES))
1515
TARGETS=$(EBIN_DIR)/rabbit.app $(BEAM_TARGETS)
1616
WEB_URL=http://stage.rabbitmq.com/
1717
MANPAGES=$(patsubst %.pod, %.gz, $(wildcard docs/*.[0-9].pod))
1818

1919
PYTHON=python
2020

21+
BASIC_PLT=basic.plt
22+
RABBIT_PLT=rabbit.plt
23+
2124
ifndef USE_SPECS
2225
# our type specs rely on features / bug fixes in dialyzer that are
2326
# only available in R13B upwards (R13B is eshell 5.7.1)
@@ -39,6 +42,8 @@ AMQP_SPEC_JSON_PATH=$(AMQP_CODEGEN_DIR)/amqp-0.8.json
3942

4043
ERL_CALL=erl_call -sname $(RABBITMQ_NODENAME) -e
4144

45+
ERL_EBIN=erl -noinput -pa $(EBIN_DIR)
46+
4247
all: $(TARGETS)
4348

4449
$(EBIN_DIR)/rabbit.app: $(EBIN_DIR)/rabbit_app.in $(BEAM_TARGETS) generate_app
@@ -57,14 +62,32 @@ $(INCLUDE_DIR)/rabbit_framing.hrl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.p
5762
$(SOURCE_DIR)/rabbit_framing.erl: codegen.py $(AMQP_CODEGEN_DIR)/amqp_codegen.py $(AMQP_SPEC_JSON_PATH)
5863
$(PYTHON) codegen.py body $(AMQP_SPEC_JSON_PATH) $@
5964

60-
dialyze: $(BEAM_TARGETS)
61-
dialyzer -c $?
65+
dialyze: $(BEAM_TARGETS) $(BASIC_PLT)
66+
$(ERL_EBIN) -eval \
67+
"rabbit_dialyzer:halt_with_code(rabbit_dialyzer:dialyze_files(\"$(BASIC_PLT)\", \"$(BEAM_TARGETS)\"))."
68+
69+
# rabbit.plt is used by rabbitmq-erlang-client's dialyze make target
70+
create-plt: $(RABBIT_PLT)
71+
72+
$(RABBIT_PLT): $(BEAM_TARGETS) $(BASIC_PLT)
73+
cp $(BASIC_PLT) $@
74+
$(ERL_EBIN) -eval \
75+
"rabbit_dialyzer:halt_with_code(rabbit_dialyzer:add_to_plt(\"$@\", \"$(BEAM_TARGETS)\"))."
76+
77+
$(BASIC_PLT): $(BEAM_TARGETS)
78+
if [ -f $@ ]; then \
79+
touch $@; \
80+
else \
81+
$(ERL_EBIN) -eval \
82+
"rabbit_dialyzer:halt_with_code(rabbit_dialyzer:create_basic_plt(\"$@\"))."; \
83+
fi
6284

6385
clean:
6486
rm -f $(EBIN_DIR)/*.beam
6587
rm -f $(EBIN_DIR)/rabbit.app $(EBIN_DIR)/rabbit.boot $(EBIN_DIR)/rabbit.script $(EBIN_DIR)/rabbit.rel
6688
rm -f $(INCLUDE_DIR)/rabbit_framing.hrl $(SOURCE_DIR)/rabbit_framing.erl codegen.pyc
6789
rm -f docs/*.[0-9].gz
90+
rm -f $(RABBIT_PLT)
6891

6992
cleandb:
7093
rm -rf $(RABBITMQ_MNESIA_DIR)/*

src/rabbit_dialyzer.erl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License at
4+
%% http://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
%% License for the specific language governing rights and limitations
9+
%% under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developers of the Original Code are LShift Ltd,
14+
%% Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
%%
16+
%% Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
%% Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
%% are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
%% Technologies LLC, and Rabbit Technologies Ltd.
20+
%%
21+
%% Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
%% Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
%% Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
%% LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
%% (C) 2007-2009 Rabbit Technologies Ltd.
26+
%%
27+
%% All Rights Reserved.
28+
%%
29+
%% Contributor(s): ______________________________________.
30+
%%
31+
32+
-module(rabbit_dialyzer).
33+
-include("rabbit.hrl").
34+
35+
-export([create_basic_plt/1, add_to_plt/2, dialyze_files/2, halt_with_code/1]).
36+
37+
%%----------------------------------------------------------------------------
38+
39+
-ifdef(use_specs).
40+
41+
-spec(create_basic_plt/1 :: (string()) -> 'ok').
42+
-spec(add_to_plt/2 :: (string(), string()) -> 'ok').
43+
-spec(dialyze_files/2 :: (string(), string()) -> 'ok').
44+
-spec(halt_with_code/1 :: (atom()) -> no_return()).
45+
46+
-endif.
47+
48+
%%----------------------------------------------------------------------------
49+
50+
create_basic_plt(BasicPltPath) ->
51+
OptsRecord = dialyzer_options:build(
52+
[{analysis_type, plt_build},
53+
{output_plt, BasicPltPath},
54+
{files_rec, otp_apps_dependencies_paths()}]),
55+
dialyzer_cl:start(OptsRecord),
56+
ok.
57+
58+
add_to_plt(PltPath, FilesString) ->
59+
{ok, Files} = regexp:split(FilesString, " "),
60+
DialyzerWarnings = dialyzer:run([{analysis_type, plt_add},
61+
{init_plt, PltPath},
62+
{output_plt, PltPath},
63+
{files, Files}]),
64+
print_warnings(DialyzerWarnings),
65+
ok.
66+
67+
dialyze_files(PltPath, ModifiedFiles) ->
68+
{ok, Files} = regexp:split(ModifiedFiles, " "),
69+
DialyzerWarnings = dialyzer:run([{init_plt, PltPath},
70+
{files, Files}]),
71+
case DialyzerWarnings of
72+
[] -> io:format("~nOk~n"),
73+
ok;
74+
_ -> io:format("~nFAILED with the following warnings:~n"),
75+
print_warnings(DialyzerWarnings),
76+
fail
77+
end.
78+
79+
print_warnings(Warnings) ->
80+
[io:format("~s", [dialyzer:format_warning(W)]) || W <- Warnings],
81+
io:format("~n"),
82+
ok.
83+
84+
otp_apps_dependencies_paths() ->
85+
[code:lib_dir(App, ebin) ||
86+
App <- [kernel, stdlib, sasl, mnesia, os_mon, ssl, eunit, tools]].
87+
88+
halt_with_code(ok) ->
89+
halt();
90+
halt_with_code(fail) ->
91+
halt(1).

0 commit comments

Comments
 (0)