From a5fc48bc52049767fd74e7652eb6cf827c9e0e3f Mon Sep 17 00:00:00 2001 From: Pablo Costas Date: Sun, 13 Sep 2020 23:05:48 +0200 Subject: [PATCH] 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. --- src/rebar_paths.erl | 33 ++++++++++++++++++++++++++++++--- src/rebar_prv_xref.erl | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/rebar_paths.erl b/src/rebar_paths.erl index 160f9fa2..a0f5cedf 100644 --- a/src/rebar_paths.erl +++ b/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)). \ No newline at end of file diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index b7c4fec2..a720d846 100644 --- a/src/rebar_prv_xref.erl +++ b/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