diff options
author | Alexey Romanov <alexey.v.romanov@gmail.com> | 2011-02-21 12:41:20 +0300 |
---|---|---|
committer | Alexey Romanov <alexey.v.romanov@gmail.com> | 2011-02-21 12:41:20 +0300 |
commit | 7dc371d8a3b9a6e2ab9f814c0d2536cf638ceb99 (patch) | |
tree | 174193ae08d2824164ba99e63f696a6593ee63c6 /src/rebar_rel_utils.erl | |
parent | 2ceeb3272139b7569c8dabc215ca1e7063b0d385 (diff) | |
parent | 6056c63eed288736c912c82d6f36aa7dd055f9ca (diff) |
Merge branch 'master' of https://github.com/basho/rebar
Diffstat (limited to 'src/rebar_rel_utils.erl')
-rw-r--r-- | src/rebar_rel_utils.erl | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl index b955a53..9729e20 100644 --- a/src/rebar_rel_utils.erl +++ b/src/rebar_rel_utils.erl @@ -1,4 +1,4 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% @@ -26,16 +26,62 @@ %% ------------------------------------------------------------------- -module(rebar_rel_utils). --export([is_rel_dir/0, is_rel_dir/1]). +-export([is_rel_dir/0, + is_rel_dir/1, + get_reltool_release_info/1, + get_rel_release_info/1, + get_rel_release_info/2, + get_previous_release_path/0]). + +-include("rebar.hrl"). is_rel_dir() -> is_rel_dir(rebar_utils:get_cwd()). is_rel_dir(Dir) -> Fname = filename:join([Dir, "reltool.config"]), - case filelib:is_file(Fname) of + case filelib:is_regular(Fname) of true -> {true, Fname}; false -> false 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 release name and version from a rel file +get_rel_release_info(RelFile) -> + case file:consult(RelFile) of + {ok, [{release, {Name, Ver}, _, _}]} -> + {Name, Ver}; + _ -> + ?ABORT("Failed to parse ~s~n", [RelFile]) + end. + +%% Get release name and version from a name and a path +get_rel_release_info(Name, Path) -> + [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*", + Name ++ ".rel"])), + [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""), + get_rel_release_info(filename:join([binary_to_list(BinDir), + Name ++ ".rel"])). + +%% Get the previous release path from a global variable +get_previous_release_path() -> + case rebar_config:get_global(previous_release, false) of + false -> + ?ABORT("previous_release=PATH is required to " + "create upgrade package~n", []); + OldVerPath -> + OldVerPath + end. |