ソースを参照

inefficient way, but safer, of checking if an app is already downloaded

pull/3/head
Tristan Sloughter 10年前
コミット
1dabd217db
4個のファイルの変更29行の追加12行の削除
  1. +1
    -0
      src/rebar_app_discover.erl
  2. +13
    -1
      src/rebar_app_utils.erl
  3. +10
    -9
      src/rebar_prv_install_deps.erl
  4. +5
    -2
      src/rebar_prv_update.erl

+ 1
- 0
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"])),

+ 13
- 1
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()).

+ 10
- 9
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()]}.

+ 5
- 2
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", []),

読み込み中…
キャンセル
保存