Skip to content

Commit

Permalink
Merge pull request #95 from josevalim/jv-default-release
Browse files Browse the repository at this point in the history
Properly detect the default release and fail on conflicts
  • Loading branch information
ericbmerritt committed Nov 22, 2013
2 parents 6316901 + 7eee9d2 commit 04a0d90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/rlx_prv_release.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ create_dep_graph(State) ->
-spec find_default_release(rlx_state:t(), rlx_depsolver:t()) ->
{ok, rlx_state:t()} | relx:error().
find_default_release(State, DepGraph) ->
case rlx_state:default_configured_release(State) of
try rlx_state:default_configured_release(State) of
{undefined, undefined} ->
resolve_default_release(State, DepGraph);
{RelName, undefined} ->
Expand All @@ -97,6 +97,9 @@ find_default_release(State, DepGraph) ->
?RLX_ERROR({no_release_name, Vsn});
{RelName, RelVsn} ->
solve_release(State, DepGraph, RelName, RelVsn)
catch
{multiple_release_names, _, _}=Error ->
?RLX_ERROR(Error)
end.

resolve_default_release(State0, DepGraph) ->
Expand Down Expand Up @@ -128,14 +131,13 @@ resolve_default_version(State0, DepGraph, RelName) ->
boolean().
release_sort({{RelName, RelVsnA}, _},
{{RelName, RelVsnB}, _}) ->
ec_semver:lte(RelVsnA, RelVsnB);
release_sort({{RelNameA, RelVsnA}, _}, {{RelNameB, RelVsnB}, _}) ->
ec_semver:lte(RelVsnB, RelVsnA);
release_sort({{RelA, _}, _}, {{RelB, _}, _}) ->
%% The release names are different. When the releases are named differently
%% we can not just take the lastest version. You *must* provide a default
%% release name at least. So we throw an error here that the top can catch
%% and return
erlang:atom_to_list(RelNameA) =< erlang:atom_to_list(RelNameB) andalso
ec_semver:lte(RelVsnA, RelVsnB).
erlang:throw({multiple_release_names, RelA, RelB}).

solve_release(State0, DepGraph, RelName, RelVsn) ->
ec_cmd_log:debug(rlx_state:log(State0),
Expand Down
11 changes: 9 additions & 2 deletions test/rlx_release_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ make_release(Config) ->
write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]}]),
goal_app_2]},
{release, {foo, "0.0.2"},
[goal_app_1,
goal_app_2]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
create_random_name("relx-output")]),
{ok, State} = relx:do(undefined, undefined, [], [LibDir1], 3,
OutputDir, ConfigFile),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
[{{foo, "0.0.2"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
?assert(lists:keymember(stdlib, 1, AppSpecs)),
?assert(lists:keymember(kernel, 1, AppSpecs)),
Expand Down Expand Up @@ -134,6 +137,10 @@ make_extend_release(Config) ->
{lib_dirs, [filename:join(LibDir1, "*")]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
create_random_name("relx-output")]),

?assertMatch({multiple_release_names,foo_test,foo},
catch relx:do(undefined, undefined, [], [LibDir1], 3, OutputDir, ConfigFile)),

{ok, State} = relx:do(foo_test, undefined, [], [LibDir1], 3,
OutputDir, ConfigFile),
[{{foo_test, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
Expand Down

0 comments on commit 04a0d90

Please sign in to comment.