summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Smith <dizzyd@dizzyd.com>2011-04-10 16:01:23 -0600
committerDave Smith <dizzyd@dizzyd.com>2011-04-10 16:12:50 -0600
commit4dc2414d891753803adefeaeedfcff4bcb8b65a5 (patch)
tree6fa2a6b4a63d0ed89412257faa2ab51de7d05ff4
parentc4907b62976a3b2341ba1cf16d5276c40634f95c (diff)
Add support for priv/<vcs.vsn> as fallback for version info
-rw-r--r--src/rebar_app_utils.erl28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index 911f436..7e6cbd9 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -129,10 +129,30 @@ get_value(Key, AppInfo, AppFile) ->
vcs_vsn(Vcs, Dir) ->
case vcs_vsn_cmd(Vcs) of
{unknown, VsnString} ->
+ ?DEBUG("vcs_vsn: Unknown VCS atom in vsn field: ~p\n", [Vcs]),
VsnString;
Cmd ->
- {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
- string:strip(VsnString, right, $\n)
+ %% If there is a valid VCS directory in the application directory,
+ %% use that version info
+ Extension = lists:concat([".", Vcs]),
+ case filelib:is_dir(filename:join(Dir, Extension)) of
+ true ->
+ ?DEBUG("vcs_vsn: Primary vcs used for ~s\n", [Dir]),
+ vcs_vsn_invoke(Cmd, Dir);
+ false ->
+ %% No VCS directory found for the app. Depending on source
+ %% tree structure, there may be one higher up, but that can
+ %% yield unexpected results when used with deps. So, we
+ %% fallback to searching for a priv/vsn.Vcs file.
+ case file:read_file(filename:join([Dir, "priv", "vsn" ++ Extension])) of
+ {ok, VsnBin} ->
+ ?DEBUG("vcs_vsn: Read ~s from priv/vsn.~p\n", [VsnBin, Vcs]),
+ string:strip(binary_to_list(VsnBin), right, $\n);
+ {error, enoent} ->
+ ?DEBUG("vcs_vsn: Fallback to vcs for ~s\n", [Dir]),
+ vcs_vsn_invoke(Cmd, Dir)
+ end
+ end
end.
vcs_vsn_cmd(git) -> "git describe --always --tags";
@@ -140,3 +160,7 @@ vcs_vsn_cmd(hg) -> "hg identify -i";
vcs_vsn_cmd(bzr) -> "bzr revno";
vcs_vsn_cmd(svn) -> "svnversion";
vcs_vsn_cmd(Version) -> {unknown, Version}.
+
+vcs_vsn_invoke(Cmd, Dir) ->
+ {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
+ string:strip(VsnString, right, $\n).