summaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-07-05 08:54:43 -0500
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-07-05 08:54:43 -0500
commit632f2dd304cc9dbd280711424985684fa8ada365 (patch)
treeff21bbf3296bb3b20254d557f660205a868a4c38 /bootstrap
parent6fdbea7094c7582635b3c809989497ec9dfaf137 (diff)
parent9e4bf8a3bad3f46f8094339b38ac880ec1b977d2 (diff)
Merge pull request #579 from carlosedp/add-proxy
Add proxy support to bootstrap and rebar3. Enhancement #561.
Diffstat (limited to 'bootstrap')
-rwxr-xr-xbootstrap29
1 files changed, 28 insertions, 1 deletions
diff --git a/bootstrap b/bootstrap
index 41d9725..71c44da 100755
--- a/bootstrap
+++ b/bootstrap
@@ -9,6 +9,8 @@ main(_Args) ->
application:start(public_key),
application:start(ssl),
inets:start(),
+ inets:start(httpc, [{profile, rebar}]),
+ set_httpc_options(),
%% Fetch and build deps required to build rebar3
BaseDeps = [{providers, []}
@@ -84,13 +86,38 @@ extract(Binary) ->
request(Url) ->
case httpc:request(get, {Url, []},
[{relaxed, true}],
- [{body_format, binary}]) of
+ [{body_format, binary}],
+ rebar) of
{ok, {{_Version, 200, _Reason}, _Headers, Body}} ->
{ok, Body};
Error ->
Error
end.
+get_rebar_config() ->
+ {ok, [[Home]]} = init:get_argument(home),
+ ConfDir = filename:join(Home, ".config/rebar3"),
+ case file:consult(filename:join(ConfDir, "rebar.config")) of
+ {ok, Config} ->
+ Config;
+ _ ->
+ []
+ end.
+
+get_http_vars(Scheme) ->
+ proplists:get_value(Scheme, get_rebar_config(), []).
+
+set_httpc_options() ->
+ set_httpc_options(https_proxy, get_http_vars(https_proxy)),
+ set_httpc_options(proxy, get_http_vars(http_proxy)).
+
+set_httpc_options(_, []) ->
+ ok;
+
+set_httpc_options(Scheme, Proxy) ->
+ {ok, {_, _, Host, Port, _, _}} = http_uri:parse(Proxy),
+ httpc:set_options([{Scheme, {{Host, Port}, []}}], rebar).
+
compile(App, FirstFiles) ->
Dir = filename:join(filename:absname("_build/default/lib/"), App),
filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])),