Skip to content

Commit

Permalink
add --relnames option to allow selectively building of multiple releases
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGeorge committed Oct 27, 2021
1 parent ba50a08 commit d0e0b83
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/rebar_relx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ do(Provider, State) ->
Args = [include_erts, system_libs, vm_args, sys_config],
RelxConfig2 = maybe_obey_command_args(RelxConfig1, Opts, Args),

{ok, RelxState_0} = rlx_config:to_state(RelxConfig2),
XrefIgnores = rebar_state:get(State, xref_ignores, []),
RelxState = rlx_state:filter_xref_warning(RelxState_0,
fun(Warnings) ->
rebar_prv_xref:filter_xref_results(undefined_function_calls, XrefIgnores, Warnings) end),
{ok, RelxState} = rlx_config:to_state(RelxConfig2),

Providers = rebar_state:providers(State),
Cwd = rebar_state:dir(State),
Expand Down Expand Up @@ -118,6 +114,8 @@ format_error(all_relup) ->
"Option --all can not be applied to `relup` command";
format_error({config_file, Filename, Error}) ->
io_lib:format("Failed to read config file ~ts: ~p", [Filename, Error]);
format_error({release_not_found, Relname}) ->
io_lib:format("No releases exists in the system for ~s!", [Relname]);
format_error(Error) ->
io_lib:format("~p", [Error]).

Expand Down Expand Up @@ -154,8 +152,9 @@ rel_handler({ok, _}, _) ->
ok.

releases_to_build(Provider, Opts, RelxState)->
case proplists:get_value(all, Opts, undefined) of
undefined ->
case {proplists:get_value(all, Opts, undefined),
proplists:get_value(relnames, Opts, undefined)} of
{undefined, undefined} ->
case proplists:get_value(relname, Opts, undefined) of
undefined ->
[undefined];
Expand All @@ -167,10 +166,20 @@ releases_to_build(Provider, Opts, RelxState)->
[{list_to_atom(R), RelVsn}]
end
end;
true when Provider =:= relup ->
{true, _} when Provider =:= relup ->
erlang:error(?PRV_ERROR(all_relup));
true ->
highest_unique_releases(rlx_state:configured_releases(RelxState))
{true, _} ->
highest_unique_releases(rlx_state:configured_releases(RelxState));
{_, Filter} ->
Releases = highest_unique_releases(rlx_state:configured_releases(RelxState)),
WantReleases = [list_to_atom(Rel) || Rel <- string:split(Filter, ",", all)],
[
case proplists:lookup(Relname, Releases) of
none -> erlang:error(?PRV_ERROR({release_not_found, Relname}));
Rel -> Rel
end
|| Relname <- WantReleases
]
end.

%% takes a map of relx configured releases and returns a list of the highest
Expand Down Expand Up @@ -280,4 +289,5 @@ opt_spec_list() ->
{sys_config, undefined, "sys_config", string, "Path to a file to use for sys.config"},
{system_libs, undefined, "system_libs", string, "Boolean or path to dir of Erlang system libs"},
{version, undefined, "version", undefined, "Print relx version"},
{root_dir, $r, "root", string, "The project root directory"}].
{root_dir, $r, "root", string, "The project root directory"},
{relnames, $m, "relnames", string, "Like --all, but only build the releases in the list, e.g. --relnames rel1,rel2"}].

0 comments on commit d0e0b83

Please sign in to comment.