diff options
author | joewilliams <joe@joetify.com> | 2011-02-10 13:27:29 -0800 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-02-15 18:33:18 +0100 |
commit | 11bf6b4aab33c273f0db94bded8763af68cbc167 (patch) | |
tree | 659ba5e779cb938185df23409b61617a46f619dc /src/rebar_utils.erl | |
parent | 9ee8ed91812f22e6e84887ba006f3a5c37457fcc (diff) |
Add 'generate-appups' command
To further support OTP releases I have added support for generating
application appup files. These include instructions that systools uses
to generate a relup file which contains the low level instructions
needed to perform a hot code upgrade. My goal with this module is to
produce "good enough" appup files or at least a skeleton to help one get
started with something more complex. If an appup file already exists for
an application this command will not attempt to create a new one.
Usage:
$ rebar generate-appups previous_release=/path/to/old/version
Generally this command will be run just before 'generate-upgrade'.
Diffstat (limited to 'src/rebar_utils.erl')
-rw-r--r-- | src/rebar_utils.erl | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index c8eccc4..dc7de9b 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -37,7 +37,11 @@ erl_to_mod/1, abort/2, escript_foldl/3, - find_executable/1]). + find_executable/1, + get_reltool_release_info/1, + get_rel_release_info/2, + get_previous_release_path/0, + prop_check/3]). -include("rebar.hrl"). @@ -151,6 +155,42 @@ find_executable(Name) -> "\"" ++ filename:nativename(Path) ++ "\"" 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(Name, Path) -> + [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*", + Name ++ ".rel"])), + [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""), + {ok, [{release, {Name1, Ver}, _, _}]} = + file:consult(filename:join([binary_to_list(BinDir), + Name ++ ".rel"])), + {Name1, Ver}. + +%% 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. + +%% Helper function for checking values and aborting when needed +prop_check(true, _, _) -> true; +prop_check(false, Msg, Args) -> ?ABORT(Msg, Args). + %% ==================================================================== %% Internal functions %% ==================================================================== |