diff options
author | Torbjorn Tornkvist <tobbe@klarna.com> | 2011-12-01 20:23:46 +0100 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-12-12 17:06:23 +0100 |
commit | b4f136d752af47508928961ae163422eef5f4c62 (patch) | |
tree | c0ea644d1e4cf3a08ba26235f9115e4c05a7efe7 | |
parent | e763ba28ed235184f1fc02374bc034d204524906 (diff) |
Make 'rebar xref' honour the skip_app directive
It is now possible to call rebar as:
rebar xref skip_app=Mod1,Mod2,...
This makes it easy to skip running xref on (e.g)
imported dependencies in your application.
The function rebar_utils:is_skipped_app/0 is added so
that other rebar commands may use it.
-rw-r--r-- | src/rebar_utils.erl | 40 | ||||
-rw-r--r-- | src/rebar_xref.erl | 8 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index ce84a57..ddd5ddc 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -43,7 +43,9 @@ prop_check/3, expand_code_path/0, deprecated/5, - expand_env_variable/3]). + expand_env_variable/3, + is_skipped_app/0 + ]). -include("rebar.hrl"). @@ -199,6 +201,42 @@ expand_env_variable(InStr, VarName, RawVarValue) -> re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts) end. +%% +%% Return: true , if we are in the context of a 'Skipped App', else: false +%% (Example: rebar xref skip_app=mochiweb,webmachine) +is_skipped_app() -> + case rebar_config:get_global(skip_app, undefined) of + undefined -> + %% no skip list + false; + + SkipApps -> + + case string:tokens(SkipApps, ",") of + [] -> + %% no tokens + false; + + SkipAppsTokens -> + + %% Where we are at the moment + Cwd = rebar_utils:get_cwd(), + + %% Return true if app should be skipped + SkipPred = fun(App) -> + case re:run(Cwd, App) of + {match,_} -> true; + _ -> false + end + end, + + %% Check if 'we' are among the skipped apps. + lists:foldl(fun(SkippedApp, Bool) -> + SkipPred(SkippedApp) or Bool + end, false, SkipAppsTokens) + end + end. + %% ==================================================================== %% Internal functions diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl index 84d422e..1392c6f 100644 --- a/src/rebar_xref.erl +++ b/src/rebar_xref.erl @@ -40,7 +40,13 @@ %% Public API %% =================================================================== -xref(Config, _) -> +xref(Config, _X) -> + case rebar_utils:is_skipped_app() of + true -> ok; + false -> xref0(Config, _X) + end. + +xref0(Config, _) -> %% Spin up xref {ok, _} = xref:start(xref), ok = xref:set_library_path(xref, code_path()), |