diff options
author | Joe Williams <joe@joetify.com> | 2011-07-01 11:16:14 -0700 |
---|---|---|
committer | Joe Williams <joe@joetify.com> | 2011-07-01 11:16:14 -0700 |
commit | 18d4ddc8d0dc7c28f55def020c3ef947e24106a9 (patch) | |
tree | f2dd983603888e7342b7e4bdc02ff083495afdac /src/rebar_rel_utils.erl | |
parent | 4c5ec87988bee1448bae426a90ca7621d77938d2 (diff) | |
parent | 0f5e3932920969dba70ae8d7edcdfa97bb472c28 (diff) |
Merge pull request #90 from smarkets/upgrade-fixes
look for new and old versions in the target parent
Diffstat (limited to 'src/rebar_rel_utils.erl')
-rw-r--r-- | src/rebar_rel_utils.erl | 74 |
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 %% =================================================================== |