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

Preserve the order of goals in rel file #812

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 12 additions & 5 deletions src/rlx_release.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@
-type parsed_goal() :: #{name := name(),
vsn => vsn() | undefined,
type => type(),
included_applications => incl_apps()}.
included_applications => incl_apps(),
%% Index of the goal in the release spec
%% Keeping track of it since maps (parsed_goals() is a map)
%% are unordered and .rel file will end up reordering goals.
index => pos_integer()}.

-type parsed_goals() :: #{name() => parsed_goal()}.

Expand Down Expand Up @@ -306,12 +310,15 @@ maybe_with_type(Tuple, Type) ->

-spec parse_goals([application_spec()]) -> parsed_goals().
parse_goals(ConfigGoals) ->
lists:foldl(fun(ConfigGoal, Acc) ->
{Result, _} = lists:foldl(fun(ConfigGoal, {Acc, Index}) ->
Goal=#{name := Name} = parse_goal(ConfigGoal),
Acc#{Name => maps:merge(#{vsn=> undefined,
Acc1 = Acc#{Name => maps:merge(#{vsn=> undefined,
type => undefined,
included_applications => undefined}, Goal)}
end, #{}, ConfigGoals).
included_applications => undefined,
index => Index}, Goal)},
{Acc1, Index + 1}
end, {#{}, 1}, ConfigGoals),
Result.

-spec parse_goal(relx:goal()) -> parsed_goal().
parse_goal(AppName) when is_atom(AppName) ->
Expand Down
6 changes: 5 additions & 1 deletion src/rlx_resolve.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ solve_release(Release, State0) ->
erlang:error(?RLX_ERROR({no_goals_specified, {RelName, RelVsn}}));
Goals ->
LibDirs = rlx_state:lib_dirs(State1),
Pkgs = subset(maps:to_list(Goals), AllApps, LibDirs),
OrderedGoals = lists:sort(fun compare_goals/2, maps:to_list(Goals)),
Pkgs = subset(OrderedGoals, AllApps, LibDirs),
Pkgs1 = remove_exclude_apps(Pkgs, State1),
set_resolved(Release, Pkgs1, State1)
end.

compare_goals({_, #{index := IndexA}}, {_, #{index := IndexB}}) ->
IndexA < IndexB.

%% find the app_info records for each application and its deps needed for the release
subset(Apps, World, LibDirs) ->
subset(Apps, World, sets:new(), LibDirs, []).
Expand Down
18 changes: 17 additions & 1 deletion test/rlx_release_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ groups() ->
make_exclude_modules_release, make_release_with_sys_config_vm_args_src,
make_exclude_app_release, make_overridden_release, make_goalless_release,
make_one_app_top_level_release, make_release_twice, make_erts_release,
make_erts_config_release, make_included_nodetool_release]},
make_erts_config_release, make_included_nodetool_release, make_release_goal_order]},
{dev_mode, [shuffle], [make_dev_mode_template_release,
make_dev_mode_release,
make_release_twice_dev_mode]},
Expand Down Expand Up @@ -97,6 +97,22 @@ make_release(Config) ->
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)).

make_release_goal_order(Config) ->
LibDir = ?config(lib_dir, Config),
OutputDir = ?config(out_dir, Config),

RelxConfig = [{release, {ordered_foo, "0.0.1"},
[goal_app_2, goal_app_1]}
],

{ok, State} = relx:build_release(ordered_foo, [{root_dir, LibDir}, {lib_dirs, [LibDir]},
{output_dir, OutputDir} | RelxConfig]),

[{{ordered_foo, "0.0.1"}, Release}] = maps:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:app_specs(Release),
?assertMatch([{goal_app_2, "0.0.1"}, {goal_app_1, "0.0.1"} | _], AppSpecs).


make_config_release(Config) ->
DataDir = ?config(priv_dir, Config),
LibDir1 = ?config(lib_dir, Config),
Expand Down