mirror of
https://github.com/correl/rebar.git
synced 2024-11-15 03:00:18 +00:00
Refactor setup_env rebar_config funs
This commit is contained in:
parent
c9ddb8325a
commit
392adcf967
2 changed files with 9 additions and 10 deletions
|
@ -32,7 +32,7 @@
|
|||
set/3,
|
||||
set_global/3, get_global/3,
|
||||
is_verbose/1,
|
||||
set_env/3, get_env/2, reset_env/1,
|
||||
save_env/3, get_env/2, reset_envs/1,
|
||||
set_skip_dir/2, is_skip_dir/2, reset_skip_dirs/1,
|
||||
clean_config/2,
|
||||
set_xconf/3, get_xconf/2, get_xconf/3, erase_xconf/2]).
|
||||
|
@ -42,9 +42,8 @@
|
|||
-record(config, { dir :: file:filename(),
|
||||
opts = [] :: list(),
|
||||
globals = new_globals() :: dict(),
|
||||
%% TODO: consider storing envs in xconf
|
||||
envs = new_env() :: dict(),
|
||||
%% cross-directory config
|
||||
%% cross-directory/-command config
|
||||
skip_dirs = new_skip_dirs() :: dict(),
|
||||
xconf = new_xconf() :: dict() }).
|
||||
|
||||
|
@ -132,14 +131,14 @@ consult_file(File) ->
|
|||
end
|
||||
end.
|
||||
|
||||
set_env(Config, Mod, Env) ->
|
||||
save_env(Config, Mod, Env) ->
|
||||
NewEnvs = dict:store(Mod, Env, Config#config.envs),
|
||||
Config#config{envs = NewEnvs}.
|
||||
|
||||
get_env(Config, Mod) ->
|
||||
dict:fetch(Mod, Config#config.envs).
|
||||
|
||||
reset_env(Config) ->
|
||||
reset_envs(Config) ->
|
||||
Config#config{envs = new_env()}.
|
||||
|
||||
set_skip_dir(Config, Dir) ->
|
||||
|
|
|
@ -257,8 +257,8 @@ processing_base_dir(Config, Dir) ->
|
|||
%% process each one we haven't seen yet
|
||||
%%
|
||||
process_each([], _Command, Config, _ModuleSetFile, DirSet) ->
|
||||
%% reset cached setup_env
|
||||
Config1 = rebar_config:reset_env(Config),
|
||||
%% reset cached (setup_env) envs
|
||||
Config1 = rebar_config:reset_envs(Config),
|
||||
{Config1, DirSet};
|
||||
process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
|
||||
case sets:is_element(Dir, DirSet) of
|
||||
|
@ -268,8 +268,8 @@ process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
|
|||
false ->
|
||||
{Config1, DirSet2} = process_dir(Dir, Config, Command, DirSet),
|
||||
Config2 = rebar_config:clean_config(Config, Config1),
|
||||
%% reset cached setup_env
|
||||
Config3 = rebar_config:reset_env(Config2),
|
||||
%% reset cached (setup_env) envs
|
||||
Config3 = rebar_config:reset_envs(Config2),
|
||||
process_each(Rest, Command, Config3, ModuleSetFile, DirSet2)
|
||||
end.
|
||||
|
||||
|
@ -434,7 +434,7 @@ setup_envs(Config, Modules) ->
|
|||
case erlang:function_exported(M, setup_env, 1) of
|
||||
true ->
|
||||
Env = M:setup_env(C),
|
||||
C1 = rebar_config:set_env(C, M, Env),
|
||||
C1 = rebar_config:save_env(C, M, Env),
|
||||
{C1, E++Env};
|
||||
false ->
|
||||
T
|
||||
|
|
Loading…
Reference in a new issue