From 51f98b5bf45ffcb94766539b4f8a6256bc9267f0 Mon Sep 17 00:00:00 2001 From: Pablo Costas Date: Wed, 18 Mar 2020 10:55:12 +0100 Subject: [PATCH] Return an error if no apps are found when using bare compiler Would close erlang#2202. In case of no apps found when calling `rebar_state:project_apps(State)` rebar3 now throws an error with a warning. --- src/rebar_prv_bare_compile.erl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/rebar_prv_bare_compile.erl b/src/rebar_prv_bare_compile.erl index f458dd4d..0ad20917 100644 --- a/src/rebar_prv_bare_compile.erl +++ b/src/rebar_prv_bare_compile.erl @@ -57,16 +57,26 @@ do(State) -> [ code:add_pathsa(filelib:wildcard(PathWildcard)) || PathWildcard <- rebar_string:lexemes(Paths, Sep) ], - [AppInfo] = rebar_state:project_apps(State), - AppInfo1 = rebar_app_info:out_dir(AppInfo, OutDir), + case rebar_state:project_apps(State) of + [] -> + {error, {?MODULE, {not_an_application_structure, OutDir}}}; + [AppInfo] -> + AppInfo1 = rebar_app_info:out_dir(AppInfo, OutDir), - %% run compile in the default namespace - rebar_prv_compile:compile(rebar_state:namespace(State, default), AppInfo1), + %% run compile in the default namespace + rebar_prv_compile:compile(rebar_state:namespace(State, default), AppInfo1), - rebar_utils:cleanup_code_path(OrigPath), + rebar_utils:cleanup_code_path(OrigPath), - {ok, State}. + {ok, State} + end. -spec format_error(any()) -> iolist(). +format_error({not_an_application_structure, Path}) -> + io_lib:format( + "Compilation failed: there is no code in this directory (~ts), " ++ + "it is unreadable or for some other reason " ++ + "is not a recognizable application structure.", + [Path]); format_error(Reason) -> io_lib:format("~p", [Reason]).