summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbootstrap40
1 files changed, 28 insertions, 12 deletions
diff --git a/bootstrap b/bootstrap
index a26ebff..b20d0d3 100755
--- a/bootstrap
+++ b/bootstrap
@@ -2,8 +2,7 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
-
-main(_Args) ->
+main(_) ->
application:start(crypto),
application:start(asn1),
application:start(public_key),
@@ -34,7 +33,14 @@ main(_Args) ->
setup_env(),
os:putenv("REBAR_PROFILE", "bootstrap"),
- rebar3:run(["update"]),
+ RegistryFile = default_registry_file(),
+ case filelib:is_file(RegistryFile) of
+ true ->
+ ok;
+ false ->
+ rebar3:run(["update"])
+ end,
+
{ok, State} = rebar3:run(["compile"]),
reset_env(),
os:putenv("REBAR_PROFILE", ""),
@@ -62,6 +68,11 @@ main(_Args) ->
ok
end.
+default_registry_file() ->
+ {ok, [[Home]]} = init:get_argument(home),
+ CacheDir = filename:join([Home, ".cache", "rebar3"]),
+ filename:join([CacheDir, "hex", "default", "registry"]).
+
fetch_and_compile({Name, ErlFirstFiles}, Deps) ->
case lists:keyfind(Name, 1, Deps) of
{Name, Vsn} ->
@@ -79,15 +90,20 @@ fetch_and_compile({Name, ErlFirstFiles}, Deps) ->
fetch({pkg, Name, Vsn}, App) ->
Dir = filename:join([filename:absname("_build/default/lib/"), App]),
- CDN = "https://s3.amazonaws.com/s3.hex.pm/tarballs",
- Package = binary_to_list(<<Name/binary, "-", Vsn/binary, ".tar">>),
- Url = string:join([CDN, Package], "/"),
- case request(Url) of
- {ok, Binary} ->
- {ok, Contents} = extract(Binary),
- ok = erl_tar:extract({binary, Contents}, [{cwd, Dir}, compressed]);
- _ ->
- io:format("Error: Unable to fetch package ~p ~p~n", [Name, Vsn])
+ case filelib:is_dir(Dir) of
+ false ->
+ CDN = "https://s3.amazonaws.com/s3.hex.pm/tarballs",
+ Package = binary_to_list(<<Name/binary, "-", Vsn/binary, ".tar">>),
+ Url = string:join([CDN, Package], "/"),
+ case request(Url) of
+ {ok, Binary} ->
+ {ok, Contents} = extract(Binary),
+ ok = erl_tar:extract({binary, Contents}, [{cwd, Dir}, compressed]);
+ _ ->
+ io:format("Error: Unable to fetch package ~p ~p~n", [Name, Vsn])
+ end;
+ true ->
+ io:format("Dependency ~s already exists~n", [Name])
end.
extract(Binary) ->