2009-12-31 18:42:53 +00:00
|
|
|
%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
|
|
|
%% ex: ts=4 sw=4 et
|
2009-12-26 06:19:47 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% rebar: Erlang Build Tools
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
|
|
|
|
%%
|
|
|
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
%% of this software and associated documentation files (the "Software"), to deal
|
|
|
|
%% in the Software without restriction, including without limitation the rights
|
|
|
|
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
%% copies of the Software, and to permit persons to whom the Software is
|
|
|
|
%% furnished to do so, subject to the following conditions:
|
|
|
|
%%
|
|
|
|
%% The above copyright notice and this permission notice shall be included in
|
|
|
|
%% all copies or substantial portions of the Software.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
%% THE SOFTWARE.
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
-module(rebar_deps).
|
|
|
|
|
|
|
|
-include("rebar.hrl").
|
|
|
|
|
2010-01-01 02:29:48 +00:00
|
|
|
-export([preprocess/2,
|
2010-06-09 19:16:58 +00:00
|
|
|
postprocess/2,
|
2010-03-25 19:34:19 +00:00
|
|
|
compile/2,
|
|
|
|
'check-deps'/2,
|
2010-06-09 20:07:34 +00:00
|
|
|
'get-deps'/2,
|
|
|
|
'delete-deps'/2]).
|
2010-06-09 19:16:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
-record(dep, { dir,
|
|
|
|
app,
|
|
|
|
vsn_regex,
|
|
|
|
source }).
|
2009-12-26 06:19:47 +00:00
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Public API
|
|
|
|
%% ===================================================================
|
|
|
|
|
|
|
|
preprocess(Config, _) ->
|
2010-06-12 20:55:58 +00:00
|
|
|
%% Side effect to set deps_dir globally for all dependencies from top level down.
|
|
|
|
%% Means the root deps_dir is honoured or the default used globally
|
|
|
|
%% since it will be set on the first time through here
|
|
|
|
set_global_deps_dir(Config, rebar_config:get_global(deps_dir, [])),
|
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
%% Get the list of deps for the current working directory and identify those
|
|
|
|
%% deps that are available/present.
|
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
|
|
|
{AvailableDeps, MissingDeps} = find_deps(Deps),
|
|
|
|
|
|
|
|
?DEBUG("Available deps: ~p\n", [AvailableDeps]),
|
|
|
|
?DEBUG("Missing deps : ~p\n", [MissingDeps]),
|
|
|
|
|
|
|
|
%% Add available deps to code path
|
|
|
|
update_deps_code_path(AvailableDeps),
|
|
|
|
|
2010-06-21 16:24:01 +00:00
|
|
|
%% If skip_deps=true, mark each dep dir as a skip_dir w/ the core so that
|
|
|
|
%% the current command doesn't run on the dep dir. However, pre/postprocess
|
|
|
|
%% WILL run (and we want it to) for transitivity purposes.
|
2010-06-09 19:32:28 +00:00
|
|
|
case rebar_config:get_global(skip_deps, false) of
|
2010-06-21 16:24:01 +00:00
|
|
|
"true" ->
|
2010-10-10 20:11:13 +00:00
|
|
|
lists:foreach(fun (#dep{dir = Dir}) ->
|
|
|
|
rebar_core:skip_dir(Dir)
|
|
|
|
end, AvailableDeps);
|
2010-06-12 20:55:58 +00:00
|
|
|
_ ->
|
2010-06-21 16:24:01 +00:00
|
|
|
ok
|
|
|
|
end,
|
|
|
|
|
|
|
|
%% Return all the available dep directories for process
|
|
|
|
{ok, [D#dep.dir || D <- AvailableDeps]}.
|
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
|
|
|
|
postprocess(_Config, _) ->
|
|
|
|
case erlang:get(?MODULE) of
|
|
|
|
undefined ->
|
|
|
|
{ok, []};
|
|
|
|
Dirs ->
|
|
|
|
erlang:erase(?MODULE),
|
|
|
|
{ok, Dirs}
|
2010-03-16 19:30:22 +00:00
|
|
|
end.
|
|
|
|
|
2010-03-25 19:34:19 +00:00
|
|
|
compile(Config, AppFile) ->
|
|
|
|
'check-deps'(Config, AppFile).
|
|
|
|
|
|
|
|
'check-deps'(Config, _) ->
|
2010-06-09 19:16:58 +00:00
|
|
|
%% Get the list of immediate (i.e. non-transitive) deps that are missing
|
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
|
|
|
case find_deps(Deps) of
|
|
|
|
{_, []} ->
|
|
|
|
%% No missing deps
|
2010-03-25 19:34:19 +00:00
|
|
|
ok;
|
2010-06-09 19:16:58 +00:00
|
|
|
{_, MissingDeps} ->
|
2010-10-10 20:11:13 +00:00
|
|
|
lists:foreach(fun (#dep{app=App, vsn_regex=Vsn, source=Src}) ->
|
|
|
|
?CONSOLE("Dependency not available: ~p-~s (~p)\n",
|
|
|
|
[App, Vsn, Src])
|
|
|
|
end, MissingDeps),
|
2010-06-09 19:16:58 +00:00
|
|
|
?FAIL
|
2010-03-25 19:34:19 +00:00
|
|
|
end.
|
|
|
|
|
2010-03-16 19:30:22 +00:00
|
|
|
'get-deps'(Config, _) ->
|
2010-06-09 19:16:58 +00:00
|
|
|
%% Determine what deps are available and missing
|
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
2010-10-03 15:22:47 +00:00
|
|
|
{AvailableDeps, MissingDeps} = find_deps(Deps),
|
2010-03-16 19:30:22 +00:00
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
%% For each missing dep with a specified source, try to pull it.
|
2010-10-03 15:22:47 +00:00
|
|
|
PulledDeps0 = [use_source(D) || D <- MissingDeps, D#dep.source /= undefined],
|
|
|
|
|
|
|
|
%% For each available dep try to update the source to the specified
|
|
|
|
%% version.
|
|
|
|
PulledDeps1 = [update_source(D) || D <- AvailableDeps,
|
|
|
|
D#dep.source /= undefined],
|
2010-06-09 19:16:58 +00:00
|
|
|
|
|
|
|
%% Add each pulled dep to our list of dirs for post-processing. This yields
|
|
|
|
%% the necessary transitivity of the deps
|
2010-10-03 15:22:47 +00:00
|
|
|
erlang:put(?MODULE, [D#dep.dir || D <- PulledDeps0 ++ PulledDeps1]),
|
2010-06-09 19:16:58 +00:00
|
|
|
ok.
|
2009-12-30 05:05:32 +00:00
|
|
|
|
2010-06-09 20:07:34 +00:00
|
|
|
'delete-deps'(Config, _) ->
|
2010-08-20 16:42:02 +00:00
|
|
|
%% Delete all the available deps in our deps/ directory, if any
|
|
|
|
DepsDir = get_deps_dir(),
|
2010-06-11 16:03:41 +00:00
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
|
|
|
{AvailableDeps, _} = find_deps(Deps),
|
2010-10-10 20:11:13 +00:00
|
|
|
_ = [delete_dep(D) || D <- AvailableDeps,
|
|
|
|
lists:prefix(DepsDir, D#dep.dir) == true],
|
2010-06-11 16:03:41 +00:00
|
|
|
ok.
|
|
|
|
|
2010-06-09 20:07:34 +00:00
|
|
|
|
2009-12-30 05:05:32 +00:00
|
|
|
%% ===================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%% ===================================================================
|
|
|
|
|
2010-06-12 20:55:58 +00:00
|
|
|
%% Added because of trans deps,
|
|
|
|
%% need all deps in same dir and should be the one set by the root rebar.config
|
|
|
|
%% Sets a default if root config has no deps_dir set
|
|
|
|
set_global_deps_dir(Config, []) ->
|
|
|
|
rebar_config:set_global(deps_dir, rebar_config:get_local(Config, deps_dir, "deps"));
|
|
|
|
set_global_deps_dir(_Config, _DepsDir) ->
|
|
|
|
ok.
|
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
get_deps_dir() ->
|
|
|
|
BaseDir = rebar_config:get_global(base_dir, []),
|
2010-06-12 20:55:58 +00:00
|
|
|
DepsDir = rebar_config:get_global(deps_dir, "deps"),
|
|
|
|
filename:join(BaseDir, DepsDir).
|
2010-03-16 19:30:22 +00:00
|
|
|
|
|
|
|
update_deps_code_path([]) ->
|
|
|
|
ok;
|
2010-06-09 19:16:58 +00:00
|
|
|
update_deps_code_path([Dep | Rest]) ->
|
|
|
|
case is_app_available(Dep#dep.app, Dep#dep.vsn_regex, Dep#dep.dir) of
|
|
|
|
{true, _} ->
|
2010-10-25 12:48:17 +00:00
|
|
|
Dir = filename:join(Dep#dep.dir, "ebin"),
|
|
|
|
ok = filelib:ensure_dir(filename:join(Dir, "dummy")),
|
|
|
|
true = code:add_patha(Dir);
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, _} ->
|
2010-10-10 20:11:13 +00:00
|
|
|
true
|
2010-03-16 19:30:22 +00:00
|
|
|
end,
|
|
|
|
update_deps_code_path(Rest).
|
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
find_deps(Deps) ->
|
|
|
|
find_deps(Deps, {[], []}).
|
|
|
|
|
|
|
|
find_deps([], {Avail, Missing}) ->
|
|
|
|
{lists:reverse(Avail), lists:reverse(Missing)};
|
|
|
|
find_deps([App | Rest], Acc) when is_atom(App) ->
|
|
|
|
find_deps([{App, ".*", undefined} | Rest], Acc);
|
|
|
|
find_deps([{App, VsnRegex} | Rest], Acc) when is_atom(App) ->
|
|
|
|
find_deps([{App, VsnRegex, undefined} | Rest], Acc);
|
|
|
|
find_deps([{App, VsnRegex, Source} | Rest], {Avail, Missing}) ->
|
|
|
|
Dep = #dep { app = App,
|
|
|
|
vsn_regex = VsnRegex,
|
|
|
|
source = Source },
|
2009-12-31 03:03:27 +00:00
|
|
|
case is_app_available(App, VsnRegex) of
|
2010-06-09 19:16:58 +00:00
|
|
|
{true, AppDir} ->
|
|
|
|
find_deps(Rest, {[Dep#dep { dir = AppDir } | Avail], Missing});
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, _} ->
|
2010-06-09 19:16:58 +00:00
|
|
|
AppDir = filename:join(get_deps_dir(), Dep#dep.app),
|
|
|
|
case is_app_available(App, VsnRegex, AppDir) of
|
|
|
|
{true, AppDir} ->
|
|
|
|
find_deps(Rest, {[Dep#dep { dir = AppDir } | Avail], Missing});
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, _} ->
|
2010-06-09 19:16:58 +00:00
|
|
|
find_deps(Rest, {Avail, [Dep#dep { dir = AppDir } | Missing]})
|
|
|
|
end
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
2010-06-09 19:16:58 +00:00
|
|
|
find_deps([Other | _Rest], _Acc) ->
|
2009-12-31 03:03:27 +00:00
|
|
|
?ABORT("Invalid dependency specification ~p in ~s\n",
|
|
|
|
[Other, rebar_utils:get_cwd()]).
|
|
|
|
|
|
|
|
|
2010-06-11 16:03:41 +00:00
|
|
|
delete_dep(D) ->
|
|
|
|
case filelib:is_dir(D#dep.dir) of
|
|
|
|
true ->
|
|
|
|
?INFO("Deleting dependency: ~s\n", [D#dep.dir]),
|
|
|
|
rebar_file_utils:rm_rf(D#dep.dir);
|
|
|
|
false ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2009-12-31 03:03:27 +00:00
|
|
|
require_source_engine(Source) ->
|
2010-10-25 22:38:51 +00:00
|
|
|
true = source_engine_avail(Source),
|
|
|
|
ok.
|
2009-12-31 03:03:27 +00:00
|
|
|
|
|
|
|
is_app_available(App, VsnRegex) ->
|
2009-12-30 05:05:32 +00:00
|
|
|
case code:lib_dir(App) of
|
|
|
|
{error, bad_name} ->
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, bad_name};
|
2009-12-30 05:05:32 +00:00
|
|
|
Path ->
|
2009-12-31 03:03:27 +00:00
|
|
|
is_app_available(App, VsnRegex, Path)
|
|
|
|
end.
|
|
|
|
|
|
|
|
is_app_available(App, VsnRegex, Path) ->
|
|
|
|
case rebar_app_utils:is_app_dir(Path) of
|
|
|
|
{true, AppFile} ->
|
2010-04-28 14:44:06 +00:00
|
|
|
case rebar_app_utils:app_name(AppFile) of
|
|
|
|
App ->
|
|
|
|
Vsn = rebar_app_utils:app_vsn(AppFile),
|
2009-12-31 03:03:27 +00:00
|
|
|
?INFO("Looking for ~s-~s ; found ~s-~s at ~s\n",
|
|
|
|
[App, VsnRegex, App, Vsn, Path]),
|
|
|
|
case re:run(Vsn, VsnRegex, [{capture, none}]) of
|
|
|
|
match ->
|
2010-06-09 19:16:58 +00:00
|
|
|
{true, Path};
|
2009-12-31 03:03:27 +00:00
|
|
|
nomatch ->
|
|
|
|
?WARN("~s has version ~p; requested regex was ~s\n",
|
|
|
|
[AppFile, Vsn, VsnRegex]),
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, version_mismatch}
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
2010-04-28 14:44:06 +00:00
|
|
|
OtherApp ->
|
2009-12-31 03:03:27 +00:00
|
|
|
?WARN("~s has application id ~p; expected ~p\n", [AppFile, OtherApp, App]),
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, name_mismatch}
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
?WARN("Expected ~s to be an app dir (containing ebin/*.app), but no .app found.\n",
|
|
|
|
[Path]),
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, missing_app_file}
|
2009-12-31 03:03:27 +00:00
|
|
|
end.
|
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
use_source(Dep) ->
|
|
|
|
use_source(Dep, 3).
|
2009-12-31 03:03:27 +00:00
|
|
|
|
2010-06-09 19:16:58 +00:00
|
|
|
use_source(Dep, 0) ->
|
|
|
|
?ABORT("Failed to acquire source from ~p after 3 tries.\n", [Dep#dep.source]);
|
|
|
|
use_source(Dep, Count) ->
|
|
|
|
case filelib:is_dir(Dep#dep.dir) of
|
2009-12-31 03:03:27 +00:00
|
|
|
true ->
|
|
|
|
%% Already downloaded -- verify the versioning matches up with our regex
|
2010-06-09 19:16:58 +00:00
|
|
|
case is_app_available(Dep#dep.app, Dep#dep.vsn_regex, Dep#dep.dir) of
|
|
|
|
{true, _} ->
|
2010-10-25 12:48:17 +00:00
|
|
|
Dir = filename:join(Dep#dep.dir, "ebin"),
|
|
|
|
ok = filelib:ensure_dir(filename:join(Dir, "dummy")),
|
2010-10-10 20:11:13 +00:00
|
|
|
%% Available version matches up -- we're good to go;
|
|
|
|
%% add the app dir to our code path
|
2010-10-25 12:48:17 +00:00
|
|
|
true = code:add_patha(Dir),
|
2010-06-09 19:16:58 +00:00
|
|
|
Dep;
|
2010-11-29 23:46:50 +00:00
|
|
|
{false, Reason} ->
|
2009-12-31 03:03:27 +00:00
|
|
|
%% The app that was downloaded doesn't match up (or had
|
|
|
|
%% errors or something). For the time being, abort.
|
2010-11-29 23:46:50 +00:00
|
|
|
?ABORT("Dependency dir ~s failed application validation "
|
|
|
|
"with reason ~p.\n", [Dep#dep.dir, Reason])
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
|
|
|
false ->
|
2010-06-09 19:16:58 +00:00
|
|
|
?CONSOLE("Pulling ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
|
|
|
|
require_source_engine(Dep#dep.source),
|
|
|
|
TargetDir = filename:join(get_deps_dir(), Dep#dep.app),
|
|
|
|
download_source(TargetDir, Dep#dep.source),
|
|
|
|
use_source(Dep#dep { dir = TargetDir }, Count-1)
|
2009-12-31 03:03:27 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
download_source(AppDir, {hg, Url, Rev}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
2010-05-11 21:46:20 +00:00
|
|
|
rebar_utils:sh(?FMT("hg clone -U ~s ~s", [Url, filename:basename(AppDir)]), [], filename:dirname(AppDir)),
|
2010-04-14 16:39:46 +00:00
|
|
|
rebar_utils:sh(?FMT("hg update ~s", [Rev]), [], AppDir);
|
2010-09-15 10:10:53 +00:00
|
|
|
download_source(AppDir, {git, Url, {branch, Branch}}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
|
|
|
rebar_utils:sh(?FMT("git clone -n ~s ~s", [Url, filename:basename(AppDir)]), [], filename:dirname(AppDir)),
|
2010-11-16 01:25:14 +00:00
|
|
|
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), [], AppDir);
|
2010-09-15 10:10:53 +00:00
|
|
|
download_source(AppDir, {git, Url, {tag, Tag}}) ->
|
2010-01-07 14:46:06 +00:00
|
|
|
ok = filelib:ensure_dir(AppDir),
|
2010-05-11 21:46:20 +00:00
|
|
|
rebar_utils:sh(?FMT("git clone -n ~s ~s", [Url, filename:basename(AppDir)]), [], filename:dirname(AppDir)),
|
2010-11-16 01:25:14 +00:00
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), [], AppDir);
|
2010-09-15 10:10:53 +00:00
|
|
|
download_source(AppDir, {git, Url, Rev}) ->
|
|
|
|
download_source(AppDir, {git, Url, {branch, Rev}});
|
2010-03-05 08:06:39 +00:00
|
|
|
download_source(AppDir, {bzr, Url, Rev}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
|
|
|
rebar_utils:sh(?FMT("bzr branch -r ~s ~s ~s",
|
|
|
|
[Rev, Url, filename:basename(AppDir)]), [],
|
|
|
|
filename:dirname(AppDir));
|
2010-03-05 07:50:57 +00:00
|
|
|
download_source(AppDir, {svn, Url, Rev}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
|
|
|
rebar_utils:sh(?FMT("svn checkout -r ~s ~s ~s",
|
|
|
|
[Rev, Url, filename:basename(AppDir)]), [],
|
|
|
|
filename:dirname(AppDir)).
|
2009-12-31 03:03:27 +00:00
|
|
|
|
2010-10-03 15:22:47 +00:00
|
|
|
update_source(Dep) ->
|
2010-12-07 17:37:29 +00:00
|
|
|
%% It's possible when updating a source, that a given dep does not have a
|
|
|
|
%% VCS directory, such as when a source archive is built of a project, with
|
|
|
|
%% all deps already downloaded/included. So, verify that the necessary VCS
|
|
|
|
%% directory exists before attempting to do the update.
|
|
|
|
AppDir = filename:join(get_deps_dir(), Dep#dep.app),
|
|
|
|
case has_vcs_dir(element(1, Dep#dep.source), AppDir) of
|
|
|
|
true ->
|
|
|
|
?CONSOLE("Updating ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
|
|
|
|
require_source_engine(Dep#dep.source),
|
|
|
|
update_source(AppDir, Dep#dep.source),
|
|
|
|
Dep;
|
|
|
|
false ->
|
|
|
|
?WARN("Skipping update for ~p: no VCS directory available!\n", [Dep]),
|
|
|
|
Dep
|
|
|
|
end.
|
2010-10-03 15:22:47 +00:00
|
|
|
|
2010-11-16 01:25:14 +00:00
|
|
|
update_source(AppDir, {git, _Url, {branch, Branch}}) ->
|
|
|
|
rebar_utils:sh(?FMT("git fetch origin", []), [], AppDir),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), [], AppDir);
|
|
|
|
update_source(AppDir, {git, _Url, {tag, Tag}}) ->
|
|
|
|
rebar_utils:sh(?FMT("git fetch --tags origin", []), [], AppDir),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), [], AppDir);
|
2010-10-03 15:22:47 +00:00
|
|
|
update_source(AppDir, {git, Url, Refspec}) ->
|
|
|
|
update_source(AppDir, {git, Url, {branch, Refspec}});
|
|
|
|
update_source(AppDir, {svn, _Url, Rev}) ->
|
|
|
|
rebar_utils:sh(?FMT("svn up -r ~s", [Rev]), [], AppDir);
|
|
|
|
update_source(AppDir, {hg, _Url, Rev}) ->
|
|
|
|
rebar_utils:sh(?FMT("hg pull -u -r ~s", [Rev]), [], AppDir);
|
|
|
|
update_source(AppDir, {bzr, _Url, Rev}) ->
|
|
|
|
rebar_utils:sh(?FMT("bzr update -r ~s", [Rev]), [], AppDir).
|
|
|
|
|
|
|
|
|
2009-12-31 03:03:27 +00:00
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Source helper functions
|
|
|
|
%% ===================================================================
|
2009-12-30 05:05:32 +00:00
|
|
|
|
2010-09-29 21:09:04 +00:00
|
|
|
source_engine_avail({Name, _, _}=Source)
|
2010-03-05 08:06:39 +00:00
|
|
|
when Name == hg; Name == git; Name == svn; Name == bzr ->
|
2010-01-07 14:46:06 +00:00
|
|
|
case scm_client_vsn(Name) >= required_scm_client_vsn(Name) of
|
|
|
|
true ->
|
|
|
|
true;
|
2010-01-06 22:22:05 +00:00
|
|
|
false ->
|
2010-09-29 21:09:04 +00:00
|
|
|
?ABORT("Rebar requires version ~p or higher of ~s to process ~p\n",
|
|
|
|
[required_scm_client_vsn(Name), Name, Source])
|
2010-01-07 14:46:06 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
scm_client_vsn(false, _VsnArg, _VsnRegex) ->
|
|
|
|
false;
|
|
|
|
scm_client_vsn(Path, VsnArg, VsnRegex) ->
|
2010-10-02 20:58:25 +00:00
|
|
|
Info = os:cmd("LANG=C " ++ Path ++ VsnArg),
|
2010-01-07 14:46:06 +00:00
|
|
|
case re:run(Info, VsnRegex, [{capture, all_but_first, list}]) of
|
|
|
|
{match, Match} ->
|
|
|
|
list_to_tuple([list_to_integer(S) || S <- Match]);
|
2010-01-06 22:22:05 +00:00
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end.
|
2010-01-07 14:46:06 +00:00
|
|
|
|
2010-04-14 18:51:52 +00:00
|
|
|
required_scm_client_vsn(hg) -> {1, 1};
|
2010-04-19 14:06:07 +00:00
|
|
|
required_scm_client_vsn(git) -> {1, 5};
|
2010-03-05 08:06:39 +00:00
|
|
|
required_scm_client_vsn(bzr) -> {2, 0};
|
2010-03-05 07:50:57 +00:00
|
|
|
required_scm_client_vsn(svn) -> {1, 6}.
|
2010-01-07 14:46:06 +00:00
|
|
|
|
|
|
|
scm_client_vsn(hg) ->
|
2010-09-29 21:09:04 +00:00
|
|
|
scm_client_vsn(rebar_utils:find_executable("hg"), " --version", "version (\\d+).(\\d+)");
|
2010-01-07 14:46:06 +00:00
|
|
|
scm_client_vsn(git) ->
|
2010-09-29 21:09:04 +00:00
|
|
|
scm_client_vsn(rebar_utils:find_executable("git"), " --version", "git version (\\d+).(\\d+)");
|
2010-03-05 08:06:39 +00:00
|
|
|
scm_client_vsn(bzr) ->
|
2010-09-29 21:09:04 +00:00
|
|
|
scm_client_vsn(rebar_utils:find_executable("bzr"), " --version", "Bazaar \\(bzr\\) (\\d+).(\\d+)");
|
2010-03-05 07:50:57 +00:00
|
|
|
scm_client_vsn(svn) ->
|
2010-10-02 20:58:25 +00:00
|
|
|
scm_client_vsn(rebar_utils:find_executable("svn"), " --version", "svn, version (\\d+).(\\d+)").
|
2010-12-07 17:37:29 +00:00
|
|
|
|
|
|
|
has_vcs_dir(git, Dir) ->
|
|
|
|
filelib:is_dir(filename:join(Dir, ".git"));
|
|
|
|
has_vcs_dir(hg, Dir) ->
|
|
|
|
filelib:is_dir(filename:join(Dir, ".hg"));
|
2010-12-07 18:32:58 +00:00
|
|
|
has_vcs_dir(bzr, Dir) ->
|
|
|
|
filelib:is_dir(filename:join(Dir, ".bzr"));
|
|
|
|
has_vcs_dir(svn, Dir) ->
|
|
|
|
filelib:is_dir(filename:join(Dir, ".svn"))
|
|
|
|
orelse filelib:is_dir(filename:join(Dir, "_svn"));
|
2010-12-07 17:37:29 +00:00
|
|
|
has_vcs_dir(_, _) ->
|
|
|
|
true.
|