summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatwey V. Kornilov <matwey.kornilov@gmail.com>2016-03-02 16:30:30 +0300
committerMatwey V. Kornilov <matwey.kornilov@gmail.com>2016-03-18 11:05:18 +0300
commit16bc8f77254d58913748e3d878b48be290a5fa89 (patch)
tree774fe5904ceca628b7cbe876bd767864299ec766 /src
parent384af7ef191b8b3f52b212f6b7f02ace786ba2a9 (diff)
downloadrebar-16bc8f77254d58913748e3d878b48be290a5fa89.tar.gz
Introduce REBAR_VSN_CACHE_FILE env variable to load/save vsn cache
When REBAR_VSN_CACHE_FILE is set, then vsn cache is loaded from this file on rebar start and updated when new data. Under specific circumstances (i.e. in build environments), full git tree may not be available, but only its snapshot. We need a way to use preheat vsn cache instead of invocing git command. Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl3
-rw-r--r--src/rebar_core.erl2
-rw-r--r--src/rebar_utils.erl22
3 files changed, 24 insertions, 3 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index 888f80d..5a809d2 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -143,7 +143,7 @@ init_config({Options, _NonOptArgs}) ->
%% Keep track of how many operations we do, so we can detect bad commands
BaseConfig1 = rebar_config:set_xconf(BaseConfig, operations, 0),
%% Initialize vsn cache
- rebar_config:set_xconf(BaseConfig1, vsn_cache, dict:new()).
+ rebar_utils:init_vsn_cache(BaseConfig1).
init_config1(BaseConfig) ->
%% Determine the location of the rebar executable; important for pulling
@@ -288,6 +288,7 @@ help() ->
?CONSOLE(
"Environment variables:~n"
" REBAR_DEPS_PREFER_LIBS to look for dependecies in system libs prior fetching.~n"
+ " REBAR_VSN_CACHE_FILE to load vsn cache from and save to specified file.~n"
"~n", []).
%%
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 0650430..6cc8d38 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -106,7 +106,7 @@ process_commands([Command | Rest], ParentConfig) ->
ParentConfig2),
%% Wipe out vsn cache to avoid invalid hits when
%% dependencies are updated
- rebar_config:set_xconf(ParentConfig3, vsn_cache, dict:new())
+ rebar_utils:init_vsn_cache(ParentConfig3)
catch
throw:rebar_abort ->
case rebar_config:get_xconf(ParentConfig1, keep_going, false) of
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 1fb5419..c3ebfe5 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -67,7 +67,9 @@
processing_base_dir/1,
processing_base_dir/2,
patch_env/2,
- cleanup_code_path/1
+ cleanup_code_path/1,
+ init_vsn_cache/1,
+ save_vsn_cache/1
]).
%% for internal use only
@@ -268,6 +270,23 @@ expand_env_variable(InStr, VarName, RawVarValue) ->
re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
end.
+init_vsn_cache(Config) ->
+ init_vsn_cache(Config, os:getenv("REBAR_VSN_CACHE_FILE")).
+init_vsn_cache(Config, false) ->
+ rebar_config:set_xconf(Config, vsn_cache, dict:new());
+init_vsn_cache(Config, CacheFile) ->
+ {ok, CacheList} = file:consult(CacheFile),
+ CacheDict = dict:from_list(CacheList),
+ rebar_config:set_xconf(Config, vsn_cache, CacheDict).
+
+save_vsn_cache(Config) ->
+ save_vsn_cache(Config, os:getenv("REBAR_VSN_CACHE_FILE")).
+save_vsn_cache(_Config, false) ->
+ ok;
+save_vsn_cache(Config, CacheFile) ->
+ file:write_file(CacheFile,
+ [io_lib:format("~p.~n", [X]) || X <- dict:to_list(rebar_config:get_xconf(Config, vsn_cache))]).
+
vcs_vsn(Config, Vsn, Dir) ->
Key = {Vsn, Dir},
Cache = rebar_config:get_xconf(Config, vsn_cache),
@@ -276,6 +295,7 @@ vcs_vsn(Config, Vsn, Dir) ->
VsnString = vcs_vsn_1(Vsn, Dir),
Cache1 = dict:store(Key, VsnString, Cache),
Config1 = rebar_config:set_xconf(Config, vsn_cache, Cache1),
+ save_vsn_cache(Config1),
{Config1, VsnString};
{ok, VsnString} ->
{Config, VsnString}