summaryrefslogtreecommitdiff
path: root/src/rebar_prv_escriptize.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_prv_escriptize.erl')
-rw-r--r--src/rebar_prv_escriptize.erl43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl
index 32f5508..7ee20c2 100644
--- a/src/rebar_prv_escriptize.erl
+++ b/src/rebar_prv_escriptize.erl
@@ -61,8 +61,11 @@ desc() ->
"the project's and its dependencies' BEAM files.".
do(State) ->
+ Providers = rebar_state:providers(State),
+ Cwd = rebar_state:dir(State),
+ rebar_hooks:run_project_and_app_hooks(Cwd, pre, ?PROVIDER, Providers, State),
?INFO("Building escript...", []),
- case rebar_state:get(State, escript_main_app, undefined) of
+ Res = case rebar_state:get(State, escript_main_app, undefined) of
undefined ->
case rebar_state:project_apps(State) of
[App] ->
@@ -72,9 +75,15 @@ do(State) ->
end;
Name ->
AllApps = rebar_state:all_deps(State)++rebar_state:project_apps(State),
- {ok, AppInfo} = rebar_app_utils:find(ec_cnv:to_binary(Name), AllApps),
- escriptize(State, AppInfo)
- end.
+ case rebar_app_utils:find(ec_cnv:to_binary(Name), AllApps) of
+ {ok, AppInfo} ->
+ escriptize(State, AppInfo);
+ _ ->
+ ?PRV_ERROR({bad_name, Name})
+ end
+ end,
+ rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State),
+ Res.
escriptize(State0, App) ->
AppName = rebar_app_info:name(App),
@@ -90,9 +99,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 +228,25 @@ 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.
+ DepDir <- [code:lib_dir(Dep)],
+ DepDir =:= {error, bad_name} orelse % those are all local
+ not lists:prefix(code:root_dir(), DepDir)]
+ -- ([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),