From 3966610e532f18f71c6e4d04c3a96d6372ddc390 Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Tue, 11 Oct 2016 10:31:57 +0300 Subject: Made Common Test load the user's applications before slurping config. --- src/rebar_prv_common_test.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 1e0632e..8bfa192 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -221,6 +221,7 @@ select_tests(State, ProjectApps, CmdOpts, CfgOpts) -> Configs = lists:flatmap(fun(Filename) -> rebar_file_utils:consult_config(State, Filename) end, SysConfigs), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), [application:load(Application) || Config <- Configs, {Application, _} <- Config], rebar_utils:reread_config(Configs), -- cgit v1.1 From 6e9503c4f0232d6e8152b56a7037f22843e53959 Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Tue, 11 Oct 2016 10:33:14 +0300 Subject: Rereading system configuration sets up persistent options if possible. --- src/rebar_utils.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index aa9e268..dc0bb42 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -414,8 +414,14 @@ user_agent() -> ?FMT("Rebar/~s (OTP/~s)", [Vsn, otp_release()]). reread_config(ConfigList) -> + SetEnv = case version_tuple(?MODULE:otp_release()) of + {X, _, _} when X =< 17 -> + fun application:set_env/3; + _ -> + fun (App, Key, Val) -> application:set_env(App, Key, Val, [{persistent, true}]) end + end, try - [application:set_env(Application, Key, Val) + [SetEnv(Application, Key, Val) || Config <- ConfigList, {Application, Items} <- Config, {Key, Val} <- Items] -- cgit v1.1 From 0afb4c4d477b1c1fba54ad3ef086d0697a5faeaa Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Tue, 11 Oct 2016 10:36:12 +0300 Subject: Made reading sys.configs consistent with OTP specification. --- src/rebar_file_utils.erl | 13 ++++++++----- src/rebar_prv_common_test.erl | 6 +++--- src/rebar_prv_shell.erl | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 437780d..28cc516 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -72,11 +72,14 @@ consult_config(State, Filename) -> [T] -> T; [] -> [] end, - SubConfigs = [consult_config(State, Entry ++ ".config") || - Entry <- Config, is_list(Entry) - ], - - [Config | lists:merge(SubConfigs)]. + lists:flatmap( + fun (SubConfig) when is_list(SubConfig) -> + case consult_config(State, SubConfig) of + [] -> consult_config(State, SubConfig ++ ".config"); + X -> X + end; + (Entry) -> [Entry] + end, Config). format_error({bad_term_file, AppFile, Reason}) -> io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 8bfa192..e69d33e 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -218,9 +218,9 @@ select_tests(_, _, _, {error, _} = Error) -> Error; select_tests(State, ProjectApps, CmdOpts, CfgOpts) -> %% set application env if sys_config argument is provided SysConfigs = sys_config_list(CmdOpts, CfgOpts), - Configs = lists:flatmap(fun(Filename) -> - rebar_file_utils:consult_config(State, Filename) - end, SysConfigs), + Configs = lists:map(fun(Filename) -> + rebar_file_utils:consult_config(State, Filename) + end, SysConfigs), code:add_pathsa(rebar_state:code_paths(State, all_deps)), [application:load(Application) || Config <- Configs, {Application, _} <- Config], rebar_utils:reread_config(Configs), diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index b7febf8..e14ae3a 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -331,8 +331,8 @@ reread_config(State) -> case find_config(State) of no_config -> ok; - ConfigList -> - _ = rebar_utils:reread_config(ConfigList), + Config -> + _ = rebar_utils:reread_config([Config]), ok end. -- cgit v1.1 From 4ce21e4c800108030d5c646b226032f460e68065 Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Tue, 11 Oct 2016 16:30:27 +0300 Subject: Avoid backward-compatibility-breaking changes. --- src/rebar_file_utils.erl | 18 ++++++++++-------- src/rebar_prv_common_test.erl | 6 +++--- src/rebar_prv_shell.erl | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 28cc516..6721b5a 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -72,14 +72,16 @@ consult_config(State, Filename) -> [T] -> T; [] -> [] end, - lists:flatmap( - fun (SubConfig) when is_list(SubConfig) -> - case consult_config(State, SubConfig) of - [] -> consult_config(State, SubConfig ++ ".config"); - X -> X - end; - (Entry) -> [Entry] - end, Config). + JoinedConfig = lists:flatmap( + fun (SubConfig) when is_list(SubConfig) -> + case lists:suffix(".config", SubConfig) of + false -> consult_config(State, SubConfig ++ ".config"); + true -> consult_config(State, SubConfig) + end; + (Entry) -> [Entry] + end, Config), + %% Backwards compatibility + [JoinedConfig]. format_error({bad_term_file, AppFile, Reason}) -> io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index e69d33e..8bfa192 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -218,9 +218,9 @@ select_tests(_, _, _, {error, _} = Error) -> Error; select_tests(State, ProjectApps, CmdOpts, CfgOpts) -> %% set application env if sys_config argument is provided SysConfigs = sys_config_list(CmdOpts, CfgOpts), - Configs = lists:map(fun(Filename) -> - rebar_file_utils:consult_config(State, Filename) - end, SysConfigs), + Configs = lists:flatmap(fun(Filename) -> + rebar_file_utils:consult_config(State, Filename) + end, SysConfigs), code:add_pathsa(rebar_state:code_paths(State, all_deps)), [application:load(Application) || Config <- Configs, {Application, _} <- Config], rebar_utils:reread_config(Configs), diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index e14ae3a..b7febf8 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -331,8 +331,8 @@ reread_config(State) -> case find_config(State) of no_config -> ok; - Config -> - _ = rebar_utils:reread_config([Config]), + ConfigList -> + _ = rebar_utils:reread_config(ConfigList), ok end. -- cgit v1.1 From e71b80752f905d9f4bb5dbf78c16693dbc6133f4 Mon Sep 17 00:00:00 2001 From: Alexander Sedov Date: Tue, 11 Oct 2016 16:34:21 +0300 Subject: Some post-review changes: - restore path after loading applications, - helpful comments. --- src/rebar_prv_common_test.erl | 4 ++++ src/rebar_utils.erl | 2 ++ 2 files changed, 6 insertions(+) (limited to 'src') diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 8bfa192..46bd1a7 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -221,9 +221,13 @@ select_tests(State, ProjectApps, CmdOpts, CfgOpts) -> Configs = lists:flatmap(fun(Filename) -> rebar_file_utils:consult_config(State, Filename) end, SysConfigs), + %% NB: load the applications (from user directories too) to support OTP < 17 + %% to our best ability. + OldPath = code:get_path(), code:add_pathsa(rebar_state:code_paths(State, all_deps)), [application:load(Application) || Config <- Configs, {Application, _} <- Config], rebar_utils:reread_config(Configs), + code:set_path(OldPath), Merged = lists:ukeymerge(1, lists:ukeysort(1, CmdOpts), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index dc0bb42..f55f40f 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -414,6 +414,8 @@ user_agent() -> ?FMT("Rebar/~s (OTP/~s)", [Vsn, otp_release()]). reread_config(ConfigList) -> + %% NB: we attempt to mimic -config here, which survives app reload, + %% hence {persistent, true}. SetEnv = case version_tuple(?MODULE:otp_release()) of {X, _, _} when X =< 17 -> fun application:set_env/3; -- cgit v1.1