summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Peregud <gleber.p@gmail.com>2015-12-15 14:28:07 +0100
committerGleb Peregud <gleber.p@gmail.com>2016-01-03 16:59:34 +0100
commitcde592150b2ec4e850bbac94b6a145402c022e25 (patch)
tree4d401060768f491b499192552aa01101cd5f3a18
parent21ae3145dfd9f24af9df962fcbf00fdb55d9b923 (diff)
Skip update and compilation if possible.
This detects existence of Hex registry at $HOME/.cache/rebar3/hex/default/registry and skips "rebar3 update" step. It also detect presence of bootstrap dependencies in _build/default/lib/ and skips fetching them.
-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) ->