mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Refactoring app file access to be via rebar_app_utils in prep for supporting .app.src
This commit is contained in:
parent
87bca27644
commit
c19b8ac003
5 changed files with 52 additions and 23 deletions
|
@ -27,7 +27,11 @@
|
||||||
-module(rebar_app_utils).
|
-module(rebar_app_utils).
|
||||||
|
|
||||||
-export([is_app_dir/0, is_app_dir/1,
|
-export([is_app_dir/0, is_app_dir/1,
|
||||||
load_app_file/1]).
|
app_name/1,
|
||||||
|
app_applications/1,
|
||||||
|
app_vsn/1]).
|
||||||
|
|
||||||
|
-export([load_app_file/1]). % TEMPORARY
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
|
@ -47,14 +51,45 @@ is_app_dir(Dir) ->
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
app_name(AppFile) ->
|
||||||
|
case load_app_file(AppFile) of
|
||||||
|
{ok, AppName, _} ->
|
||||||
|
AppName;
|
||||||
|
{error, Reason} ->
|
||||||
|
?ABORT("Failed to extract name from ~s: ~p\n",
|
||||||
|
[AppFile, Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
|
app_applications(AppFile) ->
|
||||||
|
case load_app_file(AppFile) of
|
||||||
|
{ok, _, AppInfo} ->
|
||||||
|
proplists:get_value(applications, AppInfo);
|
||||||
|
{error, Reason} ->
|
||||||
|
?ABORT("Failed to extract applications from ~s: ~p\n",
|
||||||
|
[AppFile, Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
|
app_vsn(AppFile) ->
|
||||||
|
case load_app_file(AppFile) of
|
||||||
|
{ok, _, AppInfo} ->
|
||||||
|
proplists:get_value(vsn, AppInfo);
|
||||||
|
{error, Reason} ->
|
||||||
|
?ABORT("Failed to extract vsn from ~s: ~p\n",
|
||||||
|
[AppFile, Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%% ===================================================================
|
||||||
|
%% Internal functions
|
||||||
|
%% ===================================================================
|
||||||
|
|
||||||
load_app_file(Filename) ->
|
load_app_file(Filename) ->
|
||||||
case file:consult(Filename) of
|
case file:consult(Filename) of
|
||||||
{ok, [{application, AppName, AppData}]} ->
|
{ok, [{application, AppName, AppData}]} ->
|
||||||
{ok, AppName, AppData};
|
{ok, AppName, AppData};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ERROR("Failed to load app file from ~s: ~p\n", [Filename, Reason]),
|
{error, Reason};
|
||||||
?FAIL;
|
|
||||||
Other ->
|
Other ->
|
||||||
?ERROR("Unexpected terms from app file ~s: ~p\n", [Filename, Other]),
|
{error, {unexpected_terms, Other}}
|
||||||
?FAIL
|
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -195,9 +195,9 @@ is_app_available(App, VsnRegex) ->
|
||||||
is_app_available(App, VsnRegex, Path) ->
|
is_app_available(App, VsnRegex, Path) ->
|
||||||
case rebar_app_utils:is_app_dir(Path) of
|
case rebar_app_utils:is_app_dir(Path) of
|
||||||
{true, AppFile} ->
|
{true, AppFile} ->
|
||||||
case rebar_app_utils:load_app_file(AppFile) of
|
case rebar_app_utils:app_name(AppFile) of
|
||||||
{ok, App, AppData} ->
|
App ->
|
||||||
{vsn, Vsn} = lists:keyfind(vsn, 1, AppData),
|
Vsn = rebar_app_utils:app_vsn(AppFile),
|
||||||
?INFO("Looking for ~s-~s ; found ~s-~s at ~s\n",
|
?INFO("Looking for ~s-~s ; found ~s-~s at ~s\n",
|
||||||
[App, VsnRegex, App, Vsn, Path]),
|
[App, VsnRegex, App, Vsn, Path]),
|
||||||
case re:run(Vsn, VsnRegex, [{capture, none}]) of
|
case re:run(Vsn, VsnRegex, [{capture, none}]) of
|
||||||
|
@ -208,11 +208,9 @@ is_app_available(App, VsnRegex, Path) ->
|
||||||
[AppFile, Vsn, VsnRegex]),
|
[AppFile, Vsn, VsnRegex]),
|
||||||
false
|
false
|
||||||
end;
|
end;
|
||||||
{ok, OtherApp, _} ->
|
OtherApp ->
|
||||||
?WARN("~s has application id ~p; expected ~p\n", [AppFile, OtherApp, App]),
|
?WARN("~s has application id ~p; expected ~p\n", [AppFile, OtherApp, App]),
|
||||||
false;
|
false
|
||||||
{error, Reason} ->
|
|
||||||
?ABORT("Failed to parse ~s: ~p\n", [AppFile, Reason])
|
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
?WARN("Expected ~s to be an app dir (containing ebin/*.app), but no .app found.\n",
|
?WARN("Expected ~s to be an app dir (containing ebin/*.app), but no .app found.\n",
|
||||||
|
|
|
@ -85,8 +85,7 @@ analyze(Config, File) ->
|
||||||
build_plt(Config, File) ->
|
build_plt(Config, File) ->
|
||||||
Plt = plt_path(Config, File),
|
Plt = plt_path(Config, File),
|
||||||
|
|
||||||
{ok, _AppName, AppData} = rebar_app_utils:load_app_file(File),
|
Apps = rebar_app_utils:app_applications(File),
|
||||||
Apps = proplists:get_value(applications, AppData),
|
|
||||||
|
|
||||||
Warnings = dialyzer:run([{analysis_type, plt_build},
|
Warnings = dialyzer:run([{analysis_type, plt_build},
|
||||||
{files_rec, app_dirs(Apps)},
|
{files_rec, app_dirs(Apps)},
|
||||||
|
@ -140,7 +139,7 @@ output_warnings(Warnings) ->
|
||||||
%% @spec plt_path(Config::#config{}, File::string()) -> string()
|
%% @spec plt_path(Config::#config{}, File::string()) -> string()
|
||||||
-spec(plt_path(Config::#config{}, File::string()) -> string()).
|
-spec(plt_path(Config::#config{}, File::string()) -> string()).
|
||||||
plt_path(Config, File) ->
|
plt_path(Config, File) ->
|
||||||
{ok, AppName, _AppData} = rebar_app_utils:load_app_file(File),
|
AppName = rebar_app_utils:app_name(File),
|
||||||
DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []),
|
DialyzerOpts = rebar_config:get(Config, dialyzer_opts, []),
|
||||||
case proplists:get_value(plt, DialyzerOpts) of
|
case proplists:get_value(plt, DialyzerOpts) of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
escriptize(_Config, AppFile) ->
|
escriptize(_Config, AppFile) ->
|
||||||
%% Extract the application name from the archive -- this will be be what
|
%% Extract the application name from the archive -- this will be be what
|
||||||
%% we call the output script
|
%% we call the output script
|
||||||
{ok, AppName, _AppData} = rebar_app_utils:load_app_file(AppFile),
|
AppName = rebar_app_utils:app_name(AppFile),
|
||||||
|
|
||||||
%% Construct the archive of everything in ebin/ dir -- put it on the
|
%% Construct the archive of everything in ebin/ dir -- put it on the
|
||||||
%% top-level of the zip file so that code loading works properly.
|
%% top-level of the zip file so that code loading works properly.
|
||||||
|
|
|
@ -325,12 +325,9 @@ so_name(Config, AppFile) ->
|
||||||
undefined ->
|
undefined ->
|
||||||
%% Get the app name, which we'll use to
|
%% Get the app name, which we'll use to
|
||||||
%% generate the linked port driver name
|
%% generate the linked port driver name
|
||||||
case rebar_app_utils:load_app_file(AppFile) of
|
AppName = rebar_app_utils:app_name(AppFile),
|
||||||
{ok, AppName, _} ->
|
lists:concat([AppName, "_drv.so"]);
|
||||||
lists:concat([AppName, "_drv.so"]);
|
|
||||||
error ->
|
|
||||||
?FAIL
|
|
||||||
end;
|
|
||||||
Soname ->
|
Soname ->
|
||||||
Soname
|
Soname
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in a new issue