mirror of
https://github.com/correl/rebar.git
synced 2025-04-10 01:01:08 -09: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/3,
|
||||||
set_global/3, get_global/3,
|
set_global/3, get_global/3,
|
||||||
is_verbose/1,
|
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,
|
set_skip_dir/2, is_skip_dir/2, reset_skip_dirs/1,
|
||||||
clean_config/2,
|
clean_config/2,
|
||||||
set_xconf/3, get_xconf/2, get_xconf/3, erase_xconf/2]).
|
set_xconf/3, get_xconf/2, get_xconf/3, erase_xconf/2]).
|
||||||
|
@ -42,9 +42,8 @@
|
||||||
-record(config, { dir :: file:filename(),
|
-record(config, { dir :: file:filename(),
|
||||||
opts = [] :: list(),
|
opts = [] :: list(),
|
||||||
globals = new_globals() :: dict(),
|
globals = new_globals() :: dict(),
|
||||||
%% TODO: consider storing envs in xconf
|
|
||||||
envs = new_env() :: dict(),
|
envs = new_env() :: dict(),
|
||||||
%% cross-directory config
|
%% cross-directory/-command config
|
||||||
skip_dirs = new_skip_dirs() :: dict(),
|
skip_dirs = new_skip_dirs() :: dict(),
|
||||||
xconf = new_xconf() :: dict() }).
|
xconf = new_xconf() :: dict() }).
|
||||||
|
|
||||||
|
@ -132,14 +131,14 @@ consult_file(File) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_env(Config, Mod, Env) ->
|
save_env(Config, Mod, Env) ->
|
||||||
NewEnvs = dict:store(Mod, Env, Config#config.envs),
|
NewEnvs = dict:store(Mod, Env, Config#config.envs),
|
||||||
Config#config{envs = NewEnvs}.
|
Config#config{envs = NewEnvs}.
|
||||||
|
|
||||||
get_env(Config, Mod) ->
|
get_env(Config, Mod) ->
|
||||||
dict:fetch(Mod, Config#config.envs).
|
dict:fetch(Mod, Config#config.envs).
|
||||||
|
|
||||||
reset_env(Config) ->
|
reset_envs(Config) ->
|
||||||
Config#config{envs = new_env()}.
|
Config#config{envs = new_env()}.
|
||||||
|
|
||||||
set_skip_dir(Config, Dir) ->
|
set_skip_dir(Config, Dir) ->
|
||||||
|
|
|
@ -257,8 +257,8 @@ processing_base_dir(Config, Dir) ->
|
||||||
%% process each one we haven't seen yet
|
%% process each one we haven't seen yet
|
||||||
%%
|
%%
|
||||||
process_each([], _Command, Config, _ModuleSetFile, DirSet) ->
|
process_each([], _Command, Config, _ModuleSetFile, DirSet) ->
|
||||||
%% reset cached setup_env
|
%% reset cached (setup_env) envs
|
||||||
Config1 = rebar_config:reset_env(Config),
|
Config1 = rebar_config:reset_envs(Config),
|
||||||
{Config1, DirSet};
|
{Config1, DirSet};
|
||||||
process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
|
process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
|
||||||
case sets:is_element(Dir, DirSet) of
|
case sets:is_element(Dir, DirSet) of
|
||||||
|
@ -268,8 +268,8 @@ process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
|
||||||
false ->
|
false ->
|
||||||
{Config1, DirSet2} = process_dir(Dir, Config, Command, DirSet),
|
{Config1, DirSet2} = process_dir(Dir, Config, Command, DirSet),
|
||||||
Config2 = rebar_config:clean_config(Config, Config1),
|
Config2 = rebar_config:clean_config(Config, Config1),
|
||||||
%% reset cached setup_env
|
%% reset cached (setup_env) envs
|
||||||
Config3 = rebar_config:reset_env(Config2),
|
Config3 = rebar_config:reset_envs(Config2),
|
||||||
process_each(Rest, Command, Config3, ModuleSetFile, DirSet2)
|
process_each(Rest, Command, Config3, ModuleSetFile, DirSet2)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ setup_envs(Config, Modules) ->
|
||||||
case erlang:function_exported(M, setup_env, 1) of
|
case erlang:function_exported(M, setup_env, 1) of
|
||||||
true ->
|
true ->
|
||||||
Env = M:setup_env(C),
|
Env = M:setup_env(C),
|
||||||
C1 = rebar_config:set_env(C, M, Env),
|
C1 = rebar_config:save_env(C, M, Env),
|
||||||
{C1, E++Env};
|
{C1, E++Env};
|
||||||
false ->
|
false ->
|
||||||
T
|
T
|
||||||
|
|
Loading…
Add table
Reference in a new issue