summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2014-10-16 21:43:44 -0500
committerTristan Sloughter <t@crashfast.com>2014-10-16 21:44:02 -0500
commitfa74056d2ac7add49397615cde8b5591f3c36bf6 (patch)
treea38a3104420ca5aa0c8ca7f37f27024fb9fdd591 /src
parent141d34a5d01216b7e918b07c22ee998766217b6d (diff)
test deps support, but builds them after project apps currently
Diffstat (limited to 'src')
-rw-r--r--src/rebar.app.src1
-rw-r--r--src/rebar_app_discover.erl5
-rw-r--r--src/rebar_prv_install_deps.erl6
-rw-r--r--src/rebar_prv_test_deps.erl55
-rw-r--r--src/rebar_utils.erl10
5 files changed, 71 insertions, 6 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src
index 2ede1db..e7cbcd1 100644
--- a/src/rebar.app.src
+++ b/src/rebar.app.src
@@ -25,6 +25,7 @@
rebar_prv_deps,
rebar_prv_do,
rebar_prv_lock,
+ rebar_prv_test_deps,
rebar_prv_install_deps,
rebar_prv_packages,
rebar_erlydtl_compiler,
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 147bc92..a51252e 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -111,7 +111,10 @@ create_app_info(AppDir, AppFile) ->
case file:consult(AppFile) of
{ok, [{application, AppName, AppDetails}]} ->
AppVsn = proplists:get_value(vsn, AppDetails),
- AppDeps = proplists:get_value(applications, AppDetails, []),
+ %AppDeps = proplists:get_value(applications, AppDetails, []),
+ C = rebar_config:consult(AppDir),
+ S = rebar_state:new(rebar_state:new(), C, AppDir),
+ AppDeps = rebar_state:deps_names(S),
AbsCwd = filename:absname(rebar_utils:get_cwd()),
{ok, AppInfo} = rebar_app_info:new(AppName, AppVsn, AppDir, AppDeps),
RebarConfig = filename:join(AppDir, "rebar.config"),
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index a717e5f..654a5fb 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -77,7 +77,7 @@ do(State) ->
Source = ProjectApps ++ rebar_state:src_apps(State1),
case rebar_topo:sort_apps(Source) of
{ok, Sort} ->
- {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))};
+ {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun rebar_app_info:valid/1, Sort -- ProjectApps))};
{error, Error} ->
{error, Error}
end.
@@ -137,10 +137,6 @@ handle_deps(State, Deps, Update) ->
%% Internal functions
%% ===================================================================
--spec is_valid(rebar_app_info:t()) -> boolean().
-is_valid(App) ->
- rebar_app_info:valid(App).
-
-spec package_to_app(file:filename_all(), rebar_dict(),
rlx_depsolver:pkg()) -> [rebar_app_info:t()].
package_to_app(DepsDir, Packages, Pkg={_, Vsn}) ->
diff --git a/src/rebar_prv_test_deps.erl b/src/rebar_prv_test_deps.erl
new file mode 100644
index 0000000..7dea0ab
--- /dev/null
+++ b/src/rebar_prv_test_deps.erl
@@ -0,0 +1,55 @@
+-module(rebar_prv_test_deps).
+
+-behaviour(provider).
+
+-export([init/1,
+ do/1]).
+
+-include("rebar.hrl").
+
+-define(PROVIDER, test_deps).
+-define(DEPS, [install_deps]).
+
+%% ===================================================================
+%% Public API
+%% ===================================================================
+
+-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
+init(State) ->
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, undefined},
+ {short_desc, "Install dependencies needed only for testing."},
+ {desc, ""},
+ {opts, []}])),
+ {ok, State1}.
+
+-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
+do(State) ->
+ ProjectApps = rebar_state:project_apps(State),
+ TestDeps = rebar_state:get(State, test_deps, []),
+ Names = [ec_cnv:to_binary(element(1, Dep)) || Dep <- TestDeps],
+ ProjectApps1 = [rebar_app_info:deps(A, Names) || A <- ProjectApps],
+
+ {ok, State1} = rebar_prv_install_deps:handle_deps(State, TestDeps),
+ AllDeps = rebar_state:get(State1, all_deps, []),
+
+ case rebar_topo:sort_apps(ProjectApps1++AllDeps) of
+ {ok, Sort} ->
+ ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Sort),
+ lists:foreach(fun(AppInfo) ->
+ AppDir = rebar_app_info:dir(AppInfo),
+ C = rebar_config:consult(AppDir),
+ S = rebar_state:new(State1, C, AppDir),
+ rebar_prv_compile:build(S, AppInfo)
+ end, ToBuild),
+ {ok, State1};
+ {error, Error} ->
+ {error, Error}
+ end.
+
+%% ===================================================================
+%% Internal functions
+%% ===================================================================
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 5661501..87387be 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -32,6 +32,8 @@
is_arch/1,
sh/2,
sh_send/3,
+ abort/0,
+ abort/2,
escript_foldl/3,
find_files/2,
find_files/3,
@@ -408,6 +410,14 @@ beams(Dir) ->
filelib:fold_files(Dir, ".*\.beam\$", true,
fun(F, Acc) -> [F | Acc] end, []).
+-spec abort() -> no_return().
+abort() ->
+ throw(rebar_abort).
+-spec abort(string(), [term()]) -> no_return().
+abort(String, Args) ->
+ ?ERROR(String, Args),
+ abort().
+
escript_foldl(Fun, Acc, File) ->
case escript:extract(File, [compile_source]) of
{ok, [_Shebang, _Comment, _EmuArgs, Body]} ->