aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2018-06-12 19:07:22 -0600
committerGitHub <[email protected]>2018-06-12 19:07:22 -0600
commitee477fb31ad9a7603aaea8922aaa9ecd3712ee2d (patch)
tree5d37580d953db02cddfbf1821d3ba535677e3e1e /src
parent53f4c6eb6b57408a8b3cad412373db534a13ca1f (diff)
downloadrelx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.tar.gz
relx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.tar.bz2
relx-ee477fb31ad9a7603aaea8922aaa9ecd3712ee2d.zip
support for OTP21's sys.config.src file in releases (#647)
* support for OTP21's sys.config.src file in releases * always replace os vars in .src files if found * support vm_args_src to be consistent with sys_config_src * add newlines after warning logs * improve sys and vm src config tests
Diffstat (limited to 'src')
-rw-r--r--src/rlx_config.erl4
-rw-r--r--src/rlx_prv_assembler.erl97
-rw-r--r--src/rlx_state.erl22
3 files changed, 99 insertions, 24 deletions
diff --git a/src/rlx_config.erl b/src/rlx_config.erl
index 57aac71..ee58db5 100644
--- a/src/rlx_config.erl
+++ b/src/rlx_config.erl
@@ -256,10 +256,14 @@ load_terms({vm_args, false}, {ok, State}) ->
{ok, rlx_state:vm_args(State, false)};
load_terms({vm_args, VmArgs}, {ok, State}) ->
{ok, rlx_state:vm_args(State, filename:absname(VmArgs))};
+load_terms({vm_args_src, VmArgs}, {ok, State}) ->
+ {ok, rlx_state:vm_args_src(State, filename:absname(VmArgs))};
load_terms({sys_config, false}, {ok, State}) ->
{ok, rlx_state:sys_config(State, false)};
load_terms({sys_config, SysConfig}, {ok, State}) ->
{ok, rlx_state:sys_config(State, filename:absname(SysConfig))};
+load_terms({sys_config_src, SysConfigSrc}, {ok, State}) ->
+ {ok, rlx_state:sys_config_src(State, filename:absname(SysConfigSrc))};
load_terms({root_dir, Root}, {ok, State}) ->
{ok, rlx_state:root_dir(State, filename:absname(Root))};
load_terms({output_dir, OutputDir}, {ok, State}) ->
diff --git a/src/rlx_prv_assembler.erl b/src/rlx_prv_assembler.erl
index 65975e5..705e51a 100644
--- a/src/rlx_prv_assembler.erl
+++ b/src/rlx_prv_assembler.erl
@@ -86,8 +86,17 @@ format_error({unresolved_release, RelName, RelVsn}) ->
format_error({ec_file_error, AppDir, TargetDir, E}) ->
io_lib:format("Unable to copy OTP App from ~s to ~s due to ~p",
[AppDir, TargetDir, E]);
+format_error({vmargs_does_not_exist, Path}) ->
+ io_lib:format("The vm.args file specified for this release (~s) does not exist!",
+ [Path]);
+format_error({vmargs_src_does_not_exist, Path}) ->
+ io_lib:format("The vm.args.src file specified for this release (~s) does not exist!",
+ [Path]);
format_error({config_does_not_exist, Path}) ->
- io_lib:format("The config file specified for this release (~s) does not exist!",
+ io_lib:format("The sys.config file specified for this release (~s) does not exist!",
+ [Path]);
+format_error({config_src_does_not_exist, Path}) ->
+ io_lib:format("The sys.config.src file specified for this release (~s) does not exist!",
[Path]);
format_error({sys_config_parse_error, ConfigPath, Reason}) ->
io_lib:format("The config file (~s) specified for this release could not be opened or parsed: ~s",
@@ -557,18 +566,38 @@ generate_start_erl_data_file(Release, ReleasesDir) ->
copy_or_generate_vmargs_file(State, Release, RelDir) ->
RelVmargsPath = filename:join([RelDir, "vm.args"]),
- case rlx_state:vm_args(State) of
- false ->
- ok;
+ RelVmargsSrcPath = filename:join([RelDir, "vm.args.src"]),
+ case rlx_state:vm_args_src(State) of
undefined ->
- RelName = erlang:atom_to_list(rlx_release:name(Release)),
- unless_exists_write_default(RelVmargsPath, vm_args_file(RelName));
- ArgsPath ->
- case filelib:is_regular(ArgsPath) of
+ case rlx_state:vm_args(State) of
+ false ->
+ ok;
+ undefined ->
+ RelName = erlang:atom_to_list(rlx_release:name(Release)),
+ unless_exists_write_default(RelVmargsPath, vm_args_file(RelName));
+ ArgsPath ->
+ case filelib:is_regular(ArgsPath) of
+ false ->
+ ?RLX_ERROR({vmargs_does_not_exist, ArgsPath});
+ true ->
+ copy_or_symlink_config_file(State, ArgsPath, RelVmargsPath)
+ end
+ end;
+ ArgsSrcPath ->
+ %% print a warning if vm_args is also set
+ case rlx_state:vm_args(State) of
+ undefined ->
+ ok;
+ _->
+ ec_cmd_log:warn(rlx_state:log(State),
+ "Both vm_args_src and vm_args are set, vm_args will be ignored~n", [])
+ end,
+
+ case filelib:is_regular(ArgsSrcPath) of
false ->
- ?RLX_ERROR({vmargs_does_not_exist, ArgsPath});
+ ?RLX_ERROR({vmargs_src_does_not_exist, ArgsSrcPath});
true ->
- copy_or_symlink_config_file(State, ArgsPath, RelVmargsPath)
+ copy_or_symlink_config_file(State, ArgsSrcPath, RelVmargsSrcPath)
end
end.
@@ -577,23 +606,43 @@ copy_or_generate_vmargs_file(State, Release, RelDir) ->
{ok, rlx_state:t()} | relx:error().
copy_or_generate_sys_config_file(State, RelDir) ->
RelSysConfPath = filename:join([RelDir, "sys.config"]),
- case rlx_state:sys_config(State) of
- false ->
- ok;
+ RelSysConfSrcPath = filename:join([RelDir, "sys.config.src"]),
+ case rlx_state:sys_config_src(State) of
undefined ->
- unless_exists_write_default(RelSysConfPath, sys_config_file());
- ConfigPath ->
- case filelib:is_regular(ConfigPath) of
+ case rlx_state:sys_config(State) of
false ->
- ?RLX_ERROR({config_does_not_exist, ConfigPath});
- true ->
- %% validate sys.config is valid Erlang terms
- case file:consult(ConfigPath) of
- {ok, _} ->
- copy_or_symlink_config_file(State, ConfigPath, RelSysConfPath);
- {error, Reason} ->
- ?RLX_ERROR({sys_config_parse_error, ConfigPath, Reason})
+ ok;
+ undefined ->
+ unless_exists_write_default(RelSysConfPath, sys_config_file());
+ ConfigPath ->
+ case filelib:is_regular(ConfigPath) of
+ false ->
+ ?RLX_ERROR({config_does_not_exist, ConfigPath});
+ true ->
+ %% validate sys.config is valid Erlang terms
+ case file:consult(ConfigPath) of
+ {ok, _} ->
+ copy_or_symlink_config_file(State, ConfigPath, RelSysConfPath);
+ {error, Reason} ->
+ ?RLX_ERROR({sys_config_parse_error, ConfigPath, Reason})
+ end
end
+ end;
+ ConfigSrcPath ->
+ %% print a warning if sys_config is also set
+ case rlx_state:sys_config(State) of
+ P when P =:= false orelse P =:= undefined ->
+ ok;
+ _->
+ ec_cmd_log:warn(rlx_state:log(State),
+ "Both sys_config_src and sys_config are set, sys_config will be ignored~n", [])
+ end,
+
+ case filelib:is_regular(ConfigSrcPath) of
+ false ->
+ ?RLX_ERROR({config_src_does_not_exist, ConfigSrcPath});
+ true ->
+ copy_or_symlink_config_file(State, ConfigSrcPath, RelSysConfSrcPath)
end
end.
diff --git a/src/rlx_state.erl b/src/rlx_state.erl
index 5032628..5488a41 100644
--- a/src/rlx_state.erl
+++ b/src/rlx_state.erl
@@ -54,8 +54,12 @@
hooks/2,
vm_args/1,
vm_args/2,
+ vm_args_src/1,
+ vm_args_src/2,
sys_config/1,
sys_config/2,
+ sys_config_src/1,
+ sys_config_src/2,
root_dir/1,
root_dir/2,
add_configured_release/2,
@@ -106,7 +110,9 @@
available_apps=[] :: [rlx_app_info:t()],
default_configured_release :: {rlx_release:name() | undefined, rlx_release:vsn() |undefined} | undefined,
vm_args :: file:filename() | false | undefined,
+ vm_args_src :: file:filename() | undefined,
sys_config :: file:filename() | false | undefined,
+ sys_config_src :: file:filename() | undefined,
overrides=[] :: [{AppName::atom(), Directory::file:filename()}],
skip_apps=[] :: [AppName::atom()],
exclude_apps=[] :: [AppName::atom()],
@@ -284,6 +290,14 @@ vm_args(#state_t{vm_args=VmArgs}) ->
vm_args(State, VmArgs) ->
State#state_t{vm_args=VmArgs}.
+-spec vm_args_src(t()) -> file:filename() | undefined.
+vm_args_src(#state_t{vm_args_src=VmArgs}) ->
+ VmArgs.
+
+-spec vm_args_src(t(), undefined | file:filename()) -> t().
+vm_args_src(State, VmArgs) ->
+ State#state_t{vm_args_src=VmArgs}.
+
-spec sys_config(t()) -> file:filename() | false | undefined.
sys_config(#state_t{sys_config=SysConfig}) ->
SysConfig.
@@ -292,6 +306,14 @@ sys_config(#state_t{sys_config=SysConfig}) ->
sys_config(State, SysConfig) ->
State#state_t{sys_config=SysConfig}.
+-spec sys_config_src(t()) -> file:filename() | undefined.
+sys_config_src(#state_t{sys_config_src=SysConfigSrc}) ->
+ SysConfigSrc.
+
+-spec sys_config_src(t(), file:filename() | undefined) -> t().
+sys_config_src(State, SysConfigSrc) ->
+ State#state_t{sys_config_src=SysConfigSrc}.
+
-spec root_dir(t()) -> file:filename() | undefined.
root_dir(#state_t{root_dir=RootDir}) ->
RootDir.