summaryrefslogtreecommitdiff
path: root/src/rebar_app_info.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_app_info.erl')
-rw-r--r--src/rebar_app_info.erl61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl
index 008bfd2..7a33811 100644
--- a/src/rebar_app_info.erl
+++ b/src/rebar_app_info.erl
@@ -1,7 +1,6 @@
-module(rebar_app_info).
--export([new/0,
- new/1,
+-export([new/1,
new/2,
new/3,
new/4,
@@ -21,6 +20,8 @@
ebin_dir/1,
deps/1,
deps/2,
+ dep_level/1,
+ dep_level/2,
dir/1,
dir/2,
source/1,
@@ -31,43 +32,40 @@
-export_type([t/0]).
-record(app_info_t, {name :: binary(),
- app_file_src :: file:name() | undefined,
- app_file :: file:name(),
- config :: rebar_config:config() | undefined,
- original_vsn :: string(),
+ app_file_src :: file:filename_all() | undefined,
+ app_file :: file:filename_all() | undefined,
+ config :: rebar_state:t() | undefined,
+ original_vsn :: binary() | string() | undefined,
app_details=[] :: list(),
deps=[] :: list(),
+ dep_level :: integer(),
dir :: file:name(),
- source :: string() | undefined,
+ source :: string() | tuple() | undefined,
valid :: boolean()}).
%%============================================================================
%% types
%%============================================================================
--opaque t() :: record(app_info_t).
+-type t() :: record(app_info_t).
%%============================================================================
%% API
%% ============================================================================
%% @doc Build a new, empty, app info value. This is not of a lot of use and you
%% probably wont be doing this much.
--spec new() -> {ok, t()}.
-new() ->
- {ok, #app_info_t{}}.
-
-spec new(atom() | binary() | string()) ->
{ok, t()}.
new(AppName) ->
{ok, #app_info_t{name=ec_cnv:to_binary(AppName)}}.
--spec new(atom() | binary() | string(), string()) ->
+-spec new(atom() | binary() | string(), binary() | string()) ->
{ok, t()}.
new(AppName, Vsn) ->
{ok, #app_info_t{name=ec_cnv:to_binary(AppName),
original_vsn=Vsn}}.
%% @doc build a complete version of the app info with all fields set.
--spec new(atom() | binary() | string(), string(), file:name()) ->
+-spec new(atom() | binary() | string(), binary() | string(), file:name()) ->
{ok, t()}.
new(AppName, Vsn, Dir) ->
{ok, #app_info_t{name=ec_cnv:to_binary(AppName),
@@ -75,7 +73,7 @@ new(AppName, Vsn, Dir) ->
dir=Dir}}.
%% @doc build a complete version of the app info with all fields set.
--spec new(atom() | binary() | string(), string(), file:name(), list()) ->
+-spec new(atom() | binary() | string(), binary() | string(), file:name(), list()) ->
{ok, t()}.
new(AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=ec_cnv:to_binary(AppName),
@@ -84,17 +82,16 @@ new(AppName, Vsn, Dir, Deps) ->
deps=Deps}}.
%% @doc discover a complete version of the app info with all fields set.
--spec discover(file:name()) ->
- {ok, t()}.
+-spec discover(file:filename_all()) -> {ok, t()} | not_found.
discover(Dir) ->
case rebar_app_discover:find_app(Dir, all) of
{true, AppInfo} ->
{ok, AppInfo};
- _ ->
+ false ->
not_found
end.
--spec name(t()) -> atom().
+-spec name(t()) -> binary().
name(#app_info_t{name=Name}) ->
Name.
@@ -102,15 +99,15 @@ name(#app_info_t{name=Name}) ->
name(AppInfo=#app_info_t{}, AppName) ->
AppInfo#app_info_t{name=ec_cnv:to_binary(AppName)}.
--spec config(t()) -> rebar_config:confg().
+-spec config(t()) -> rebar_state:t().
config(#app_info_t{config=Config}) ->
Config.
--spec config(t(), rebar_config:confg()) -> t().
+-spec config(t(), rebar_state:t()) -> t().
config(AppInfo=#app_info_t{}, Config) ->
AppInfo#app_info_t{config=Config}.
--spec app_file_src(t()) -> file:name().
+-spec app_file_src(t()) -> file:filename_all() | undefined.
app_file_src(#app_info_t{app_file_src=undefined, dir=Dir, name=Name}) ->
AppFileSrc = filename:join([ec_cnv:to_list(Dir), "src", ec_cnv:to_list(Name)++".app.src"]),
case filelib:is_file(AppFileSrc) of
@@ -122,11 +119,11 @@ app_file_src(#app_info_t{app_file_src=undefined, dir=Dir, name=Name}) ->
app_file_src(#app_info_t{app_file_src=AppFileSrc}) ->
ec_cnv:to_list(AppFileSrc).
--spec app_file_src(t(), file:name()) -> t().
+-spec app_file_src(t(), file:filename_all()) -> t().
app_file_src(AppInfo=#app_info_t{}, AppFileSrc) ->
AppInfo#app_info_t{app_file_src=ec_cnv:to_list(AppFileSrc)}.
--spec app_file(t()) -> file:name().
+-spec app_file(t()) -> file:filename_all() | undefined.
app_file(#app_info_t{app_file=undefined, dir=Dir, name=Name}) ->
AppFile = filename:join([ec_cnv:to_list(Dir), "ebin", ec_cnv:to_list(Name)++".app"]),
case filelib:is_file(AppFile) of
@@ -138,9 +135,9 @@ app_file(#app_info_t{app_file=undefined, dir=Dir, name=Name}) ->
app_file(#app_info_t{app_file=AppFile}) ->
AppFile.
--spec app_file(t(), file:name()) -> t().
+-spec app_file(t(), file:filename_all()) -> t().
app_file(AppInfo=#app_info_t{}, AppFile) ->
- AppInfo#app_info_t{app_file=ec_cnv:to_list(AppFile)}.
+ AppInfo#app_info_t{app_file=AppFile}.
-spec app_details(t()) -> list().
app_details(#app_info_t{app_details=AppDetails}) ->
@@ -154,7 +151,7 @@ app_details(AppInfo=#app_info_t{}, AppDetails) ->
original_vsn(#app_info_t{original_vsn=Vsn}) ->
Vsn.
--spec original_vsn(t(), string()) -> string().
+-spec original_vsn(t(), string()) -> t().
original_vsn(AppInfo=#app_info_t{}, Vsn) ->
AppInfo#app_info_t{original_vsn=Vsn}.
@@ -166,6 +163,12 @@ deps(#app_info_t{deps=Deps}) ->
deps(AppInfo=#app_info_t{}, Deps) ->
AppInfo#app_info_t{deps=Deps}.
+dep_level(AppInfo=#app_info_t{}, Level) ->
+ AppInfo#app_info_t{dep_level=Level}.
+
+dep_level(#app_info_t{dep_level=Level}) ->
+ Level.
+
-spec dir(t()) -> file:name().
dir(#app_info_t{dir=Dir}) ->
Dir.
@@ -178,11 +181,11 @@ dir(AppInfo=#app_info_t{}, Dir) ->
ebin_dir(#app_info_t{dir=Dir}) ->
filename:join(Dir, "ebin").
--spec source(t(), string()) -> t().
+-spec source(t(), string() | tuple()) -> t().
source(AppInfo=#app_info_t{}, Source) ->
AppInfo#app_info_t{source=Source}.
--spec source(t()) -> string().
+-spec source(t()) -> string() | tuple().
source(#app_info_t{source=Source}) ->
Source.