Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and report missing escript dependency #2532

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rebar_prv_escriptize.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ do(State) ->
_ ->
AppInfo1 = rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, AppInfo0, State),
?INFO("Building escript for ~s...", [rebar_app_info:name(AppInfo0)]),
Res = escriptize(State, AppInfo1),
Res = try
escriptize(State, AppInfo1)
catch
throw:Err=?PRV_ERROR(_) -> Err
end,
rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, AppInfo1, State),
Res
end.
Expand Down Expand Up @@ -165,6 +169,8 @@ format_error({zip_error, AppName, ZipError}) ->
format_error({bad_name, App}) ->
io_lib:format("Failed to get ebin/ directory for "
"escript_incl_app: ~p", [App]);
format_error({bad_app, App}) ->
io_lib:format("Failed to find application ~p", [App]);
format_error(no_main_app) ->
io_lib:format("Multiple project apps and {escript_main_app, atom()}."
" not set in rebar.config", []).
Expand Down Expand Up @@ -260,7 +266,10 @@ find_deps(AppNames, AllApps) ->
find_deps_of_deps([], _, Acc) -> Acc;
find_deps_of_deps([Name|Names], Apps, Acc) ->
?DIAGNOSTIC("processing ~p", [Name]),
{ok, App} = rebar_app_utils:find(Name, Apps),
App = case rebar_app_utils:find(Name, Apps) of
{ok, Found} -> Found;
error -> throw(?PRV_ERROR({bad_app, binary_to_atom(Name, utf8)}))
end,
DepNames = proplists:get_value(applications, rebar_app_info:app_details(App), []),
BinDepNames = [rebar_utils:to_binary(Dep) || Dep <- DepNames,
%% ignore system libs; shouldn't include them.
Expand Down
11 changes: 11 additions & 0 deletions test/rebar_escriptize_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
all/0,
escriptize_with_name/1,
escriptize_with_bad_name/1,
escriptize_with_bad_dep/1,
build_and_clean_app/1,
escriptize_with_ebin_subdir/1]).

Expand All @@ -31,6 +32,7 @@ all() ->
build_and_clean_app,
escriptize_with_name,
escriptize_with_bad_name,
escriptize_with_bad_dep,
escriptize_with_ebin_subdir
].

Expand Down Expand Up @@ -62,6 +64,15 @@ escriptize_with_bad_name(Config) ->
rebar_test_utils:run_and_check(Config, [{escript_main_app, boogers}], ["escriptize"],
{error,{rebar_prv_escriptize, {bad_name, boogers}}}).

escriptize_with_bad_dep(Config) ->
AppDir = ?config(apps, Config),

Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib, boogers]),
rebar_test_utils:run_and_check(Config, [{escript_main_app, Name}], ["escriptize"],
{error,{rebar_prv_escriptize, {bad_app, boogers}}}).

escriptize_with_ebin_subdir(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
Expand Down