summaryrefslogtreecommitdiff
path: root/src/rebar_prv_escriptize.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-06-26 20:26:51 -0400
committerFred Hebert <mononcqc@ferd.ca>2016-06-26 20:30:18 -0400
commit6bc8ccefd344ba1620b183c5c6810b6cd727d841 (patch)
treedc6a25fbe48ea61600732aa0922841557b26b439 /src/rebar_prv_escriptize.erl
parentfeed75ca91423be8eaf49e1db57a5ef605238aed (diff)
Escriptize based on configured apps only
Prior to this patch, the escriptize command flat out selected all declared dependencies. This patch instead looks at the app files and only includes the dependencies of the top level app and the extra ones, avoiding to package more apps than required. This required a version bump on cth_readable as it mistakenly included 'syntax_lib' instead of 'syntax_tools' as a dependency.
Diffstat (limited to 'src/rebar_prv_escriptize.erl')
-rw-r--r--src/rebar_prv_escriptize.erl24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl
index 32f5508..d8704f6 100644
--- a/src/rebar_prv_escriptize.erl
+++ b/src/rebar_prv_escriptize.erl
@@ -90,9 +90,9 @@ escriptize(State0, App) ->
%% Look for a list of other applications (dependencies) to include
%% in the output file. We then use the .app files for each of these
%% to pull in all the .beam files.
- InclApps = lists:usort([ec_cnv:to_atom(AppName) | rebar_state:get(State, escript_incl_apps, [])
- ++ all_deps(State)]),
+ TopInclApps = lists:usort([ec_cnv:to_atom(AppName) | rebar_state:get(State, escript_incl_apps, [])]),
AllApps = rebar_state:all_deps(State)++rebar_state:project_apps(State),
+ InclApps = find_deps(TopInclApps, AllApps),
InclBeams = get_apps_beams(InclApps, AllApps),
%% Look for a list of extra files to include in the output file.
@@ -219,9 +219,23 @@ usort(List) ->
get_nonempty(Files) ->
[{FName,FBin} || {FName,FBin} <- Files, FBin =/= <<>>].
-all_deps(State) ->
- [list_to_existing_atom(binary_to_list(rebar_app_info:name(App)))
- || App <- rebar_state:all_deps(State)].
+find_deps(AppNames, AllApps) ->
+ BinAppNames = [ec_cnv:to_binary(Name) || Name <- AppNames],
+ [ec_cnv:to_atom(Name) ||
+ Name <- find_deps_of_deps(BinAppNames, AllApps, BinAppNames)].
+
+%% Should look at the app files to find direct dependencies
+find_deps_of_deps([], _, Acc) -> Acc;
+find_deps_of_deps([Name|Names], Apps, Acc) ->
+ ?DEBUG("processing ~p", [Name]),
+ {ok, App} = rebar_app_utils:find(Name, Apps),
+ DepNames = proplists:get_value(applications, rebar_app_info:app_details(App), []),
+ BinDepNames = [ec_cnv:to_binary(Dep) || Dep <- DepNames,
+ %% ignore system libs; shouldn't include them.
+ not lists:prefix(code:root_dir(), code:lib_dir(Dep))]
+ -- ([Name|Names]++Acc), % avoid already seen deps
+ ?DEBUG("new deps of ~p found to be ~p", [Name, BinDepNames]),
+ find_deps_of_deps(BinDepNames ++ Names, Apps, BinDepNames ++ Acc).
def(Rm, State, Key, Default) ->
Value0 = rebar_state:get(State, Key, Default),