summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rebar.hrl1
-rw-r--r--src/rebar_app_discover.erl95
-rw-r--r--src/rebar_app_info.erl17
-rw-r--r--src/rebar_base_compiler.erl4
-rw-r--r--src/rebar_core.erl8
-rw-r--r--src/rebar_deps.erl70
-rw-r--r--src/rebar_prv_app_discovery.erl2
7 files changed, 114 insertions, 83 deletions
diff --git a/include/rebar.hrl b/include/rebar.hrl
index 9452633..bc74b59 100644
--- a/include/rebar.hrl
+++ b/include/rebar.hrl
@@ -24,5 +24,6 @@
opts :: list()}). % The list of options that the task requires/understands
-define(DEFAULT_LIB_DIRS, ["apps", "libs", "."]).
+-define(DEFAULT_DEPS_DIRS, ["deps"]).
-define(DEFAULT_CONFIG_FILE, "rebar.config").
-define(LOCK_FILE, "rebar.lock").
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl
index 9e9a108..d4c904d 100644
--- a/src/rebar_app_discover.erl
+++ b/src/rebar_app_discover.erl
@@ -1,10 +1,12 @@
-module(rebar_app_discover).
-export([do/2,
- find_apps/1]).
+ find_unbuilt_apps/1,
+ find_apps/1,
+ find_apps/2]).
do(State, LibDirs) ->
- Apps = find_apps(LibDirs),
+ Apps = find_apps(LibDirs, all),
lists:foldl(fun(AppInfo, StateAcc) ->
rebar_state:add_app(StateAcc, AppInfo)
end, State, Apps).
@@ -37,27 +39,56 @@ app_dirs(LibDir) ->
[app_dir(File) || File <- Files] ++ Acc
end, [], [Path1, Path2, Path3, Path4])).
+find_unbuilt_apps(LibDirs) ->
+ find_apps(LibDirs, invalid).
+
find_apps(LibDirs) ->
- lists:map(fun(AppDir) ->
+ find_apps(LibDirs, valid).
+
+find_apps(LibDirs, Validate) ->
+ lists:filtermap(fun(AppDir) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),
case AppFile of
[File] ->
AppInfo = create_app_info(AppDir, File),
AppInfo1 = rebar_app_info:app_file(AppInfo, File),
- case AppSrcFile of
- [F] ->
- rebar_app_info:app_file_src(AppInfo1, F);
- [] ->
- AppInfo1
+ AppInfo2 = case AppSrcFile of
+ [F] ->
+ rebar_app_info:app_file_src(AppInfo1, F);
+ [] ->
+ AppInfo1
+ end,
+ case Validate of
+ valid ->
+ case validate_application_info(AppInfo2) of
+ true ->
+ {true, AppInfo2};
+ false ->
+ false
+ end;
+ invalid ->
+ case validate_application_info(AppInfo2) of
+ false ->
+ {true, AppInfo2};
+ true ->
+ false
+ end;
+ all ->
+ {true, AppInfo2}
end;
[] ->
case AppSrcFile of
[File] ->
- AppInfo = create_app_info(AppDir, File),
- rebar_app_info:app_file_src(AppInfo, File);
+ case Validate of
+ V when V =:= invalid ; V =:= all ->
+ AppInfo = create_app_info(AppDir, File),
+ {true, rebar_app_info:app_file_src(AppInfo, File)};
+ valid ->
+ false
+ end;
[] ->
- error
+ false
end
end
end, all_app_dirs(LibDirs)).
@@ -80,6 +111,46 @@ create_app_info(AppDir, AppFile) ->
rebar_state:new()
end,
AppState1 = rebar_state:set(AppState, base_dir, AbsCwd),
- AppInfo1 = rebar_app_info:config(AppInfo, AppState1),
+ AppInfo1 = rebar_app_info:config(
+ rebar_app_info:app_details(AppInfo, AppDetails), AppState1),
rebar_app_info:dir(AppInfo1, AppDir)
end.
+-spec validate_application_info(rebar_app_info:t()) -> boolean().
+validate_application_info(AppInfo) ->
+ EbinDir = rebar_app_info:ebin_dir(AppInfo),
+ AppFile = rebar_app_info:app_file(AppInfo),
+ AppName = rebar_app_info:app_details(AppInfo),
+ AppDetail = rebar_app_info:app_details(AppInfo),
+ AppDir = filename:dirname(EbinDir),
+ case get_modules_list(AppFile, AppDetail) of
+ {ok, List} ->
+ has_all_beams(EbinDir, List);
+ _Error ->
+ false
+ end.
+
+-spec get_modules_list(file:name(), proplists:proplist()) ->
+ {ok, list()} |
+ {warning, Reason::term()} |
+ {error, Reason::term()}.
+get_modules_list(AppFile, AppDetail) ->
+ case proplists:get_value(modules, AppDetail) of
+ undefined ->
+ {warning, {invalid_app_file, AppFile}};
+ ModulesList ->
+ {ok, ModulesList}
+ end.
+
+-spec has_all_beams(file:name(), list()) ->
+ ok | {error, Reason::term()}.
+has_all_beams(EbinDir, [Module | ModuleList]) ->
+ BeamFile = filename:join([EbinDir,
+ list_to_binary(atom_to_list(Module) ++ ".beam")]),
+ case filelib:is_file(BeamFile) of
+ true ->
+ has_all_beams(EbinDir, ModuleList);
+ false ->
+ false
+ end;
+has_all_beams(_, []) ->
+ true.
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl
index 89307ad..72a4a97 100644
--- a/src/rebar_app_info.erl
+++ b/src/rebar_app_info.erl
@@ -10,8 +10,11 @@
app_file_src/2,
app_file/1,
app_file/2,
+ app_details/1,
+ app_details/2,
original_vsn/1,
original_vsn/2,
+ ebin_dir/1,
dir/1,
dir/2]).
@@ -22,6 +25,7 @@
app_file :: file:name(),
config :: rebar_config:config() | undefined,
original_vsn :: string(),
+ app_details :: list(),
dir :: file:name(),
source :: string() | undefined}).
@@ -81,6 +85,14 @@ app_file(#app_info_t{app_file=AppFile}) ->
app_file(AppInfo=#app_info_t{}, AppFile) ->
AppInfo#app_info_t{app_file=AppFile}.
+-spec app_details(t()) -> list().
+app_details(#app_info_t{app_details=AppDetails}) ->
+ AppDetails.
+
+-spec app_details(t(), list()) -> t().
+app_details(AppInfo=#app_info_t{}, AppDetails) ->
+ AppInfo#app_info_t{app_details=AppDetails}.
+
-spec original_vsn(t()) -> string().
original_vsn(#app_info_t{original_vsn=Vsn}) ->
Vsn.
@@ -92,6 +104,11 @@ original_vsn(AppInfo=#app_info_t{}, Vsn) ->
-spec dir(t()) -> file:name().
dir(#app_info_t{dir=Dir}) ->
Dir.
+
-spec dir(t(), file:name()) -> t().
dir(AppInfo=#app_info_t{}, Dir) ->
AppInfo#app_info_t{dir=Dir}.
+
+-spec ebin_dir(t()) -> file:name().
+ebin_dir(#app_info_t{dir=Dir}) ->
+ filename:join(Dir, "ebin").
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index bf08ee6..e4e4b79 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -173,11 +173,11 @@ compile_queue(Config, Pids, Targets) ->
{compiled, Source, Warnings} ->
report(Warnings),
- ?CONSOLE("Compiled ~s\n", [Source]),
+ ?INFO("Compiled ~s\n", [Source]),
compile_queue(Config, Pids, Targets);
{compiled, Source} ->
- ?CONSOLE("Compiled ~s\n", [Source]),
+ ?INFO("Compiled ~s\n", [Source]),
compile_queue(Config, Pids, Targets);
{skipped, Source} ->
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index f366b84..a146cce 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -37,17 +37,17 @@
process_command(State, Command) ->
true = rebar_utils:expand_code_path(),
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
- DepsDir = rebar_state:get(State, deps_dir, "deps"),
+ DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIRS),
_UpdatedCodePaths = update_code_path([DepsDir | LibDirs]),
rebar_deps:setup_env(State),
- State2 = rebar_app_discover:do(State, LibDirs),
- TargetProviders = rebar_provider:get_target_providers(Command, State2),
+
+ TargetProviders = rebar_provider:get_target_providers(Command, State),
lists:foldl(fun(TargetProvider, Conf) ->
Provider = rebar_provider:get_provider(TargetProvider, rebar_state:providers(Conf)),
{ok, Conf1} = rebar_provider:do(Provider, Conf),
Conf1
- end, State2, TargetProviders).
+ end, State, TargetProviders).
update_code_path([]) ->
no_change;
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index e52ed91..bb7f33f 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -79,12 +79,13 @@ update_deps(Config, Deps) ->
DepsDir = get_deps_dir(Config),
%% Find available apps to fulfill dependencies
+ UnbuiltApps = rebar_app_discover:find_unbuilt_apps([DepsDir]),
FoundApps = rebar_app_discover:find_apps([DepsDir]),
%% Resolve deps and their dependencies
- Deps1 = handle_deps(Deps, FoundApps),
+ Deps1 = handle_deps(Deps, UnbuiltApps++FoundApps),
- case download_missing_deps(Config, DepsDir, FoundApps, Deps1) of
+ case download_missing_deps(Config, DepsDir, FoundApps, UnbuiltApps, Deps1) of
{Config1, []} ->
{Config1, Deps1};
{Config1, _} ->
@@ -106,12 +107,11 @@ handle_deps(Deps, Found) ->
element(1, A) =:= element(1, B)
end, lists:usort(Deps), lists:usort(NewDeps1)).
-download_missing_deps(Config, DepsDir, Found, Deps) ->
- Apps = rebar_state:apps_to_build(Config),
+download_missing_deps(Config, DepsDir, Found, Unbuilt, Deps) ->
Missing = lists:filter(fun(X) ->
not lists:any(fun(F) ->
element(1, X) =:= element(2, F)
- end, Found++Apps)
+ end, Found++Unbuilt)
end, Deps),
ec_plists:foreach(fun(X) ->
TargetDir = get_deps_dir(DepsDir, element(1, X)),
@@ -125,7 +125,7 @@ download_missing_deps(Config, DepsDir, Found, Deps) ->
Config1 = lists:foldl(fun(X, ConfigAcc) ->
TargetDir = get_deps_dir(DepsDir, element(1, X)),
- [AppSrc] = rebar_app_discover:find_apps([TargetDir]),
+ [AppSrc] = rebar_app_discover:find_unbuilt_apps([TargetDir]),
rebar_state:add_app(ConfigAcc, AppSrc)
end, Config, Missing),
@@ -161,64 +161,6 @@ get_deps_dir(DepsDir, App) ->
%% Internal functions
%% ===================================================================
-
--spec gather_application_info(file:name(), file:filename()) ->
- {ok, rebar_app_info:t()} |
- {warning, Reason::term()} |
- {error, Reason::term()}.
-gather_application_info(EbinDir, File) ->
- AppDir = filename:dirname(EbinDir),
- case file:consult(File) of
- {ok, [{application, AppName, AppDetail}]} ->
- validate_application_info(EbinDir, File, AppName, AppDetail);
- {error, Reason} ->
- {warning, {unable_to_load_app, AppDir, Reason}};
- _ ->
- {warning, {invalid_app_file, File}}
- end.
-
--spec validate_application_info(file:name(),
- file:name(),
- atom(),
- proplists:proplist()) ->
- {ok, list()} |
- {warning, Reason::term()} |
- {error, Reason::term()}.
-validate_application_info(EbinDir, AppFile, AppName, AppDetail) ->
- AppDir = filename:dirname(EbinDir),
- case get_modules_list(AppFile, AppDetail) of
- {ok, List} ->
- has_all_beams(EbinDir, List);
- Error ->
- Error
- end.
-
--spec get_modules_list(file:name(), proplists:proplist()) ->
- {ok, list()} |
- {warning, Reason::term()} |
- {error, Reason::term()}.
-get_modules_list(AppFile, AppDetail) ->
- case proplists:get_value(modules, AppDetail) of
- undefined ->
- {warning, {invalid_app_file, AppFile}};
- ModulesList ->
- {ok, ModulesList}
- end.
-
--spec has_all_beams(file:name(), list()) ->
- ok | {error, Reason::term()}.
-has_all_beams(EbinDir, [Module | ModuleList]) ->
- BeamFile = filename:join([EbinDir,
- list_to_binary(atom_to_list(Module) ++ ".beam")]),
- case filelib:is_file(BeamFile) of
- true ->
- has_all_beams(EbinDir, ModuleList);
- false ->
- {warning, {missing_beam_file, Module, BeamFile}}
- end;
-has_all_beams(_, []) ->
- ok.
-
info(help, 'deps') ->
info_help("Display dependencies").
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index e3144aa..c1f5708 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -32,5 +32,5 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()}.
do(State) ->
LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS),
- State1 = rebar_app_discover:do(State, ["deps" | LibDirs]),
+ State1 = rebar_app_discover:do(State, LibDirs),
{ok, State1}.