summaryrefslogtreecommitdiff
path: root/src/rebar_app_utils.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_app_utils.erl')
-rw-r--r--src/rebar_app_utils.erl107
1 files changed, 29 insertions, 78 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index 2b63519..cd1124a 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -28,13 +28,13 @@
-export([find/2,
find/3,
- is_app_dir/0, is_app_dir/1,
is_app_src/1,
app_src_to_app/1,
- load_app_file/2,
- app_vsn/2]).
+ validate_application_info/1,
+ validate_application_info/2]).
-include("rebar.hrl").
+-include_lib("providers/include/providers.hrl").
%% ===================================================================
%% Public API
@@ -51,35 +51,6 @@ find(Name, Vsn, Apps) ->
andalso rebar_app_info:original_vsn(App) =:= Vsn
end, Apps).
--spec is_app_dir() -> {true, file:name()} | false.
-is_app_dir() ->
- is_app_dir(rebar_dir:get_cwd()).
-
--spec is_app_dir(file:name()) -> {true, file:name()} | false.
-is_app_dir(Dir) ->
- SrcDir = filename:join([Dir, "src"]),
- AppSrc = filename:join([SrcDir, "*.app.src"]),
- case filelib:wildcard(AppSrc) of
- [AppSrcFile] ->
- {true, AppSrcFile};
- [] ->
- EbinDir = filename:join([Dir, "ebin"]),
- App = filename:join([EbinDir, "*.app"]),
- case filelib:wildcard(App) of
- [AppFile] ->
- {true, AppFile};
- [] ->
- false;
- _ ->
- ?ERROR("More than one .app file in ~s~n", [EbinDir]),
- false
- end;
- _ ->
- ?ERROR("More than one .app.src file in ~s~n", [SrcDir]),
- false
- end.
-
-
is_app_src(Filename) ->
%% If removing the extension .app.src yields a shorter name,
%% this is an .app.src file.
@@ -91,58 +62,38 @@ app_src_to_app(Filename) ->
filelib:ensure_dir(AppFile),
AppFile.
-app_vsn(Config, AppFile) ->
- case load_app_file(Config, AppFile) of
- {ok, Config1, _, AppInfo} ->
- AppDir = filename:dirname(filename:dirname(AppFile)),
- rebar_utils:vcs_vsn(Config1, get_value(vsn, AppInfo, AppFile),
- AppDir);
- {error, Reason} ->
- ?ABORT("Failed to extract vsn from ~s: ~p\n",
- [AppFile, Reason])
- end.
+-spec validate_application_info(rebar_app_info:t()) -> boolean().
+validate_application_info(AppInfo) ->
+ validate_application_info(AppInfo, rebar_app_info:app_details(AppInfo)).
-load_app_file(_State, undefined) -> {error, missing_app_file};
-load_app_file(State, Filename) ->
- AppFile = {app_file, Filename},
- case rebar_state:get(State, {appfile, AppFile}, undefined) of
+validate_application_info(AppInfo, AppDetail) ->
+ EbinDir = rebar_app_info:ebin_dir(AppInfo),
+ case rebar_app_info:app_file(AppInfo) of
undefined ->
- case consult_app_file(Filename) of
- {ok, [{application, AppName, AppData}]} ->
- State1 = rebar_state:set(State,
- {appfile, AppFile},
- {AppName, AppData}),
- {ok, State1, AppName, AppData};
- {error, _} = Error ->
- Error;
- Other ->
- {error, {unexpected_terms, Other}}
- end;
- {AppName, AppData} ->
- {ok, State, AppName, AppData}
+ false;
+ AppFile ->
+ case proplists:get_value(modules, AppDetail) of
+ undefined ->
+ ?PRV_ERROR({module_list, AppFile});
+ List ->
+ has_all_beams(EbinDir, List)
+
+ end
end.
%% ===================================================================
%% Internal functions
%% ===================================================================
-%% In the case of *.app.src we want to give the user the ability to
-%% dynamically script the application resource file (think dynamic version
-%% string, etc.), in a way similar to what can be done with the rebar
-%% config. However, in the case of *.app, rebar should not manipulate
-%% that file. This enforces that dichotomy between app and app.src.
-consult_app_file(Filename) ->
- case lists:suffix(".app.src", Filename) of
- false ->
- file:consult(Filename);
+-spec has_all_beams(file:filename_all(), list()) -> true | providers:error().
+has_all_beams(EbinDir, [Module | ModuleList]) ->
+ BeamFile = filename:join([EbinDir,
+ ec_cnv:to_list(Module) ++ ".beam"]),
+ case filelib:is_file(BeamFile) of
true ->
- {ok, rebar_config:consult_file(Filename)}
- end.
-
-get_value(Key, AppInfo, AppFile) ->
- case proplists:get_value(Key, AppInfo) of
- undefined ->
- ?ABORT("Failed to get app value '~p' from '~s'~n", [Key, AppFile]);
- Value ->
- Value
- end.
+ has_all_beams(EbinDir, ModuleList);
+ false ->
+ ?PRV_ERROR({missing_module, Module})
+ end;
+has_all_beams(_, []) ->
+ true.