From cde592150b2ec4e850bbac94b6a145402c022e25 Mon Sep 17 00:00:00 2001 From: Gleb Peregud Date: Tue, 15 Dec 2015 14:28:07 +0100 Subject: 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. --- bootstrap | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'bootstrap') 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(<>), - 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(<>), + 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) -> -- cgit v1.1