Просмотр исходного кода

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

pull/3/head
Tristan Sloughter 10 лет назад
Родитель
Сommit
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) find_app(AppDir, Validate)
end, all_app_dirs(LibDirs)). end, all_app_dirs(LibDirs)).
-spec find_app(list(), boolean()) -> rebar_app_info:t() | false.
find_app(AppDir, Validate) -> find_app(AppDir, Validate) ->
AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])),
AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])),

+ 13
- 1
src/rebar_app_utils.erl Просмотреть файл

@ -26,7 +26,8 @@
%% ------------------------------------------------------------------- %% -------------------------------------------------------------------
-module(rebar_app_utils). -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, is_app_src/1,
app_src_to_app/1, app_src_to_app/1,
app_name/2, app_name/2,
@ -42,6 +43,17 @@
%% Public API %% 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() ->
is_app_dir(rebar_utils:get_cwd()). is_app_dir(rebar_utils:get_cwd()).

+ 10
- 9
src/rebar_prv_install_deps.erl Просмотреть файл

@ -114,7 +114,7 @@ handle_deps(State, Deps) ->
,Packages ,Packages
,Name ,Name
,Vsn), ,Vsn),
ok = maybe_fetch(AppInfo),
ok = maybe_fetch(AppInfo, State2),
AppInfo AppInfo
end, S) end, S)
end, end,
@ -154,7 +154,7 @@ update_src_deps(State) ->
SrcDeps = rebar_state:src_deps(State), SrcDeps = rebar_state:src_deps(State),
DepsDir = get_deps_dir(State), DepsDir = get_deps_dir(State),
case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) ->
ok = maybe_fetch(AppInfo),
ok = maybe_fetch(AppInfo, State),
{AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo),
{ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps)
,NewBinaryDeps++BinaryDepsAcc} ,NewBinaryDeps++BinaryDepsAcc}
@ -175,16 +175,17 @@ handle_dep(DepsDir, AppInfo) ->
{SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps),
{AppInfo1, SrcDeps, BinaryDeps}. {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), 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)]), ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]),
Source = rebar_app_info:source(AppInfo), Source = rebar_app_info:source(AppInfo),
rebar_fetch:download_source(AppDir, Source);
true ->
ok
rebar_fetch:download_source(AppDir, Source)
end. end.
-spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. -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"). -include("rebar.hrl").
-define(PROVIDER, update). -define(PROVIDER, update).
-define(DEPS, []).
-define(DEPS, [install_deps]).
%% =================================================================== %% ===================================================================
%% Public API %% Public API
@ -29,11 +29,14 @@ init(State) ->
opts = []}), opts = []}),
{ok, State1}. {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) -> do(State) ->
case rebar_state:command_args(State) of case rebar_state:command_args(State) of
[Name] -> [Name] ->
?ERROR("NOT IMPLEMENTED: Updating ~s~n", [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}; {ok, State};
[] -> [] ->
?INFO("Updating package index...~n", []), ?INFO("Updating package index...~n", []),

Загрузка…
Отмена
Сохранить