summaryrefslogtreecommitdiff
path: root/src/rebar_xref.erl
diff options
context:
space:
mode:
authorAmit Kapoor <amit@koanect.com>2012-04-02 08:01:39 -0700
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2012-04-02 19:14:37 +0200
commit0191806f9282c6ce1da0f1a2c0672406de15ed24 (patch)
tree549da2c65dc3c346a8f247199902acbe84ef302e /src/rebar_xref.erl
parent26e12522501fbe59d85f127a5fbd26e4f464e352 (diff)
Add support for custom xref queries
The custom queries are configured in rebar.config via the tuple {xref_queries, [{query(), query_result()},...]}. The implementation passes the query() string to xref:q and compares the return value with query_result(). It will result in an error if they do not match. The following configuration, for example, is the same as running the xref check undefined_function_calls. It additionally filters ejabberd_logger:*_msg/4 from the result as these functions are generated on execution by ejabberd and not available at compile time. {xref_queries, [{"(XC - UC) || (XU - X - B - (\"ejabberd_logger\":\".*_msg\"/\"4\"))",[]}]}. This patch also modifies the build process of this package by running a custom query instead of doing a diff against a static xref_warning file.
Diffstat (limited to 'src/rebar_xref.erl')
-rw-r--r--src/rebar_xref.erl19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl
index 84d422e..cfdfb8c 100644
--- a/src/rebar_xref.erl
+++ b/src/rebar_xref.erl
@@ -77,13 +77,19 @@ xref(Config, _) ->
false ->
true
end,
+
+ %% Run custom queries
+ QueryChecks = rebar_config:get(Config, xref_queries, []),
+ QueryNoWarn = lists:all(fun check_query/1, QueryChecks),
+
%% Restore the original code path
true = code:set_path(OrigPath),
%% Stop xref
stopped = xref:stop(xref),
- case lists:all(fun(NoWarn) -> NoWarn end, [ExportsNoWarn, UndefNoWarn]) of
+ case lists:all(fun(NoWarn) -> NoWarn end,
+ [ExportsNoWarn, UndefNoWarn, QueryNoWarn]) of
true ->
ok;
false ->
@@ -115,6 +121,17 @@ check_undefined_function_calls() ->
end, UndefinedCalls),
UndefinedCalls =:= [].
+check_query({Query, Value}) ->
+ {ok, Answer} = xref:q(xref, Query),
+ case Answer =:= Value of
+ false ->
+ ?CONSOLE("Query ~s~n answer ~p~n did not match ~p~n",
+ [Query, Answer, Value]),
+ false;
+ _ ->
+ true
+ end.
+
code_path() ->
[P || P <- code:get_path(),
filelib:is_dir(P)] ++ [filename:join(rebar_utils:get_cwd(), "ebin")].