From 1dabd217dbfbebae2f5375160551c35cd1f2a972 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 13:51:14 -0500 Subject: inefficient way, but safer, of checking if an app is already downloaded --- src/rebar_prv_update.erl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/rebar_prv_update.erl') 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", []), -- cgit v1.1 From 0649be271bd8b2db2549dbc3228bd2d6b83e8954 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 14:19:02 -0500 Subject: wip: update dep --- src/rebar_prv_update.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index f4b25f0..4a02664 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -36,7 +36,7 @@ do(State) -> ?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)]), + rebar_prv_install_deps:handle_deps(State, [list_to_atom(Name)], true), {ok, State}; [] -> ?INFO("Updating package index...~n", []), -- cgit v1.1 From e1b1152b219cf65c7f8cd3b77db5cf2156fcbab7 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 22:36:54 -0500 Subject: slowly widdling away at dialyzer errors --- src/rebar_prv_update.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 4a02664..b599266 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -29,13 +29,13 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()} | rebar:error(). +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. 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), + {ok, _App} = rebar_app_utils:find(list_to_binary(Name), AllDeps), rebar_prv_install_deps:handle_deps(State, [list_to_atom(Name)], true), {ok, State}; [] -> -- cgit v1.1 From e392bfaec3942e63a88bb86a676fe4755ba84ce3 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 26 Sep 2014 08:22:24 -0500 Subject: update src dep works except for removed transitive deps --- src/rebar_prv_update.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index b599266..5180d4a 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, [install_deps]). +-define(DEPS, [lock]). %% =================================================================== %% Public API @@ -33,10 +33,12 @@ init(State) -> 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_atom(Name)], true), + ?ERROR("Updating ~s~n", [Name]), + Locks = rebar_state:get(State, locks, []), + {_, _, _, Level} = lists:keyfind(ec_cnv:to_binary(Name), 1, Locks), + Deps = rebar_state:get(State, deps), + Dep = lists:keyfind(list_to_atom(Name), 1, Deps), + rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}), {ok, State}; [] -> ?INFO("Updating package index...~n", []), -- cgit v1.1 From e9a3396e56679a11ac1caa3b47f1f196f0307d72 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 27 Sep 2014 14:12:11 -0500 Subject: return error messages from providers --- src/rebar_prv_update.erl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 5180d4a..c885167 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -29,17 +29,21 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> case rebar_state:command_args(State) of [Name] -> - ?ERROR("Updating ~s~n", [Name]), + ?INFO("Updating ~s~n", [Name]), Locks = rebar_state:get(State, locks, []), - {_, _, _, Level} = lists:keyfind(ec_cnv:to_binary(Name), 1, Locks), - Deps = rebar_state:get(State, deps), - Dep = lists:keyfind(list_to_atom(Name), 1, Deps), - rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}), - {ok, State}; + case lists:keyfind(ec_cnv:to_binary(Name), 1, Locks) of + {_, _, _, Level} -> + Deps = rebar_state:get(State, deps), + Dep = lists:keyfind(list_to_atom(Name), 1, Deps), + rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}), + {ok, State}; + false -> + {error, io_lib:format("No such dependency ~s~n", [Name])} + end; [] -> ?INFO("Updating package index...~n", []), Url = url(State), -- cgit v1.1 From db9ba68f801ec961313d0cdf9ceb03d79cc84d09 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 27 Sep 2014 14:49:53 -0500 Subject: erorr message on failed package update --- src/rebar_prv_update.erl | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index c885167..bfe3ab6 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, [lock]). +-define(DEPS, []). %% =================================================================== %% Public API @@ -46,22 +46,17 @@ do(State) -> end; [] -> ?INFO("Updating package index...~n", []), - Url = url(State), - %{ok, [Home]} = init:get_argument(home), - ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])), - PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]), - {ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile}, {sync, false}]), - wait(RequestId, State) - end. - -wait(RequestId, State) -> - receive - {http, {RequestId, saved_to_file}} -> - {ok, State} - after - 500 -> - io:format("."), - wait(RequestId, State) + try + Url = url(State), + %{ok, [Home]} = init:get_argument(home), + ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])), + PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]), + {ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} + ,{sync, true}]) + catch + _:_ -> + {error, io_lib:format("Failed to write package index.~n", [])} + end end. url(State) -> -- cgit v1.1 From 955f582a3ea6bb89b7b5df8ccdcbf48ab5fc815c Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sun, 28 Sep 2014 17:27:31 -0500 Subject: fix for downloading transitive source deps --- src/rebar_prv_update.erl | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index bfe3ab6..e1648e2 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -23,40 +23,25 @@ init(State) -> provider_impl = ?MODULE, bare = false, deps = ?DEPS, - example = "rebar update cowboy", - short_desc = "Update package index or individual dependency.", + example = "rebar update", + short_desc = "Update package index.", desc = "", opts = []}), {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - case rebar_state:command_args(State) of - [Name] -> - ?INFO("Updating ~s~n", [Name]), - Locks = rebar_state:get(State, locks, []), - case lists:keyfind(ec_cnv:to_binary(Name), 1, Locks) of - {_, _, _, Level} -> - Deps = rebar_state:get(State, deps), - Dep = lists:keyfind(list_to_atom(Name), 1, Deps), - rebar_prv_install_deps:handle_deps(State, [Dep], {true, ec_cnv:to_binary(Name), Level}), - {ok, State}; - false -> - {error, io_lib:format("No such dependency ~s~n", [Name])} - end; - [] -> - ?INFO("Updating package index...~n", []), - try - Url = url(State), + ?INFO("Updating package index...~n", []), + try + Url = url(State), %{ok, [Home]} = init:get_argument(home), - ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])), - PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]), - {ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} - ,{sync, true}]) - catch - _:_ -> - {error, io_lib:format("Failed to write package index.~n", [])} - end + ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])), + PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]), + {ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} + ,{sync, true}]) + catch + _:_ -> + {error, io_lib:format("Failed to write package index.~n", [])} end. url(State) -> -- cgit v1.1 From b37a5ae611aaf6b84a046fbe716f40c2aa8c75d8 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 3 Oct 2014 06:33:33 -0500 Subject: move providers to separate app --- src/rebar_prv_update.erl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index e1648e2..53402db 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -3,7 +3,7 @@ -module(rebar_prv_update). --behaviour(rebar_provider). +-behaviour(provider). -export([init/1, do/1]). @@ -19,14 +19,14 @@ -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> - State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER, - provider_impl = ?MODULE, - bare = false, - deps = ?DEPS, - example = "rebar update", - short_desc = "Update package index.", - desc = "", - opts = []}), + State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {bare, false}, + {deps, ?DEPS}, + {example, "rebar update"}, + {short_desc, "Update package index."}, + {desc, ""}, + {opts, []}])), {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. -- cgit v1.1 From 4b7281effc83a359662d32d3ec840deadd2eaf22 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 17 Oct 2014 14:28:07 -0500 Subject: fix update provider do/1 return --- src/rebar_prv_update.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 53402db..8ac4426 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -37,12 +37,13 @@ do(State) -> %{ok, [Home]} = init:get_argument(home), ec_file:mkdir_p(filename:join([os:getenv("HOME"), ".rebar"])), PackagesFile = filename:join([os:getenv("HOME"), ".rebar", "packages"]), - {ok, RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} - ,{sync, true}]) + {ok, _RequestId} = httpc:request(get, {Url, []}, [], [{stream, PackagesFile} + ,{sync, true}]) catch _:_ -> {error, io_lib:format("Failed to write package index.~n", [])} - end. + end, + {ok, State}. url(State) -> SystemArch = erlang:system_info(system_architecture), -- cgit v1.1 From 1dce2d36cc75263db279abd7f282772ce0f0f3e6 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Oct 2014 12:03:49 -0500 Subject: add format_error/2 provider callback to providers --- src/rebar_prv_update.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/rebar_prv_update.erl') diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 8ac4426..0d388c8 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -6,7 +6,8 @@ -behaviour(provider). -export([init/1, - do/1]). + do/1, + format_error/2]). -include("rebar.hrl"). @@ -45,6 +46,10 @@ do(State) -> end, {ok, State}. +-spec format_error(any(), rebar_state:t()) -> {iolist(), rebar_state:t()}. +format_error(Reason, State) -> + {io_lib:format("~p", [Reason]), State}. + url(State) -> SystemArch = erlang:system_info(system_architecture), ErtsVsn = erlang:system_info(version), -- cgit v1.1