Clean up and fix vcs functions and logging

This commit is contained in:
Tuncer Ayaz 2011-09-02 14:54:08 +02:00
parent a337939e7a
commit c3a4ed292e

View file

@ -144,9 +144,7 @@ compile(Config, AppFile) ->
Deps = rebar_config:get_local(Config, deps, []), Deps = rebar_config:get_local(Config, deps, []),
case find_deps(find, Deps) of case find_deps(find, Deps) of
{AvailDeps, []} -> {AvailDeps, []} ->
lists:foreach(fun(Dep) -> lists:foreach(fun(Dep) -> print_source(Dep) end, AvailDeps),
?CONSOLE("~s\n", [print_source(Dep#dep.source)])
end, AvailDeps),
ok; ok;
{_, MissingDeps} -> {_, MissingDeps} ->
?ABORT("Missing dependencies: ~p\n", [MissingDeps]) ?ABORT("Missing dependencies: ~p\n", [MissingDeps])
@ -422,17 +420,17 @@ source_engine_avail(Source) ->
source_engine_avail(Name, Source) source_engine_avail(Name, Source)
when Name == hg; Name == git; Name == svn; Name == bzr -> when Name == hg; Name == git; Name == svn; Name == bzr ->
case scm_client_vsn(Name) >= required_scm_client_vsn(Name) of case vcs_client_vsn(Name) >= required_vcs_client_vsn(Name) of
true -> true ->
true; true;
false -> false ->
?ABORT("Rebar requires version ~p or higher of ~s to process ~p\n", ?ABORT("Rebar requires version ~p or higher of ~s to process ~p\n",
[required_scm_client_vsn(Name), Name, Source]) [required_vcs_client_vsn(Name), Name, Source])
end. end.
scm_client_vsn(false, _VsnArg, _VsnRegex) -> vcs_client_vsn(false, _VsnArg, _VsnRegex) ->
false; false;
scm_client_vsn(Path, VsnArg, VsnRegex) -> vcs_client_vsn(Path, VsnArg, VsnRegex) ->
{ok, Info} = rebar_utils:sh(Path ++ VsnArg, [{env, [{"LANG", "C"}]}, {ok, Info} = rebar_utils:sh(Path ++ VsnArg, [{env, [{"LANG", "C"}]},
{use_stdout, false}]), {use_stdout, false}]),
case re:run(Info, VsnRegex, [{capture, all_but_first, list}]) of case re:run(Info, VsnRegex, [{capture, all_but_first, list}]) of
@ -442,22 +440,22 @@ scm_client_vsn(Path, VsnArg, VsnRegex) ->
false false
end. end.
required_scm_client_vsn(hg) -> {1, 1}; required_vcs_client_vsn(hg) -> {1, 1};
required_scm_client_vsn(git) -> {1, 5}; required_vcs_client_vsn(git) -> {1, 5};
required_scm_client_vsn(bzr) -> {2, 0}; required_vcs_client_vsn(bzr) -> {2, 0};
required_scm_client_vsn(svn) -> {1, 6}. required_vcs_client_vsn(svn) -> {1, 6}.
scm_client_vsn(hg) -> vcs_client_vsn(hg) ->
scm_client_vsn(rebar_utils:find_executable("hg"), " --version", vcs_client_vsn(rebar_utils:find_executable("hg"), " --version",
"version (\\d+).(\\d+)"); "version (\\d+).(\\d+)");
scm_client_vsn(git) -> vcs_client_vsn(git) ->
scm_client_vsn(rebar_utils:find_executable("git"), " --version", vcs_client_vsn(rebar_utils:find_executable("git"), " --version",
"git version (\\d+).(\\d+)"); "git version (\\d+).(\\d+)");
scm_client_vsn(bzr) -> vcs_client_vsn(bzr) ->
scm_client_vsn(rebar_utils:find_executable("bzr"), " --version", vcs_client_vsn(rebar_utils:find_executable("bzr"), " --version",
"Bazaar \\(bzr\\) (\\d+).(\\d+)"); "Bazaar \\(bzr\\) (\\d+).(\\d+)");
scm_client_vsn(svn) -> vcs_client_vsn(svn) ->
scm_client_vsn(rebar_utils:find_executable("svn"), " --version", vcs_client_vsn(rebar_utils:find_executable("svn"), " --version",
"svn, version (\\d+).(\\d+)"). "svn, version (\\d+).(\\d+)").
has_vcs_dir(git, Dir) -> has_vcs_dir(git, Dir) ->
@ -472,9 +470,18 @@ has_vcs_dir(svn, Dir) ->
has_vcs_dir(_, _) -> has_vcs_dir(_, _) ->
true. true.
print_source({git, Url}) -> ?FMT("BRANCH ~s ~s", ["HEAD", Url]); print_source(#dep{app=App, source=Source}) ->
print_source({git, Url, ""}) -> ?FMT("BRANCH ~s ~s", ["HEAD", Url]); ?CONSOLE("~s~n", [format_source(App, Source)]).
print_source({git, Url, {branch, Branch}}) -> ?FMT("BRANCH ~s ~s", [Branch, Url]);
print_source({git, Url, {tag, Tag}}) -> ?FMT("TAG ~s ~s", [Tag, Url]);
print_source({_, Url, Rev}) -> ?FMT("REV ~s ~s", [Rev, Url]).
format_source(App, {git, Url}) ->
?FMT("~p BRANCH ~s ~s", [App, "HEAD", Url]);
format_source(App, {git, Url, ""}) ->
?FMT("~p BRANCH ~s ~s", [App, "HEAD", Url]);
format_source(App, {git, Url, {branch, Branch}}) ->
?FMT("~p BRANCH ~s ~s", [App, Branch, Url]);
format_source(App, {git, Url, {tag, Tag}}) ->
?FMT("~p TAG ~s ~s", [App, Tag, Url]);
format_source(App, {_, Url, Rev}) ->
?FMT("~p REV ~s ~s", [App, Rev, Url]);
format_source(App, undefined) ->
?FMT("~p", [App]).