From d922985b368cebfa10606f347d84eafb06c26d15 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 7 Jan 2011 17:24:27 +0100 Subject: Fix typos --- src/rebar_xref.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rebar_xref.erl') diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl index 55b4f0e..0e29792 100644 --- a/src/rebar_xref.erl +++ b/src/rebar_xref.erl @@ -111,7 +111,7 @@ filter_away_ignored(UnusedExports) -> %% Functions can be ignored by using %% -ignore_xref([{F, A}, ...]). - %% Setup a filter function that build a list of behaviour callbacks and/or + %% Setup a filter function that builds a list of behaviour callbacks and/or %% any functions marked to ignore. We then use this list to mask any functions %% marked as unused exports by xref F = fun(Mod) -> -- cgit v1.1 From 150c9d0b470b5177282a1f005986cba75c689ebb Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sun, 9 Jan 2011 11:54:40 +0100 Subject: Simplify and cleanup rebar_xref --- src/rebar_xref.erl | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'src/rebar_xref.erl') diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl index 0e29792..05bb46b 100644 --- a/src/rebar_xref.erl +++ b/src/rebar_xref.erl @@ -121,7 +121,7 @@ filter_away_ignored(UnusedExports) -> [{Mod, F, A} || {F, A} <- Ignore ++ lists:flatten(Callbacks)] end, AttrIgnore = lists:flatten(lists:map(F, lists:usort([M || {M, _, _} <- UnusedExports]))), - [X || X <- UnusedExports, not(lists:member(X, AttrIgnore))]. + [X || X <- UnusedExports, not lists:member(X, AttrIgnore)]. kf(Key, List) -> @@ -147,6 +147,7 @@ format_fa({_M, F, A}) -> %% %% Extract an element from a tuple, or undefined if N > tuple size +%% safe_element(N, Tuple) -> case catch(element(N, Tuple)) of {'EXIT', {badarg, _}} -> @@ -155,23 +156,6 @@ safe_element(N, Tuple) -> Value end. -%% -%% Extract the line number for a given function def -%% -abstract_code_function_line(Code, Name, Args) -> - [{function, Line, Name, _, _}] = [E || E <- Code, - safe_element(1, E) == function, - safe_element(3, E) == Name, - safe_element(4, E) == Args], - Line. - -%% -%% Extract the original source filename from the abstract code -%% -abstract_code_source_file(Code) -> - [{attribute, 1, file, {Name, _}} | _] = Code, - Name. - %% %% Given a MFA, find the file and LOC where it's defined. Note that @@ -182,7 +166,11 @@ find_mfa_source({M, F, A}) -> {M, Bin, _} = code:get_object_code(M), {ok, {M, [{abstract_code, AbstractCode}]}} = beam_lib:chunks(Bin, [abstract_code]), {raw_abstract_v1, Code} = AbstractCode, - Source = abstract_code_source_file(Code), - Line = abstract_code_function_line(Code, F, A), + %% Extract the original source filename from the abstract code + [{attribute, 1, file, {Source, _}} | _] = Code, + %% Extract the line number for a given function def + [{function, Line, F, _, _}] = [E || E <- Code, + safe_element(1, E) == function, + safe_element(3, E) == F, + safe_element(4, E) == A], {Source, Line}. - -- cgit v1.1 From c466076ffb5a1ea4c00d49fefff0dcfbceb58236 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 31 Jan 2011 17:43:31 +0100 Subject: Clean up emacs file local variables --- src/rebar_xref.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rebar_xref.erl') diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl index 05bb46b..8a489a8 100644 --- a/src/rebar_xref.erl +++ b/src/rebar_xref.erl @@ -1,4 +1,4 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% -- cgit v1.1 From 63de05d914f3c2bef6dcfc6cf966400d93c9c80d Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 28 Jan 2011 16:08:27 +0100 Subject: Clean up code --- src/rebar_xref.erl | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'src/rebar_xref.erl') diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl index 8a489a8..f46ccfc 100644 --- a/src/rebar_xref.erl +++ b/src/rebar_xref.erl @@ -44,8 +44,11 @@ xref(Config, _) -> %% Spin up xref {ok, _} = xref:start(xref), ok = xref:set_library_path(xref, code_path()), - xref:set_default(xref, [{warnings, rebar_config:get(Config, xref_warnings, false)}, + + xref:set_default(xref, [{warnings, + rebar_config:get(Config, xref_warnings, false)}, {verbose, rebar_config:is_verbose()}]), + {ok, _} = xref:add_directory(xref, "ebin"), %% Save the code path prior to doing anything @@ -53,8 +56,9 @@ xref(Config, _) -> true = code:add_path(filename:join(rebar_utils:get_cwd(), "ebin")), %% Get list of xref checks we want to run - XrefChecks = rebar_config:get(Config, xref_checks, [exports_not_used, - undefined_function_calls]), + XrefChecks = rebar_config:get(Config, xref_checks, + [exports_not_used, + undefined_function_calls]), %% Look for exports that are unused by anything case lists:member(exports_not_used, XrefChecks) of @@ -91,12 +95,15 @@ check_exports_not_used(_Config) -> check_undefined_function_calls(_Config) -> {ok, UndefinedCalls0} = xref:analyze(xref, undefined_function_calls), - UndefinedCalls = [{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)} || - {Caller, Target} <- UndefinedCalls0], - lists:foreach(fun({{Source, Line}, FunStr, Target}) -> - ?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n", - [Source, Line, FunStr, Target]) - end, UndefinedCalls), + UndefinedCalls = + [{find_mfa_source(Caller), format_fa(Caller), format_mfa(Target)} || + {Caller, Target} <- UndefinedCalls0], + + lists:foreach( + fun({{Source, Line}, FunStr, Target}) -> + ?CONSOLE("~s:~w: Warning ~s calls undefined function ~s\n", + [Source, Line, FunStr, Target]) + end, UndefinedCalls), ok. @@ -112,15 +119,18 @@ filter_away_ignored(UnusedExports) -> %% -ignore_xref([{F, A}, ...]). %% Setup a filter function that builds a list of behaviour callbacks and/or - %% any functions marked to ignore. We then use this list to mask any functions - %% marked as unused exports by xref + %% any functions marked to ignore. We then use this list to mask any + %% functions marked as unused exports by xref F = fun(Mod) -> Attrs = kf(attributes, Mod:module_info()), Ignore = kf(ignore_xref, Attrs), - Callbacks = [B:behaviour_info(callbacks) || B <- kf(behaviour, Attrs)], + Callbacks = + [B:behaviour_info(callbacks) || B <- kf(behaviour, Attrs)], [{Mod, F, A} || {F, A} <- Ignore ++ lists:flatten(Callbacks)] end, - AttrIgnore = lists:flatten(lists:map(F, lists:usort([M || {M, _, _} <- UnusedExports]))), + AttrIgnore = + lists:flatten( + lists:map(F, lists:usort([M || {M, _, _} <- UnusedExports]))), [X || X <- UnusedExports, not lists:member(X, AttrIgnore)]. @@ -136,7 +146,8 @@ display_mfas([], _Message) -> ok; display_mfas([{_Mod, Fun, Args} = MFA | Rest], Message) -> {Source, Line} = find_mfa_source(MFA), - ?CONSOLE("~s:~w: Warning: function ~s/~w ~s\n", [Source, Line, Fun, Args, Message]), + ?CONSOLE("~s:~w: Warning: function ~s/~w ~s\n", + [Source, Line, Fun, Args, Message]), display_mfas(Rest, Message). format_mfa({M, F, A}) -> @@ -164,8 +175,8 @@ safe_element(N, Tuple) -> %% find_mfa_source({M, F, A}) -> {M, Bin, _} = code:get_object_code(M), - {ok, {M, [{abstract_code, AbstractCode}]}} = beam_lib:chunks(Bin, [abstract_code]), - {raw_abstract_v1, Code} = AbstractCode, + AbstractCode = beam_lib:chunks(Bin, [abstract_code]), + {ok, {M, [{abstract_code, {raw_abstract_v1, Code}}]}} = AbstractCode, %% Extract the original source filename from the abstract code [{attribute, 1, file, {Source, _}} | _] = Code, %% Extract the line number for a given function def -- cgit v1.1