浏览代码

Change xref paths to only those of runtime deps

This commit changes mainly the `rebar_paths` module by adding a
new `runtime` target. When using that target, `rebar_paths:get_apps/2`
will, for each project app, find all their `applications` and
`included_applicactions` and filter those that could be found
in rebar3's state.
pull/2354/head
Pablo Costas 4 年前
父节点
当前提交
a5fc48bc52
共有 2 个文件被更改,包括 31 次插入4 次删除
  1. +30
    -3
      src/rebar_paths.erl
  2. +1
    -1
      src/rebar_prv_xref.erl

+ 30
- 3
src/rebar_paths.erl 查看文件

@ -51,12 +51,14 @@ normalize_targets(List) ->
%% Plan for the eventuality of getting values piped in
%% from future versions of rebar3, possibly from plugins and so on,
%% which means we'd risk failing kind of violently. We only support
%% deps and plugins
%% deps, plugins and runtime deps.
TmpList = lists:foldl(
fun(deps, [deps | _] = Acc) -> Acc;
(plugins, [plugins | _] = Acc) -> Acc;
(runtime, [runtime | _] = Acc) -> Acc;
(deps, Acc) -> [deps | Acc -- [deps]];
(plugins, Acc) -> [plugins | Acc -- [plugins]];
(runtime, Acc) -> [runtime | Acc -- [runtime]];
(_, Acc) -> Acc
end,
[],
@ -196,7 +198,9 @@ app_groups(Targets, State) ->
get_paths(deps, State) ->
rebar_state:code_paths(State, all_deps);
get_paths(plugins, State) ->
rebar_state:code_paths(State, all_plugin_deps).
rebar_state:code_paths(State, all_plugin_deps);
get_paths(runtime, State) ->
rebar_state:code_paths(State, all_deps).
get_apps(deps, State) ->
%% The code paths for deps also include the top level apps
@ -208,4 +212,27 @@ get_apps(deps, State) ->
end ++
rebar_state:all_deps(State);
get_apps(plugins, State) ->
rebar_state:all_plugin_deps(State).
rebar_state:all_plugin_deps(State);
get_apps(runtime, State) ->
%% We get all project apps and for each of them we find
%% their runtime deps (i.e., `applications' and `included_applications').
ProjectApps = rebar_state:project_apps(State),
RuntimeApps =
[begin
Apps = rebar_app_info:applications(App),
IncludedApps = rebar_app_info:included_applications(App),
lists:foldl(
fun(AppName0, Acc) ->
%% If the App is an atom convert it to a binary, otherwise leave it as it is.
AppName1 = if is_atom(AppName0) -> atom_to_binary(AppName0, utf8);
true -> AppName0
end,
%% We only care about those apps we could find in the `State'.
case rebar_app_utils:find(AppName1, ProjectApps) of
{ok, AppInfo} -> [AppInfo|Acc];
error -> Acc
end
end, [App], Apps ++ IncludedApps)
end || App <- ProjectApps],
%% We get rid of duplicated apps from the flattened list.
lists:usort(lists:flatten(RuntimeApps)).

+ 1
- 1
src/rebar_prv_xref.erl 查看文件

@ -36,7 +36,7 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
rebar_paths:set_paths([deps], State),
rebar_paths:set_paths([runtime], State),
XrefChecks = prepare(State),
XrefIgnores = rebar_state:get(State, xref_ignores, []),
%% Run xref checks

正在加载...
取消
保存