summaryrefslogtreecommitdiff
path: root/src/rebar_rel_utils.erl
diff options
context:
space:
mode:
authorSteven Gravell <steve.gravell@smarkets.com>2011-06-30 22:50:56 +0100
committerSteven Gravell <steve.gravell@smarkets.com>2011-07-01 18:04:32 +0100
commit0f5e3932920969dba70ae8d7edcdfa97bb472c28 (patch)
treea35a9c4443b8e89653ff6c3d54fe8d1133058ef7 /src/rebar_rel_utils.erl
parent3e4138537f089c8c1a5e5f9173603569aa012eca (diff)
look for new and old versions in the target parent
The target_dir config in reltool allows you to put your release in a directory other than in ./NAME, so we should look in the parent directory of that to find the new and old versions instead of simply looking in ./ Move untaring and retaring into a temporary path instead of in ./ to prevent name collisions with "releases" and "lib" that might exist already. Having a subdirectory rel/releases/ can be useful.
Diffstat (limited to 'src/rebar_rel_utils.erl')
-rw-r--r--src/rebar_rel_utils.erl74
1 files changed, 63 insertions, 11 deletions
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl
index 0b14a28..627ce13 100644
--- a/src/rebar_rel_utils.erl
+++ b/src/rebar_rel_utils.erl
@@ -34,7 +34,11 @@
get_rel_apps/1,
get_rel_apps/2,
get_previous_release_path/0,
- get_rel_file_path/2]).
+ get_rel_file_path/2,
+ load_config/1,
+ get_sys_tuple/1,
+ get_target_dir/1,
+ get_target_parent_dir/1]).
-include("rebar.hrl").
@@ -51,16 +55,11 @@ is_rel_dir(Dir) ->
end.
%% Get release name and version from a reltool.config
-get_reltool_release_info(ReltoolFile) ->
- %% expect sys to be the first proplist in reltool.config
- case file:consult(ReltoolFile) of
- {ok, [{sys, Config}| _]} ->
- %% expect the first rel in the proplist to be the one you want
- {rel, Name, Ver, _} = proplists:lookup(rel, Config),
- {Name, Ver};
- _ ->
- ?ABORT("Failed to parse ~s~n", [ReltoolFile])
- end.
+get_reltool_release_info(ReltoolConfig) ->
+ %% expect the first rel in the proplist to be the one you want
+ {sys, Config} = get_sys_tuple(ReltoolConfig),
+ {rel, Name, Ver, _} = proplists:lookup(rel, Config),
+ {Name, Ver}.
%% Get release name and version from a rel file
get_rel_release_info(RelFile) ->
@@ -107,6 +106,59 @@ get_previous_release_path() ->
OldVerPath
end.
+%%
+%% Load terms from reltool.config
+%%
+load_config(ReltoolFile) ->
+ case file:consult(ReltoolFile) of
+ {ok, Terms} ->
+ Terms;
+ Other ->
+ ?ABORT("Failed to load expected config from ~s: ~p\n",
+ [ReltoolFile, Other])
+ end.
+
+%%
+%% Look for the {sys, [...]} tuple in the reltool.config file.
+%% Without this present, we can't run reltool.
+%%
+get_sys_tuple(ReltoolConfig) ->
+ case lists:keyfind(sys, 1, ReltoolConfig) of
+ {sys, _} = SysTuple ->
+ SysTuple;
+ false ->
+ ?ABORT("Failed to find {sys, [...]} tuple in reltool.config.", [])
+ end.
+
+%%
+%% Look for {target_dir, TargetDir} in the reltool config file; if none is
+%% found, use the name of the release as the default target directory.
+%%
+get_target_dir(ReltoolConfig) ->
+ case rebar_config:get_global(target_dir, undefined) of
+ undefined ->
+ case lists:keyfind(target_dir, 1, ReltoolConfig) of
+ {target_dir, TargetDir} ->
+ filename:absname(TargetDir);
+ false ->
+ {sys, SysInfo} = get_sys_tuple(ReltoolConfig),
+ case lists:keyfind(rel, 1, SysInfo) of
+ {rel, Name, _Vsn, _Apps} ->
+ filename:absname(Name);
+ false ->
+ filename:absname("target")
+ end
+ end;
+ TargetDir ->
+ filename:absname(TargetDir)
+ end.
+
+get_target_parent_dir(ReltoolConfig) ->
+ case lists:reverse(tl(lists:reverse(filename:split(get_target_dir(ReltoolConfig))))) of
+ [] -> ".";
+ Components -> filename:join(Components)
+ end.
+
%% ===================================================================
%% Internal functions
%% ===================================================================