diff options
author | Jeremy Raymond <jeraymond@gmail.com> | 2012-02-11 13:26:09 -0500 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2012-02-15 21:11:57 +0100 |
commit | 7e84634b8fcdf8fd88f39c6b70fb7a5798b40bba (patch) | |
tree | 32cbfb73938e1ddabb71e55e41955f91c8cdac06 /src | |
parent | 1a613d61235efe70399a0a62eaa418666ccc81f9 (diff) |
Fix for destruction of config app vars on reset
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_eunit.erl | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 61b78fc..b34ad84 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -555,13 +555,48 @@ reconstruct_app_env_vars([App|Apps]) -> _ -> [] end, - AllVars = CmdVars ++ AppVars, + + %% App vars specified in config files override those in the .app file. + %% Config files later in the args list override earlier ones. + AppVars1 = case init:get_argument(config) of + {ok, ConfigFiles} -> + {App, MergedAppVars} = lists:foldl(fun merge_app_vars/2, + {App, AppVars}, + ConfigFiles), + MergedAppVars; + error -> + AppVars + end, + AllVars = CmdVars ++ AppVars1, ?DEBUG("Reconstruct ~p ~p\n", [App, AllVars]), lists:foreach(fun({K, V}) -> application:set_env(App, K, V) end, AllVars), reconstruct_app_env_vars(Apps); reconstruct_app_env_vars([]) -> ok. +merge_app_vars(ConfigFile, {App, AppVars}) -> + File = ensure_config_extension(ConfigFile), + FileAppVars = app_vars_from_config_file(File, App), + Dict1 = dict:from_list(AppVars), + Dict2 = dict:from_list(FileAppVars), + Dict3 = dict:merge(fun(_Key, _Value1, Value2) -> Value2 end, Dict1, Dict2), + {App, dict:to_list(Dict3)}. + +ensure_config_extension(File) -> + %% config files must end with .config on disk but when specifying them + %% via the -config option the extension is optional + BaseFileName = filename:basename(File, ".config"), + DirName = filename:dirname(File), + filename:join(DirName, BaseFileName ++ ".config"). + +app_vars_from_config_file(File, App) -> + case file:consult(File) of + {ok, [Env]} -> + proplists:get_value(App, Env, []); + _ -> + [] + end. + wait_until_dead(Pid) when is_pid(Pid) -> Ref = erlang:monitor(process, Pid), receive |