aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2012-12-22 08:18:20 -0800
committerTristan Sloughter <[email protected]>2012-12-22 08:18:20 -0800
commitcef19567813d442fe8190bbd5404e0b6ce3ac153 (patch)
tree9658297244ffaaad8b48a1235591b8973ac24946
parent25483b93b6f179b29742451ac65d367ab3b7ca7e (diff)
parenta9b6d65069ceac9b601216c10a0e60c97a80603a (diff)
downloadrelx-cef19567813d442fe8190bbd5404e0b6ce3ac153.tar.gz
relx-cef19567813d442fe8190bbd5404e0b6ce3ac153.tar.bz2
relx-cef19567813d442fe8190bbd5404e0b6ce3ac153.zip
Merge pull request #18 from ericbmerritt/next
fixes to release assembly
-rw-r--r--src/rcl_cmd_args.erl2
-rw-r--r--src/rcl_prv_assembler.erl68
-rw-r--r--test/rclt_release_SUITE.erl59
3 files changed, 105 insertions, 24 deletions
diff --git a/src/rcl_cmd_args.erl b/src/rcl_cmd_args.erl
index d72bce3..dc176be 100644
--- a/src/rcl_cmd_args.erl
+++ b/src/rcl_cmd_args.erl
@@ -145,7 +145,7 @@ convert_goals([RawSpec | Rest], Acc) ->
{ok, rcl_state:cmd_args()} | relcool:error().
create_output_dir(Opts, Acc) ->
OutputDir = proplists:get_value(output_dir, Opts, "./_rel"),
- create_lib_dirs(Opts, [{output_dir, OutputDir} | Acc]).
+ create_lib_dirs(Opts, [{output_dir, filename:absname(OutputDir)} | Acc]).
-spec create_lib_dirs([getopt:option()], rcl_state:cmd_args()) ->
{ok, rcl_state:cmd_args()} | relcool:error().
diff --git a/src/rcl_prv_assembler.erl b/src/rcl_prv_assembler.erl
index 75a54ec..a721b12 100644
--- a/src/rcl_prv_assembler.erl
+++ b/src/rcl_prv_assembler.erl
@@ -79,7 +79,11 @@ format_error({unable_to_create_output_dir, OutputDir}) ->
[OutputDir]);
format_error({release_script_generation_error, Module, Errors}) ->
["Errors generating release \n",
- rcl_util:indent(1), Module:format_error(Errors)].
+ rcl_util:indent(1), Module:format_error(Errors)];
+format_error({unable_to_make_symlink, AppDir, TargetDir, Reason}) ->
+ io_lib:format("Unable to symlink directory ~s to ~s because \n~s~s",
+ [AppDir, TargetDir, rcl_util:indent(1),
+ file:format_error(Reason)]).
%%%===================================================================
%%% Internal Functions
@@ -108,9 +112,9 @@ copy_app_directories_to_output(State, Release, OutputDir) ->
(_) ->
false
end,
- ec_plists:map(fun(App) ->
- copy_app(LibDir, App)
- end, Apps)),
+ lists:flatten(ec_plists:map(fun(App) ->
+ copy_app(LibDir, App)
+ end, Apps))),
case Result of
[E | _] ->
E;
@@ -123,35 +127,55 @@ copy_app(LibDir, App) ->
AppVsn = rcl_app_info:vsn_as_string(App),
AppDir = rcl_app_info:dir(App),
TargetDir = filename:join([LibDir, AppName ++ "-" ++ AppVsn]),
+ remove_symlink_or_directory(TargetDir),
case rcl_app_info:link(App) of
true ->
- file:make_symlink(AppDir, TargetDir);
+ link_directory(AppDir, TargetDir);
false ->
- ec_plists:map(fun(SubDir) ->
- copy_dir(AppDir, TargetDir, SubDir)
- end, ["ebin",
- "include",
- "priv",
- "src",
- "c_src",
- "README",
- "LICENSE"])
+ copy_directory(AppDir, TargetDir)
end.
+remove_symlink_or_directory(TargetDir) ->
+ case ec_file:is_symlink(TargetDir) of
+ true ->
+ ec_file:remove(TargetDir);
+ false ->
+ case filelib:is_dir(TargetDir) of
+ true ->
+ ok = ec_file:remove(TargetDir, [recursive]);
+ false ->
+ ok
+ end
+ end.
+
+link_directory(AppDir, TargetDir) ->
+ case file:make_symlink(AppDir, TargetDir) of
+ {error, Reason} ->
+ ?RCL_ERROR({unable_to_make_symlink, AppDir, TargetDir, Reason});
+ ok ->
+ ok
+ end.
+
+copy_directory(AppDir, TargetDir) ->
+ ec_plists:map(fun(SubDir) ->
+ copy_dir(AppDir, TargetDir, SubDir)
+ end, ["ebin",
+ "include",
+ "priv",
+ "src",
+ "c_src",
+ "README",
+ "LICENSE"]).
+
copy_dir(AppDir, TargetDir, SubDir) ->
SubSource = filename:join(AppDir, SubDir),
SubTarget = filename:join(TargetDir, SubDir),
case filelib:is_dir(SubSource) of
true ->
- case filelib:is_dir(SubTarget) of
- true ->
- ok = ec_file:remove(SubTarget, [recursive]);
- false ->
- ok
- end,
+ ok = rcl_util:mkdir_p(SubTarget),
case ec_file:copy(SubSource, SubTarget, [recursive]) of
{error, E} ->
- ?RCL_ERROR({ec_file_error, AppDir, TargetDir, E});
+ ?RCL_ERROR({ec_file_error, AppDir, SubTarget, E});
ok ->
ok
end;
@@ -167,7 +191,7 @@ create_release_info(State, Release, OutputDir) ->
rcl_release:vsn(Release)]),
ReleaseFile = filename:join([ReleaseDir, RelName ++ ".rel"]),
ok = ec_file:mkdir_p(ReleaseDir),
- case rcl_release:metadata(Release) of
+ case rcl_release:metadata(Release) of
{ok, Meta} ->
ok = ec_file:write_term(ReleaseFile, Meta),
write_bin_file(State, Release, OutputDir, ReleaseDir);
diff --git a/test/rclt_release_SUITE.erl b/test/rclt_release_SUITE.erl
index 4ac44d9..b37fd12 100644
--- a/test/rclt_release_SUITE.erl
+++ b/test/rclt_release_SUITE.erl
@@ -26,6 +26,7 @@
all/0,
make_release/1,
make_overridden_release/1,
+ make_rerun_overridden_release/1,
make_implicit_config_release/1]).
-include_lib("common_test/include/ct.hrl").
@@ -50,7 +51,8 @@ init_per_testcase(_, Config) ->
{state, State} | Config].
all() ->
- [make_release, make_overridden_release, make_implicit_config_release].
+ [make_release, make_overridden_release, make_implicit_config_release,
+ make_rerun_overridden_release].
make_release(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
@@ -178,6 +180,61 @@ make_implicit_config_release(Config) ->
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)).
+make_rerun_overridden_release(Config) ->
+ DataDir = proplists:get_value(data_dir, Config),
+ OverrideDir1 = filename:join([DataDir, create_random_name("override_dir_")]),
+ LibDir1 = proplists:get_value(lib1, Config),
+ [(fun({Name, Vsn}) ->
+ create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
+ end)(App)
+ ||
+ App <-
+ [{create_random_name("lib_app1_"), create_random_vsn()}
+ || _ <- lists:seq(1, 100)]],
+ OverrideApp = create_random_name("override_app"),
+ OverrideVsn = create_random_vsn(),
+ OverrideAppDir = filename:join(OverrideDir1, OverrideApp),
+ OverrideAppName = erlang:list_to_atom(OverrideApp),
+
+ create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
+ create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
+ create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
+ create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
+ create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
+
+ create_app(OverrideDir1, OverrideApp, OverrideVsn, [stdlib,kernel], []),
+
+ ConfigFile = filename:join([LibDir1, "relcool.config"]),
+ write_config(ConfigFile,
+ [{release, {foo, "0.0.1"},
+ [goal_app_1,
+ erlang:list_to_atom(OverrideApp),
+ goal_app_2]}]),
+ OutputDir = filename:join([proplists:get_value(data_dir, Config),
+ create_random_name("relcool-output")]),
+ {ok, State} = relcool:do(undefined, undefined, [], [LibDir1], 2,
+ OutputDir, [{OverrideAppName, OverrideAppDir}],
+ [ConfigFile]),
+
+ %% Now we run it again to see if it failse.
+ {ok, State} = relcool:do(undefined, undefined, [], [LibDir1], 2,
+ OutputDir, [{OverrideAppName, OverrideAppDir}],
+ [ConfigFile]),
+
+ [{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rcl_state:releases(State)),
+ AppSpecs = rcl_release:applications(Release),
+ ?assert(lists:keymember(stdlib, 1, AppSpecs)),
+ ?assert(lists:keymember(kernel, 1, AppSpecs)),
+ ?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
+ ?assert(lists:member({OverrideAppName, OverrideVsn}, AppSpecs)),
+ ?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
+ {ok, Real} = file:read_link(filename:join([OutputDir, "lib",
+ OverrideApp ++ "-" ++ OverrideVsn])),
+ ?assertMatch(OverrideAppDir, Real).
+
%%%===================================================================
%%% Helper Functions