|
| 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