Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New template for starting a release #2076

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions priv/templates/init-release.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{description, "OTP Release structure for executable programs"}.
{variables, [
{name, "{{root_name}}", "Name of the OTP release. An app with this name will also be created."},
{desc, "An OTP application", "Short description of the release's main app's purpose"}
]}.
{template, "sys.config", "config/sys.config"}.
{template, "vm.args", "config/vm.args"}.
{message, "Add relx configuration to rebar.config:\n\n{relx, [{release, {{{root_name}}, \"0.1.0\"},
[{{name}},
sasl]},

{sys_config, \"./config/sys.config\"},
{vm_args, \"./config/vm.args\"},

{dev_mode, true},
{include_erts, false},

{extended_start_script, true}]
}."}.
33 changes: 19 additions & 14 deletions src/rebar_templater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -83,35 +83,40 @@ get_template_vars(TemplateTerms, State) ->
{_, Value} -> Value;
false -> []
end,
override_vars(Vars, override_vars(global_variables(State), default_variables())).
override_vars(Vars, override_vars(global_variables(State), default_variables(State))).

%% Provide a way to merge a set of variables with another one. The left-hand
%% set of variables takes precedence over the right-hand set.
%% In the case where left-hand variable description contains overriden defaults, but
%% the right-hand one contains additional data such as documentation, the resulting
%% variable description will contain the widest set of information possible.
override_vars([], General) -> General;
override_vars([{Var, Default} | Rest], General) ->
case lists:keytake(Var, 1, General) of
{value, {Var, _Default, Doc}, NewGeneral} ->
[{Var, Default, Doc} | override_vars(Rest, NewGeneral)];
{value, {Var, _Default}, NewGeneral} ->
[{Var, Default} | override_vars(Rest, NewGeneral)];
false ->
[{Var, Default} | override_vars(Rest, General)]
end;
override_vars([{Var, Default, Doc} | Rest], General) ->
[{Var, Default, Doc} | override_vars(Rest, lists:keydelete(Var, 1, General))].
override_vars(Vars, General) ->
{NewGeneral, VarsAcc} =
lists:foldl(fun({Var, Default}, {General1, Acc}) ->
case lists:keytake(Var, 1, General1) of
{value, {Var, _Default, Doc}, NewGeneral1} ->
{NewGeneral1, [{Var, expand_path(Default, General1), Doc} | Acc]};
{value, {Var, _Default}, NewGeneral1} ->
{NewGeneral1, [{Var, expand_path(Default, General1)}]};
false ->
{General1, [{Var, expand_path(Default, General1)} | Acc]}
end;
({Var, Default, Doc}, {General1, Acc}) ->
{lists:keydelete(Var, 1, General1), [{Var, rebar_utils:to_list(render(Default, General1)), Doc} | Acc]}
end, {General, []}, Vars),
NewGeneral ++ VarsAcc.

%% Default variables, generated dynamically.
default_variables() ->
default_variables(State) ->
RootName = filename:basename(filename:rootname(rebar_dir:root_dir(State))),
{DefaultAuthor, DefaultEmail} = default_author_and_email(),
{{Y,M,D},{H,Min,S}} = calendar:universal_time(),
[{date, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0w",[Y,M,D]))},
{datetime, lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w+00:00",[Y,M,D,H,Min,S]))},
{author_name, DefaultAuthor},
{author_email, DefaultEmail},
{copyright_year, integer_to_list(Y)},
{root_name, RootName},
{apps_dir, "apps", "Directory where applications will be created if needed"}].

default_author_and_email() ->
Expand Down