Fix false reporting of (plain) vsn strings

rebar used to mistakenly report plain version strings like
{vsn, "1.0.0"} as follows:
DEBUG: vcs_vsn: Unknown VCS atom in vsn field: "1.0.0"

Properly detect unknown/unsupported version terms and abort
if we encounter one.

While at it, rename a variable in vcs_vsn/3 to be non-misleading.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/commit/edef0962
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/tree/edef0962
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-rebar/diff/edef0962

Branch: refs/heads/import
Commit: edef0962d2030d462b7ebb150fa387e77ecc86c8
Parents: 988c9cd
Author: Tuncer Ayaz <[email protected]>
Authored: Sun Nov 24 17:37:59 2013 +0100
Committer: Tuncer Ayaz <[email protected]>
Committed: Tue Nov 26 20:33:34 2013 +0100

----------------------------------------------------------------------
 src/rebar_utils.erl | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-rebar/blob/edef0962/src/rebar_utils.erl
----------------------------------------------------------------------
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 4a74661..618427f 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -200,12 +200,12 @@ expand_env_variable(InStr, VarName, RawVarValue) ->
             re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
     end.
 
-vcs_vsn(Config, Vcs, Dir) ->
-    Key = {Vcs, Dir},
+vcs_vsn(Config, Vsn, Dir) ->
+    Key = {Vsn, Dir},
     Cache = rebar_config:get_xconf(Config, vsn_cache),
     case dict:find(Key, Cache) of
         error ->
-            VsnString = vcs_vsn_1(Vcs, Dir),
+            VsnString = vcs_vsn_1(Vsn, Dir),
             Cache1 = dict:store(Key, VsnString, Cache),
             Config1 = rebar_config:set_xconf(Config, vsn_cache, Cache1),
             {Config1, VsnString};
@@ -441,11 +441,12 @@ emulate_escript_foldl(Fun, Acc, File) ->
 
 vcs_vsn_1(Vcs, Dir) ->
     case vcs_vsn_cmd(Vcs) of
-        {unknown, VsnString} ->
-            ?DEBUG("vcs_vsn: Unknown VCS atom in vsn field: ~p\n", [Vcs]),
+        {plain, VsnString} ->
             VsnString;
         {cmd, CmdString} ->
             vcs_vsn_invoke(CmdString, Dir);
+        unknown ->
+            ?ABORT("vcs_vsn: Unknown vsn format: ~p\n", [Vcs]);
         Cmd ->
             %% If there is a valid VCS directory in the application directory,
             %% use that version info
@@ -478,7 +479,8 @@ vcs_vsn_cmd(bzr)    -> "bzr revno";
 vcs_vsn_cmd(svn)    -> "svnversion";
 vcs_vsn_cmd(fossil) -> "fossil info";
 vcs_vsn_cmd({cmd, _Cmd}=Custom) -> Custom;
-vcs_vsn_cmd(Version) -> {unknown, Version}.
+vcs_vsn_cmd(Version) when is_list(Version) -> {plain, Version};
+vcs_vsn_cmd(_) -> unknown.
 
 vcs_vsn_invoke(Cmd, Dir) ->
     {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),

Reply via email to