From 6bc8ccefd344ba1620b183c5c6810b6cd727d841 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sun, 26 Jun 2016 20:26:51 -0400 Subject: 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. --- rebar.config | 2 +- rebar.lock | 4 ++-- src/rebar_prv_escriptize.erl | 24 +++++++++++++++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/rebar.config b/rebar.config index 7326b46..0489572 100644 --- a/rebar.config +++ b/rebar.config @@ -9,7 +9,7 @@ {bbmustache, "1.0.4"}, {relx, "3.19.0"}, {cf, "0.2.1"}, - {cth_readable, "1.2.2"}, + {cth_readable, "1.2.3"}, {eunit_formatters, "0.3.1"}]}. {escript_name, rebar3}. diff --git a/rebar.lock b/rebar.lock index 4f133d6..66241a9 100644 --- a/rebar.lock +++ b/rebar.lock @@ -2,7 +2,7 @@ [{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.0.4">>},0}, {<<"certifi">>,{pkg,<<"certifi">>,<<"0.4.0">>},0}, {<<"cf">>,{pkg,<<"cf">>,<<"0.2.1">>},0}, - {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.2.2">>},0}, + {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.2.3">>},0}, {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.21.0">>},0}, {<<"eunit_formatters">>,{pkg,<<"eunit_formatters">>,<<"0.3.1">>},0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},0}, @@ -14,7 +14,7 @@ {<<"bbmustache">>, <<"7BA94F971C5AFD7B6617918A4BB74705E36CAB36EB84B19B6A1B7EE06427AA38">>}, {<<"certifi">>, <<"A7966EFB868B179023618D29A407548F70C52466BF1849B9E8EBD0E34B7EA11F">>}, {<<"cf">>, <<"69D0B1349FD4D7D4DC55B7F407D29D7A840BF9A1EF5AF529F1EBE0CE153FC2AB">>}, - {<<"cth_readable">>, <<"983913A8E8572310B7EAF5F2631148B7D70B3C090D2120DCFE777A93AA4165FB">>}, + {<<"cth_readable">>, <<"293120673DFF82F0768612C5282E35C40CACC1B6F94FE99077438FD3749D0E27">>}, {<<"erlware_commons">>, <<"A04433071AD7D112EDEFC75AC77719DD3E6753E697AC09428FC83D7564B80B15">>}, {<<"eunit_formatters">>, <<"7A6FC351EB5B873E2356B8852EB751E20C13A72FBCA03393CF682B8483509573">>}, {<<"getopt">>, <<"B17556DB683000BA50370B16C0619DF1337E7AF7ECBF7D64FBF8D1D6BCE3109B">>}, 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), -- cgit v1.1 From c3f336763f3f65babcdfe8c1faedb5ca9eff2a8c Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sun, 26 Jun 2016 21:03:03 -0400 Subject: Fix invalid template value Used a nonexisting option instead of a correct one --- priv/templates/escript_rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/templates/escript_rebar.config b/priv/templates/escript_rebar.config index 196f835..ef498a8 100644 --- a/priv/templates/escript_rebar.config +++ b/priv/templates/escript_rebar.config @@ -3,7 +3,7 @@ {escript_incl_apps, [{{name}}]}. -{escript_top_level_app, {{name}}}. +{escript_main_app, {{name}}}. {escript_name, {{name}}}. {escript_emu_args, "%%! +sbtu +A0\n"}. -- cgit v1.1