diff options
-rw-r--r-- | src/rebar_app_discover.erl | 1 | ||||
-rw-r--r-- | src/rebar_app_utils.erl | 14 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 19 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 7 |
4 files changed, 29 insertions, 12 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index c90a8df..7aaba21 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -55,6 +55,7 @@ find_apps(LibDirs, Validate) -> find_app(AppDir, Validate) end, all_app_dirs(LibDirs)). +-spec find_app(list(), boolean()) -> rebar_app_info:t() | false. find_app(AppDir, Validate) -> AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 1c53743..8c78850 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -26,7 +26,8 @@ %% ------------------------------------------------------------------- -module(rebar_app_utils). --export([is_app_dir/0, is_app_dir/1, +-export([find/2, + is_app_dir/0, is_app_dir/1, is_app_src/1, app_src_to_app/1, app_name/2, @@ -42,6 +43,17 @@ %% Public API %% =================================================================== +-spec find(binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. +find(Name, Apps) -> + ec_lists:find(fun(App) -> rebar_app_info:name(App) =:= Name end, Apps). + +-spec find(binary(), binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. +find(Name, Vsn, Apps) -> + ec_lists:find(fun(App) -> + rebar_app_info:name(App) =:= Name + andalso rebar_app_info:original_vsn(App) =:= Vsn + end, Apps). + is_app_dir() -> is_app_dir(rebar_utils:get_cwd()). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index c86d2d1..607aeb7 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -114,7 +114,7 @@ handle_deps(State, Deps) -> ,Packages ,Name ,Vsn), - ok = maybe_fetch(AppInfo), + ok = maybe_fetch(AppInfo, State2), AppInfo end, S) end, @@ -154,7 +154,7 @@ update_src_deps(State) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> - ok = maybe_fetch(AppInfo), + ok = maybe_fetch(AppInfo, State), {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) ,NewBinaryDeps++BinaryDepsAcc} @@ -175,16 +175,17 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, BinaryDeps}. --spec maybe_fetch(rebar_app_info:t()) -> ok. -maybe_fetch(AppInfo) -> +-spec maybe_fetch(rebar_app_info:t(), rebar_state:t()) -> ok. +maybe_fetch(AppInfo, State) -> AppDir = rebar_app_info:dir(AppInfo), - case filelib:is_dir(AppDir) of - false -> + Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), + case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of + {ok, _} -> + ok; + _ -> ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source); - true -> - ok + rebar_fetch:download_source(AppDir, Source) end. -spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index e19041a..f4b25f0 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -11,7 +11,7 @@ -include("rebar.hrl"). -define(PROVIDER, update). --define(DEPS, []). +-define(DEPS, [install_deps]). %% =================================================================== %% Public API @@ -29,11 +29,14 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | rebar:error(). do(State) -> case rebar_state:command_args(State) of [Name] -> ?ERROR("NOT IMPLEMENTED: Updating ~s~n", [Name]), + AllDeps = rebar_state:get(State, all_deps, []), + {ok, App} = rebar_app_utils:find(list_to_binary(Name), AllDeps), + rebar_prv_install_deps:handle_deps(State, [list_to_binary(Name)]), {ok, State}; [] -> ?INFO("Updating package index...~n", []), |