diff options
author | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-11-26 12:01:13 +0100 |
---|---|---|
committer | Tuncer Ayaz <tuncer.ayaz@gmail.com> | 2011-11-26 12:01:13 +0100 |
commit | a6fdac99a42093ee7038f006e418f2160fe0633f (patch) | |
tree | c752bb7c1149221af6fa6500393780ec7a042c2a | |
parent | ab79534507f5f7bf19b2f06c8e22043399b5dbb3 (diff) |
Fix and refactor reltool root_dir lookup
-rw-r--r-- | src/rebar_rel_utils.erl | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl index 91e1aea..bc77c46 100644 --- a/src/rebar_rel_utils.erl +++ b/src/rebar_rel_utils.erl @@ -159,23 +159,6 @@ get_target_dir(ReltoolConfig) -> filename:absname(TargetDir) end. -%% -%% Look for {root_dir, RootDir} in the reltool config file; if none is -%% found, use the name of the release as the default target directory. -%% -get_root_dir(ReltoolConfig) -> - case rebar_config:get_global(root_dir, undefined) of - undefined -> - case lists:keyfind(root_dir, 1, ReltoolConfig) of - {root_dir, RootDir} -> - filename:absname(RootDir); - false -> - code:root_dir() - end; - RootDir -> - filename:absname(RootDir) - end. - get_target_parent_dir(ReltoolConfig) -> TargetDir = get_target_dir(ReltoolConfig), case lists:reverse(tl(lists:reverse(filename:split(TargetDir)))) of @@ -183,6 +166,36 @@ get_target_parent_dir(ReltoolConfig) -> Components -> filename:join(Components) end. +%% +%% Look for root_dir in sys tuple and command line; fall back to +%% code:root_dir(). +%% +get_root_dir(ReltoolConfig) -> + {sys, SysInfo} = get_sys_tuple(ReltoolConfig), + SysRootDirTuple = lists:keyfind(root_dir, 1, SysInfo), + CmdRootDir = rebar_config:get_global(root_dir, undefined), + case {SysRootDirTuple, CmdRootDir} of + %% root_dir in sys typle and no root_dir on cmd-line + {{root_dir, SysRootDir}, undefined} -> + SysRootDir; + %% root_dir in sys typle and also root_dir on cmd-line + {{root_dir, SysRootDir}, CmdRootDir} when CmdRootDir =/= undefined -> + case string:equal(SysRootDir, CmdRootDir) of + true -> + ok; + false -> + ?WARN("overriding reltool.config root_dir with " + "different command line root_dir~n", []) + end, + CmdRootDir; + %% no root_dir in sys typle and no root_dir on cmd-line + {false, undefined} -> + code:root_dir(); + %% no root_dir in sys tuple but root_dir on cmd-line + {false, CmdRootDir} when CmdRootDir =/= undefined -> + CmdRootDir + end. + %% =================================================================== %% Internal functions %% =================================================================== @@ -194,4 +207,4 @@ make_proplist([H|T], Acc) -> Ver = element(2, H), make_proplist(T, [{App,Ver}|Acc]); make_proplist([], Acc) -> - Acc.
\ No newline at end of file + Acc. |