Merge default into bug23568 bug23568
authorDavid Wragg <david@rabbitmq.com>
Tue Feb 01 13:09:43 2011 +0000 (2011-02-01)
branchbug23568
changeset 2507136f91bde70
parent 247 677c78aae4b0
parent 249 fd5248695d65
child 251 f083a765ca23
Merge default into bug23568
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/check_xref	Tue Feb 01 13:09:43 2011 +0000
     1.3 @@ -0,0 +1,57 @@
     1.4 +#!/usr/bin/env escript
     1.5 +%% -*- erlang -*-
     1.6 +-mode(compile).
     1.7 +
     1.8 +%% The contents of this file are subject to the Mozilla Public License
     1.9 +%% Version 1.1 (the "License"); you may not use this file except in
    1.10 +%% compliance with the License. You may obtain a copy of the License
    1.11 +%% at http://www.mozilla.org/MPL/
    1.12 +%%
    1.13 +%% Software distributed under the License is distributed on an "AS IS"
    1.14 +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    1.15 +%% the License for the specific language governing rights and
    1.16 +%% limitations under the License.
    1.17 +%%
    1.18 +%% The Original Code is RabbitMQ.
    1.19 +%%
    1.20 +%% The Initial Developer of the Original Code is VMware, Inc.
    1.21 +%% Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
    1.22 +%%
    1.23 +
    1.24 +main([]) ->
    1.25 +    main(["."]);
    1.26 +main([PackageDir]) ->
    1.27 +    {ok, _Pid} = xref:start(?MODULE),
    1.28 +    ok = xref:set_default(?MODULE, [{verbose,false}, {warnings,false}]),
    1.29 +    {ok, PackageModules} = add_dir(PackageDir, "ebin"),
    1.30 +    [{ok, _} = add_dir(PackageDir, Dir) || Dir <- ["build", "deps"]],
    1.31 +    {ok, otp} = xref:add_release(?MODULE, code:lib_dir(), {name, otp}),
    1.32 +
    1.33 +    ModulesQ =
    1.34 +        "(" ++ lists:nthtail(
    1.35 +                 2, lists:flatten(
    1.36 +                      [io_lib:format(" + \"~s\" : Mod", [atom_to_list(Mod)])
    1.37 +                       || Mod <- PackageModules])) ++
    1.38 +        ")",
    1.39 +
    1.40 +    %% 'U' is the set of unknown Functions
    1.41 +    %% '*' is set intersection
    1.42 +    %% 'range' takes the RHS in all call pairs (From, To)
    1.43 +    %% 'closure' gives the transitive closure
    1.44 +    %% 'E' is all edges (i.e. all calls)
    1.45 +    %% '|' is the subset of calls from any of the vertices
    1.46 +    %%
    1.47 +    %% I.e. we construct the transitive closure of all calls from any
    1.48 +    %% of the plugin's modules, look at the ranges there of
    1.49 +    %% (i.e. callees, not callers), and see if they're unknown
    1.50 +
    1.51 +    Q = "U * range (closure E | " ++ ModulesQ ++")",
    1.52 +    io:format("~p~n", [xref:q(?MODULE, Q)]),
    1.53 +    ok.
    1.54 +
    1.55 +add_dir(PackageDir, Dir) ->
    1.56 +    Path = filename:join(PackageDir, Dir),
    1.57 +    case filelib:is_dir(Path) of
    1.58 +        true  -> {ok, _} = xref:add_directory(?MODULE, Path, {recurse, true});
    1.59 +        false -> {ok, []}
    1.60 +    end.