2011-01-31 16:43:31 +00:00
|
|
|
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
2009-12-31 18:42:53 +00:00
|
|
|
%% 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,
|
2011-05-09 04:46:44 +00:00
|
|
|
setup_env/1,
|
2010-03-25 19:34:19 +00:00
|
|
|
'check-deps'/2,
|
2010-06-09 20:07:34 +00:00
|
|
|
'get-deps'/2,
|
2010-12-09 18:45:58 +00:00
|
|
|
'update-deps'/2,
|
2011-04-21 12:08:40 +00:00
|
|
|
'delete-deps'/2,
|
|
|
|
'list-deps'/2]).
|
2010-06-09 19:16:58 +00:00
|
|
|
|
2012-11-10 20:59:19 +00:00
|
|
|
%% for internal use only
|
|
|
|
-export([info/2]).
|
2010-06-09 19:16:58 +00:00
|
|
|
|
|
|
|
-record(dep, { dir,
|
|
|
|
app,
|
|
|
|
vsn_regex,
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
source,
|
|
|
|
is_raw }). %% is_raw = true means non-Erlang/OTP dependency
|
2009-12-26 06:19:47 +00:00
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Public API
|
|
|
|
%% ===================================================================
|
|
|
|
|
|
|
|
preprocess(Config, _) ->
|
2011-01-28 15:08:27 +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
|
2012-07-23 18:53:43 +00:00
|
|
|
Config1 = set_shared_deps_dir(Config, get_shared_deps_dir(Config, [])),
|
2010-06-12 20:55:58 +00:00
|
|
|
|
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.
|
2012-07-14 21:44:47 +00:00
|
|
|
Deps = rebar_config:get_local(Config1, deps, []),
|
|
|
|
{Config2, {AvailableDeps, MissingDeps}} = find_deps(Config1, find, Deps),
|
2010-06-09 19:16:58 +00:00
|
|
|
|
|
|
|
?DEBUG("Available deps: ~p\n", [AvailableDeps]),
|
|
|
|
?DEBUG("Missing deps : ~p\n", [MissingDeps]),
|
|
|
|
|
|
|
|
%% Add available deps to code path
|
2012-07-14 21:44:47 +00:00
|
|
|
Config3 = update_deps_code_path(Config2, AvailableDeps),
|
2010-06-09 19:16:58 +00:00
|
|
|
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
%% Filtering out 'raw' dependencies so that no commands other than
|
|
|
|
%% deps-related can be executed on their directories.
|
|
|
|
NonRawAvailableDeps = [D || D <- AvailableDeps, not D#dep.is_raw],
|
|
|
|
|
2013-10-16 10:29:54 +00:00
|
|
|
case rebar_config:get_xconf(Config, current_command, undefined) of
|
2013-09-19 21:36:02 +00:00
|
|
|
'update-deps' ->
|
|
|
|
%% Skip ALL of the dep folders, we do this because we don't want
|
|
|
|
%% any other calls to preprocess() for update-deps beyond the
|
|
|
|
%% toplevel directory. They aren't actually harmful, but they slow
|
|
|
|
%% things down unnecessarily.
|
2013-10-16 10:54:06 +00:00
|
|
|
NewConfig = lists:foldl(
|
|
|
|
fun(D, Acc) ->
|
|
|
|
rebar_config:set_skip_dir(Acc, D#dep.dir)
|
|
|
|
end,
|
|
|
|
Config3,
|
|
|
|
collect_deps(rebar_utils:get_cwd(), Config3)),
|
2013-09-19 21:36:02 +00:00
|
|
|
%% Return the empty list, as we don't want anything processed before
|
|
|
|
%% us.
|
2013-09-23 19:11:11 +00:00
|
|
|
{ok, NewConfig, []};
|
2013-09-19 21:36:02 +00:00
|
|
|
_ ->
|
2013-10-16 10:54:06 +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.
|
2013-09-23 19:11:11 +00:00
|
|
|
%%
|
|
|
|
%% Also, if skip_deps=comma,separated,app,list, then only the given
|
|
|
|
%% dependencies are skipped.
|
2013-10-16 10:54:06 +00:00
|
|
|
NewConfig =
|
|
|
|
case rebar_config:get_global(Config3, skip_deps, false) of
|
|
|
|
"true" ->
|
|
|
|
lists:foldl(
|
|
|
|
fun(#dep{dir = Dir}, C) ->
|
|
|
|
rebar_config:set_skip_dir(C, Dir)
|
|
|
|
end, Config3, AvailableDeps);
|
|
|
|
Apps when is_list(Apps) ->
|
|
|
|
SkipApps = [list_to_atom(App) ||
|
|
|
|
App <- string:tokens(Apps, ",")],
|
|
|
|
lists:foldl(
|
|
|
|
fun(#dep{dir = Dir, app = App}, C) ->
|
|
|
|
case lists:member(App, SkipApps) of
|
|
|
|
true -> rebar_config:set_skip_dir(C, Dir);
|
|
|
|
false -> C
|
|
|
|
end
|
|
|
|
end, Config3, AvailableDeps);
|
|
|
|
_ ->
|
|
|
|
Config3
|
|
|
|
end,
|
2013-09-23 19:11:11 +00:00
|
|
|
|
2013-09-19 21:36:02 +00:00
|
|
|
%% Return all the available dep directories for process
|
|
|
|
{ok, NewConfig, dep_dirs(NonRawAvailableDeps)}
|
|
|
|
end.
|
2010-06-21 16:24:01 +00:00
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
postprocess(Config, _) ->
|
2012-07-14 21:44:47 +00:00
|
|
|
case rebar_config:get_xconf(Config, ?MODULE, undefined) of
|
|
|
|
undefined ->
|
2010-06-09 19:16:58 +00:00
|
|
|
{ok, []};
|
2012-07-14 21:44:47 +00:00
|
|
|
Dirs ->
|
2012-04-22 19:53:32 +00:00
|
|
|
NewConfig = rebar_config:erase_xconf(Config, ?MODULE),
|
|
|
|
{ok, NewConfig, Dirs}
|
2010-03-16 19:30:22 +00:00
|
|
|
end.
|
|
|
|
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
compile(Config, _) ->
|
|
|
|
{Config1, _AvailDeps} = do_check_deps(Config),
|
|
|
|
{ok, Config1}.
|
2010-03-25 19:34:19 +00:00
|
|
|
|
2011-05-09 04:46:44 +00:00
|
|
|
%% set REBAR_DEPS_DIR and ERL_LIBS environment variables
|
2012-07-14 21:44:47 +00:00
|
|
|
setup_env(Config) ->
|
|
|
|
{true, DepsDir} = get_deps_dir(Config),
|
2011-05-09 04:46:44 +00:00
|
|
|
%% include rebar's DepsDir in ERL_LIBS
|
2012-04-04 15:42:39 +00:00
|
|
|
Separator = case os:type() of
|
|
|
|
{win32, nt} ->
|
|
|
|
";";
|
|
|
|
_ ->
|
|
|
|
":"
|
|
|
|
end,
|
2011-05-09 04:46:44 +00:00
|
|
|
ERL_LIBS = case os:getenv("ERL_LIBS") of
|
|
|
|
false ->
|
|
|
|
{"ERL_LIBS", DepsDir};
|
|
|
|
PrevValue ->
|
2012-04-04 15:42:39 +00:00
|
|
|
{"ERL_LIBS", DepsDir ++ Separator ++ PrevValue}
|
2011-05-09 04:46:44 +00:00
|
|
|
end,
|
|
|
|
[{"REBAR_DEPS_DIR", DepsDir}, ERL_LIBS].
|
|
|
|
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
%% common function used by 'check-deps' and 'compile'
|
|
|
|
do_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, []),
|
2012-04-22 19:53:32 +00:00
|
|
|
case find_deps(Config, find, Deps) of
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
{Config1, {AvailDeps, []}} ->
|
2010-06-09 19:16:58 +00:00
|
|
|
%% No missing deps
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
{Config1, AvailDeps};
|
2012-04-22 19:53:32 +00:00
|
|
|
{_Config1, {_, MissingDeps}} ->
|
2010-10-10 20:11:13 +00:00
|
|
|
lists:foreach(fun (#dep{app=App, vsn_regex=Vsn, source=Src}) ->
|
2011-01-28 15:08:27 +00:00
|
|
|
?CONSOLE("Dependency not available: "
|
|
|
|
"~p-~s (~p)\n", [App, Vsn, Src])
|
|
|
|
end, MissingDeps),
|
2012-07-28 17:51:57 +00:00
|
|
|
?FAIL
|
2010-03-25 19:34:19 +00:00
|
|
|
end.
|
|
|
|
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
'check-deps'(Config, _) ->
|
|
|
|
{Config1, AvailDeps} = do_check_deps(Config),
|
|
|
|
{ok, save_dep_dirs(Config1, AvailDeps)}.
|
|
|
|
|
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, []),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {_AvailableDeps, MissingDeps}} = find_deps(Config, find, Deps),
|
|
|
|
MissingDeps1 = [D || D <- MissingDeps, D#dep.source =/= undefined],
|
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.
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config2, PulledDeps} =
|
|
|
|
lists:foldl(fun(D, {C, PulledDeps0}) ->
|
|
|
|
{C1, D1} = use_source(C, D),
|
|
|
|
{C1, [D1 | PulledDeps0]}
|
|
|
|
end, {Config1, []}, MissingDeps1),
|
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
|
2012-04-22 19:53:32 +00:00
|
|
|
{ok, save_dep_dirs(Config2, lists:reverse(PulledDeps))}.
|
2010-12-09 18:45:58 +00:00
|
|
|
|
|
|
|
'update-deps'(Config, _) ->
|
2013-10-16 10:49:06 +00:00
|
|
|
Config1 = rebar_config:set_xconf(Config, depowner, dict:new()),
|
|
|
|
{Config2, UpdatedDeps} = update_deps_int(Config1, []),
|
|
|
|
DepOwners = rebar_config:get_xconf(Config2, depowner, dict:new()),
|
2013-09-19 21:36:02 +00:00
|
|
|
|
|
|
|
%% check for conflicting deps
|
2013-10-16 10:36:32 +00:00
|
|
|
_ = [?ERROR("Conflicting dependencies for ~p: ~p~n",
|
|
|
|
[K, [{"From: " ++ string:join(dict:fetch(D, DepOwners), ", "),
|
|
|
|
{D#dep.vsn_regex, D#dep.source}} || D <- V]])
|
|
|
|
|| {K, V} <- dict:to_list(
|
|
|
|
lists:foldl(
|
|
|
|
fun(Dep, Acc) ->
|
|
|
|
dict:append(Dep#dep.app, Dep, Acc)
|
|
|
|
end, dict:new(), UpdatedDeps)),
|
|
|
|
length(V) > 1],
|
2012-04-22 19:53:32 +00:00
|
|
|
|
2010-12-09 18:45:58 +00:00
|
|
|
%% Add each updated dep to our list of dirs for post-processing. This yields
|
|
|
|
%% the necessary transitivity of the deps
|
2013-09-19 21:36:02 +00:00
|
|
|
{ok, save_dep_dirs(Config, UpdatedDeps)}.
|
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
|
2012-07-14 21:44:47 +00:00
|
|
|
{true, DepsDir} = get_deps_dir(Config),
|
2010-06-11 16:03:41 +00:00
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {AvailableDeps, _}} = find_deps(Config, find, Deps),
|
2011-01-08 18:09:24 +00:00
|
|
|
_ = [delete_dep(D)
|
|
|
|
|| D <- AvailableDeps,
|
|
|
|
lists:prefix(DepsDir, D#dep.dir)],
|
2012-04-22 19:53:32 +00:00
|
|
|
{ok, Config1}.
|
2010-06-11 16:03:41 +00:00
|
|
|
|
2011-04-21 12:08:40 +00:00
|
|
|
'list-deps'(Config, _) ->
|
|
|
|
Deps = rebar_config:get_local(Config, deps, []),
|
2012-04-22 19:53:32 +00:00
|
|
|
case find_deps(Config, find, Deps) of
|
|
|
|
{Config1, {AvailDeps, []}} ->
|
2011-09-02 12:54:08 +00:00
|
|
|
lists:foreach(fun(Dep) -> print_source(Dep) end, AvailDeps),
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
{ok, save_dep_dirs(Config1, AvailDeps)};
|
2011-04-21 12:08:40 +00:00
|
|
|
{_, MissingDeps} ->
|
|
|
|
?ABORT("Missing dependencies: ~p\n", [MissingDeps])
|
|
|
|
end.
|
|
|
|
|
2009-12-30 05:05:32 +00:00
|
|
|
%% ===================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%% ===================================================================
|
|
|
|
|
2012-11-10 20:59:19 +00:00
|
|
|
info(help, compile) ->
|
|
|
|
info_help("Display to be fetched dependencies");
|
|
|
|
info(help, 'check-deps') ->
|
|
|
|
info_help("Display to be fetched dependencies");
|
|
|
|
info(help, 'get-deps') ->
|
|
|
|
info_help("Fetch dependencies");
|
|
|
|
info(help, 'update-deps') ->
|
|
|
|
info_help("Update fetched dependencies");
|
|
|
|
info(help, 'delete-deps') ->
|
|
|
|
info_help("Delete fetched dependencies");
|
|
|
|
info(help, 'list-deps') ->
|
|
|
|
info_help("List dependencies").
|
|
|
|
|
|
|
|
info_help(Description) ->
|
|
|
|
?CONSOLE(
|
|
|
|
"~s.~n"
|
|
|
|
"~n"
|
|
|
|
"Valid rebar.config options:~n"
|
|
|
|
" ~p~n"
|
|
|
|
" ~p~n"
|
|
|
|
"Valid command line options:~n"
|
|
|
|
" deps_dir=\"deps\" (override default or rebar.config deps_dir)~n",
|
|
|
|
[
|
|
|
|
Description,
|
|
|
|
{deps_dir, "deps"},
|
2013-11-24 14:36:54 +00:00
|
|
|
{deps,
|
|
|
|
[app_name,
|
|
|
|
{rebar, "1.0.*"},
|
|
|
|
{rebar, ".*",
|
|
|
|
{git, "git://github.com/rebar/rebar.git"}},
|
|
|
|
{rebar, ".*",
|
|
|
|
{git, "git://github.com/rebar/rebar.git", "Rev"}},
|
|
|
|
{rebar, "1.0.*",
|
|
|
|
{git, "git://github.com/rebar/rebar.git", {branch, "master"}}},
|
|
|
|
{rebar, "1.0.0",
|
|
|
|
{git, "git://github.com/rebar/rebar.git", {tag, "1.0.0"}}},
|
|
|
|
{rebar, "",
|
|
|
|
{git, "git://github.com/rebar/rebar.git", {branch, "master"}},
|
|
|
|
[raw]},
|
|
|
|
{app_name, ".*", {hg, "https://www.example.org/url"}},
|
|
|
|
{app_name, ".*", {rsync, "Url"}},
|
|
|
|
{app_name, ".*", {svn, "https://www.example.org/url"}},
|
|
|
|
{app_name, ".*", {svn, "svn://svn.example.org/url"}},
|
|
|
|
{app_name, ".*", {bzr, "https://www.example.org/url", "Rev"}},
|
|
|
|
{app_name, ".*", {fossil, "https://www.example.org/url"}},
|
2013-09-17 15:22:05 +00:00
|
|
|
{app_name, ".*", {fossil, "https://www.example.org/url", "Vsn"}},
|
|
|
|
{app_name, ".*", {p4, "//depot/subdir/app_dir"}}]}
|
2012-11-10 20:59:19 +00:00
|
|
|
]).
|
|
|
|
|
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
|
2013-06-17 21:28:52 +00:00
|
|
|
%% In case one is given globally, it has higher priority
|
2010-06-12 20:55:58 +00:00
|
|
|
%% Sets a default if root config has no deps_dir set
|
2012-07-23 18:53:43 +00:00
|
|
|
set_shared_deps_dir(Config, []) ->
|
2013-06-17 21:28:52 +00:00
|
|
|
LocalDepsDir = rebar_config:get_local(Config, deps_dir, "deps"),
|
2013-07-02 16:59:26 +00:00
|
|
|
GlobalDepsDir = rebar_config:get_global(Config, deps_dir, LocalDepsDir),
|
|
|
|
DepsDir = case os:getenv("REBAR_DEPS_DIR") of
|
|
|
|
false ->
|
|
|
|
GlobalDepsDir;
|
|
|
|
Dir ->
|
|
|
|
Dir
|
|
|
|
end,
|
2012-09-15 17:05:15 +00:00
|
|
|
rebar_config:set_xconf(Config, deps_dir, DepsDir);
|
2012-07-23 18:53:43 +00:00
|
|
|
set_shared_deps_dir(Config, _DepsDir) ->
|
2012-07-14 21:44:47 +00:00
|
|
|
Config.
|
2010-06-12 20:55:58 +00:00
|
|
|
|
2012-07-23 18:53:43 +00:00
|
|
|
get_shared_deps_dir(Config, Default) ->
|
|
|
|
rebar_config:get_xconf(Config, deps_dir, Default).
|
|
|
|
|
2012-07-14 21:44:47 +00:00
|
|
|
get_deps_dir(Config) ->
|
|
|
|
get_deps_dir(Config, "").
|
2011-02-02 04:37:03 +00:00
|
|
|
|
2012-07-14 21:44:47 +00:00
|
|
|
get_deps_dir(Config, App) ->
|
2013-09-01 17:34:29 +00:00
|
|
|
BaseDir = rebar_utils:base_dir(Config),
|
2012-07-23 18:53:43 +00:00
|
|
|
DepsDir = get_shared_deps_dir(Config, "deps"),
|
2011-02-02 04:37:03 +00:00
|
|
|
{true, filename:join([BaseDir, DepsDir, App])}.
|
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
dep_dirs(Deps) ->
|
|
|
|
[D#dep.dir || D <- Deps].
|
|
|
|
|
|
|
|
save_dep_dirs(Config, Deps) ->
|
|
|
|
rebar_config:set_xconf(Config, ?MODULE, dep_dirs(Deps)).
|
|
|
|
|
2011-02-02 04:37:03 +00:00
|
|
|
get_lib_dir(App) ->
|
2011-03-13 13:10:31 +00:00
|
|
|
%% Find App amongst the reachable lib directories
|
|
|
|
%% Returns either the found path or a tagged tuple with a boolean
|
|
|
|
%% to match get_deps_dir's return type
|
2011-02-02 04:37:03 +00:00
|
|
|
case code:lib_dir(App) of
|
|
|
|
{error, bad_name} -> {false, bad_name};
|
|
|
|
Path -> {true, Path}
|
|
|
|
end.
|
2010-03-16 19:30:22 +00:00
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
update_deps_code_path(Config, []) ->
|
|
|
|
Config;
|
|
|
|
update_deps_code_path(Config, [Dep | Rest]) ->
|
|
|
|
Config2 =
|
|
|
|
case is_app_available(Config, Dep#dep.app,
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
Dep#dep.vsn_regex, Dep#dep.dir, Dep#dep.is_raw) of
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {true, _}} ->
|
|
|
|
Dir = filename:join(Dep#dep.dir, "ebin"),
|
|
|
|
ok = filelib:ensure_dir(filename:join(Dir, "dummy")),
|
|
|
|
?DEBUG("Adding ~s to code path~n", [Dir]),
|
|
|
|
true = code:add_patha(Dir),
|
|
|
|
Config1;
|
|
|
|
{Config1, {false, _}} ->
|
|
|
|
Config1
|
|
|
|
end,
|
|
|
|
update_deps_code_path(Config2, Rest).
|
|
|
|
|
|
|
|
find_deps(Config, find=Mode, Deps) ->
|
|
|
|
find_deps(Config, Mode, Deps, {[], []});
|
|
|
|
find_deps(Config, read=Mode, Deps) ->
|
|
|
|
find_deps(Config, Mode, Deps, []).
|
|
|
|
|
|
|
|
find_deps(Config, find, [], {Avail, Missing}) ->
|
|
|
|
{Config, {lists:reverse(Avail), lists:reverse(Missing)}};
|
|
|
|
find_deps(Config, read, [], Deps) ->
|
|
|
|
{Config, lists:reverse(Deps)};
|
|
|
|
find_deps(Config, Mode, [App | Rest], Acc) when is_atom(App) ->
|
|
|
|
find_deps(Config, Mode, [{App, ".*", undefined} | Rest], Acc);
|
|
|
|
find_deps(Config, Mode, [{App, VsnRegex} | Rest], Acc) when is_atom(App) ->
|
|
|
|
find_deps(Config, Mode, [{App, VsnRegex, undefined} | Rest], Acc);
|
|
|
|
find_deps(Config, Mode, [{App, VsnRegex, Source} | Rest], Acc) ->
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
find_deps(Config, Mode, [{App, VsnRegex, Source, []} | Rest], Acc);
|
2013-06-27 19:02:16 +00:00
|
|
|
find_deps(Config, Mode, [{App, VsnRegex, Source, Opts} | Rest], Acc)
|
|
|
|
when is_list(Opts) ->
|
2010-06-09 19:16:58 +00:00
|
|
|
Dep = #dep { app = App,
|
|
|
|
vsn_regex = VsnRegex,
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
source = Source,
|
|
|
|
%% dependency is considered raw (i.e. non-Erlang/OTP) when
|
|
|
|
%% 'raw' option is present
|
|
|
|
is_raw = proplists:get_value(raw, Opts, false) },
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {Availability, FoundDir}} = find_dep(Config, Dep),
|
|
|
|
find_deps(Config1, Mode, Rest,
|
|
|
|
acc_deps(Mode, Availability, Dep, FoundDir, Acc));
|
|
|
|
find_deps(_Config, _Mode, [Other | _Rest], _Acc) ->
|
2009-12-31 03:03:27 +00:00
|
|
|
?ABORT("Invalid dependency specification ~p in ~s\n",
|
|
|
|
[Other, rebar_utils:get_cwd()]).
|
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
find_dep(Config, Dep) ->
|
2011-03-13 13:10:31 +00:00
|
|
|
%% Find a dep based on its source,
|
|
|
|
%% e.g. {git, "https://github.com/mochi/mochiweb.git", "HEAD"}
|
|
|
|
%% Deps with a source must be found (or fetched) locally.
|
|
|
|
%% Those without a source may be satisfied from lib dir (get_lib_dir).
|
2012-04-22 19:53:32 +00:00
|
|
|
find_dep(Config, Dep, Dep#dep.source).
|
2011-02-02 04:37:03 +00:00
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
find_dep(Config, Dep, undefined) ->
|
2011-03-13 13:10:31 +00:00
|
|
|
%% 'source' is undefined. If Dep is not satisfied locally,
|
|
|
|
%% go ahead and find it amongst the lib_dir's.
|
2012-07-14 21:44:47 +00:00
|
|
|
case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)) of
|
2012-04-22 19:53:32 +00:00
|
|
|
{_Config1, {avail, _Dir}} = Avail ->
|
|
|
|
Avail;
|
|
|
|
{Config1, {missing, _}} ->
|
|
|
|
find_dep_in_dir(Config1, Dep, get_lib_dir(Dep#dep.app))
|
2011-02-02 04:37:03 +00:00
|
|
|
end;
|
2012-04-22 19:53:32 +00:00
|
|
|
find_dep(Config, Dep, _Source) ->
|
2011-03-13 13:10:31 +00:00
|
|
|
%% _Source is defined. Regardless of what it is, we must find it
|
|
|
|
%% locally satisfied or fetch it from the original source
|
|
|
|
%% into the project's deps
|
2012-07-14 21:44:47 +00:00
|
|
|
find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)).
|
2011-02-02 04:37:03 +00:00
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
find_dep_in_dir(Config, _Dep, {false, Dir}) ->
|
|
|
|
{Config, {missing, Dir}};
|
|
|
|
find_dep_in_dir(Config, Dep, {true, Dir}) ->
|
2011-02-02 04:37:03 +00:00
|
|
|
App = Dep#dep.app,
|
|
|
|
VsnRegex = Dep#dep.vsn_regex,
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
IsRaw = Dep#dep.is_raw,
|
|
|
|
case is_app_available(Config, App, VsnRegex, Dir, IsRaw) of
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {true, _AppFile}} -> {Config1, {avail, Dir}};
|
|
|
|
{Config1, {false, _}} -> {Config1, {missing, Dir}}
|
2011-02-02 04:37:03 +00:00
|
|
|
end.
|
|
|
|
|
2010-12-09 18:45:58 +00:00
|
|
|
acc_deps(find, avail, Dep, AppDir, {Avail, Missing}) ->
|
|
|
|
{[Dep#dep { dir = AppDir } | Avail], Missing};
|
|
|
|
acc_deps(find, missing, Dep, AppDir, {Avail, Missing}) ->
|
|
|
|
{Avail, [Dep#dep { dir = AppDir } | Missing]};
|
|
|
|
acc_deps(read, _, Dep, AppDir, Acc) ->
|
|
|
|
[Dep#dep { dir = AppDir } | Acc].
|
2009-12-31 03:03:27 +00:00
|
|
|
|
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
|
|
|
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
%% IsRaw = false means regular Erlang/OTP dependency
|
|
|
|
%%
|
|
|
|
%% IsRaw = true means non-Erlang/OTP dependency, e.g. the one that does not
|
|
|
|
%% have a proper .app file
|
|
|
|
is_app_available(Config, App, VsnRegex, Path, _IsRaw = false) ->
|
2011-11-09 21:56:54 +00:00
|
|
|
?DEBUG("is_app_available, looking for App ~p with Path ~p~n", [App, Path]),
|
2009-12-31 03:03:27 +00:00
|
|
|
case rebar_app_utils:is_app_dir(Path) of
|
|
|
|
{true, AppFile} ->
|
2012-04-22 19:53:32 +00:00
|
|
|
case rebar_app_utils:app_name(Config, AppFile) of
|
|
|
|
{Config1, App} ->
|
|
|
|
{Config2, Vsn} = rebar_app_utils:app_vsn(Config1, 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 ->
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config2, {true, Path}};
|
2009-12-31 03:03:27 +00:00
|
|
|
nomatch ->
|
|
|
|
?WARN("~s has version ~p; requested regex was ~s\n",
|
|
|
|
[AppFile, Vsn, VsnRegex]),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config2,
|
|
|
|
{false, {version_mismatch,
|
|
|
|
{AppFile,
|
|
|
|
{expected, VsnRegex}, {has, Vsn}}}}}
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, OtherApp} ->
|
2011-01-28 15:08:27 +00:00
|
|
|
?WARN("~s has application id ~p; expected ~p\n",
|
|
|
|
[AppFile, OtherApp, App]),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1,
|
|
|
|
{false, {name_mismatch,
|
|
|
|
{AppFile, {expected, App}, {has, OtherApp}}}}}
|
2009-12-31 03:03:27 +00:00
|
|
|
end;
|
|
|
|
false ->
|
2011-01-28 15:08:27 +00:00
|
|
|
?WARN("Expected ~s to be an app dir (containing ebin/*.app), "
|
|
|
|
"but no .app found.\n", [Path]),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config, {false, {missing_app_file, Path}}}
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
end;
|
|
|
|
is_app_available(Config, App, _VsnRegex, Path, _IsRaw = true) ->
|
2013-10-16 10:54:06 +00:00
|
|
|
?DEBUG("is_app_available, looking for Raw Depencency ~p with Path ~p~n",
|
|
|
|
[App, Path]),
|
Add support for non-Erlang/OTP (raw) dependencies
Introduce a new 'raw' option for dependency specs in rebar.config file.
For example:
{deps,
{dependency_name, "1.0.*",
{git, "<...>", {branch, "master"}},
[raw]
}
]}.
When this option is specified, rebar does not require the dependency to
have a standard Erlang/OTP layout which assumes presence of either
"src/dependency_name.app.src" or "ebin/dependency_name.app" files.
'raw' dependencies can still contain 'rebar.config' and even can have
the proper OTP directory layout, but they won't be compiled.
Only a subset of rebar commands will be executed on the 'raw'
subdirectories:
get-deps, update-deps, check-deps, list-deps and delete-deps.
2012-10-11 05:19:32 +00:00
|
|
|
case filelib:is_dir(Path) of
|
|
|
|
true ->
|
|
|
|
%% TODO: look for version string in <Path>/VERSION file? Not clear
|
|
|
|
%% how to detect git/svn/hg/{cmd, ...} settings that can be passed
|
|
|
|
%% to rebar_utils:vcs_vsn/2 to obtain version dynamically
|
|
|
|
{Config, {true, Path}};
|
|
|
|
false ->
|
|
|
|
?WARN("Expected ~s to be a raw dependency directory, "
|
|
|
|
"but no directory found.\n", [Path]),
|
|
|
|
{Config, {false, {missing_raw_dependency_directory, Path}}}
|
2009-12-31 03:03:27 +00:00
|
|
|
end.
|
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
use_source(Config, Dep) ->
|
|
|
|
use_source(Config, Dep, 3).
|
2009-12-31 03:03:27 +00:00
|
|
|
|
2012-04-22 19:53:32 +00:00
|
|
|
use_source(_Config, Dep, 0) ->
|
2011-01-28 15:08:27 +00:00
|
|
|
?ABORT("Failed to acquire source from ~p after 3 tries.\n",
|
|
|
|
[Dep#dep.source]);
|
2012-04-22 19:53:32 +00:00
|
|
|
use_source(Config, Dep, Count) ->
|
2010-06-09 19:16:58 +00:00
|
|
|
case filelib:is_dir(Dep#dep.dir) of
|
2009-12-31 03:03:27 +00:00
|
|
|
true ->
|
2011-01-28 15:08:27 +00:00
|
|
|
%% Already downloaded -- verify the versioning matches the regex
|
2013-10-16 10:54:06 +00:00
|
|
|
case is_app_available(Config, Dep#dep.app, Dep#dep.vsn_regex,
|
|
|
|
Dep#dep.dir, Dep#dep.is_raw) of
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, {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),
|
2012-04-22 19:53:32 +00:00
|
|
|
{Config1, Dep};
|
|
|
|
{_Config1, {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 "
|
2011-01-28 15:08:27 +00:00
|
|
|
"with reason:~n~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),
|
2012-07-14 21:44:47 +00:00
|
|
|
{true, TargetDir} = get_deps_dir(Config, Dep#dep.app),
|
2010-06-09 19:16:58 +00:00
|
|
|
download_source(TargetDir, Dep#dep.source),
|
2012-04-22 19:53:32 +00:00
|
|
|
use_source(Config, Dep#dep { dir = TargetDir }, Count-1)
|
2009-12-31 03:03:27 +00:00
|
|
|
end.
|
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
-record(p4_settings, {
|
|
|
|
client=undefined,
|
|
|
|
transport="tcp4:perforce:1666",
|
|
|
|
username,
|
|
|
|
password
|
|
|
|
}).
|
|
|
|
init_p4_settings(Basename) ->
|
|
|
|
#p4_settings{client =
|
|
|
|
case inet:gethostname() of
|
|
|
|
{ok,HostName} ->
|
|
|
|
HostName ++ "-"
|
|
|
|
++ os:getenv("USER") ++ "-"
|
|
|
|
++ Basename
|
|
|
|
++ "-Rebar-automated-download"
|
|
|
|
end}.
|
|
|
|
|
|
|
|
download_source(AppDir, {p4, Url}) ->
|
|
|
|
download_source(AppDir, {p4, Url, "#head"});
|
|
|
|
download_source(AppDir, {p4, Url, Rev}) ->
|
|
|
|
download_source(AppDir, {p4, Url, Rev, init_p4_settings(filename:basename(AppDir))});
|
|
|
|
download_source(AppDir, {p4, Url, _Rev, Settings}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
|
|
|
rebar_utils:sh_send("p4 client -i",
|
|
|
|
?FMT("Client: ~s~n"
|
|
|
|
++"Description: generated by Rebar~n"
|
|
|
|
++"Root: ~s~n"
|
|
|
|
++"View:~n"
|
|
|
|
++" ~s/... //~s/...~n",
|
|
|
|
[Settings#p4_settings.client,
|
|
|
|
AppDir,
|
|
|
|
Url,
|
|
|
|
Settings#p4_settings.client]),
|
|
|
|
[]),
|
|
|
|
rebar_utils:sh(?FMT("p4 -c ~s sync -f", [Settings#p4_settings.client]), []);
|
2009-12-31 03:03:27 +00:00
|
|
|
download_source(AppDir, {hg, Url, Rev}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("hg clone -U ~s ~s", [Url, filename:basename(AppDir)]),
|
|
|
|
[{cd, filename:dirname(AppDir)}]),
|
|
|
|
rebar_utils:sh(?FMT("hg update ~s", [Rev]), [{cd, AppDir}]);
|
2011-02-07 23:32:12 +00:00
|
|
|
download_source(AppDir, {git, Url}) ->
|
2011-10-31 21:29:46 +00:00
|
|
|
download_source(AppDir, {git, Url, {branch, "HEAD"}});
|
2011-02-07 23:32:12 +00:00
|
|
|
download_source(AppDir, {git, Url, ""}) ->
|
2011-10-31 21:29:46 +00:00
|
|
|
download_source(AppDir, {git, Url, {branch, "HEAD"}});
|
2010-09-15 10:10:53 +00:00
|
|
|
download_source(AppDir, {git, Url, {branch, Branch}}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("git clone -n ~s ~s", [Url, filename:basename(AppDir)]),
|
|
|
|
[{cd, filename:dirname(AppDir)}]),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), [{cd, 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-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("git clone -n ~s ~s", [Url, filename:basename(AppDir)]),
|
|
|
|
[{cd, filename:dirname(AppDir)}]),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), [{cd, AppDir}]);
|
2010-09-15 10:10:53 +00:00
|
|
|
download_source(AppDir, {git, Url, Rev}) ->
|
2011-08-13 00:14:17 +00:00
|
|
|
ok = filelib:ensure_dir(AppDir),
|
|
|
|
rebar_utils:sh(?FMT("git clone -n ~s ~s", [Url, filename:basename(AppDir)]),
|
|
|
|
[{cd, filename:dirname(AppDir)}]),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Rev]), [{cd, AppDir}]);
|
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",
|
2010-12-05 00:07:12 +00:00
|
|
|
[Rev, Url, filename:basename(AppDir)]),
|
|
|
|
[{cd, 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",
|
2010-12-05 00:07:12 +00:00
|
|
|
[Rev, Url, filename:basename(AppDir)]),
|
2012-04-25 15:08:18 +00:00
|
|
|
[{cd, filename:dirname(AppDir)}]);
|
|
|
|
download_source(AppDir, {rsync, Url}) ->
|
|
|
|
ok = filelib:ensure_dir(AppDir),
|
2012-09-19 19:24:51 +00:00
|
|
|
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s", [Url, AppDir]), []);
|
|
|
|
download_source(AppDir, {fossil, Url}) ->
|
|
|
|
download_source(AppDir, {fossil, Url, ""});
|
|
|
|
download_source(AppDir, {fossil, Url, Version}) ->
|
|
|
|
Repository = filename:join(AppDir, filename:basename(AppDir) ++ ".fossil"),
|
|
|
|
ok = filelib:ensure_dir(Repository),
|
|
|
|
ok = file:set_cwd(AppDir),
|
|
|
|
rebar_utils:sh(?FMT("fossil clone ~s ~s", [Url, Repository]),
|
|
|
|
[{cd, AppDir}]),
|
|
|
|
rebar_utils:sh(?FMT("fossil open ~s ~s --nested", [Repository, Version]),
|
|
|
|
[]).
|
2009-12-31 03:03:27 +00:00
|
|
|
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source(Config, 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.
|
2012-07-14 21:44:47 +00:00
|
|
|
{true, AppDir} = get_deps_dir(Config, Dep#dep.app),
|
2010-12-07 17:37:29 +00:00
|
|
|
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),
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, Dep#dep.source),
|
2010-12-07 17:37:29 +00:00
|
|
|
Dep;
|
|
|
|
false ->
|
2011-01-28 15:08:27 +00:00
|
|
|
?WARN("Skipping update for ~p: "
|
|
|
|
"no VCS directory available!\n", [Dep]),
|
2010-12-07 17:37:29 +00:00
|
|
|
Dep
|
|
|
|
end.
|
2010-10-03 15:22:47 +00:00
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
update_source1(AppDir, Args) when element(1, Args) =:= p4 ->
|
|
|
|
download_source(AppDir, Args);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {git, Url}) ->
|
|
|
|
update_source1(AppDir, {git, Url, {branch, "HEAD"}});
|
|
|
|
update_source1(AppDir, {git, Url, ""}) ->
|
|
|
|
update_source1(AppDir, {git, Url, {branch, "HEAD"}});
|
|
|
|
update_source1(AppDir, {git, _Url, {branch, Branch}}) ->
|
2011-01-08 18:09:24 +00:00
|
|
|
ShOpts = [{cd, AppDir}],
|
|
|
|
rebar_utils:sh("git fetch origin", ShOpts),
|
2013-09-23 19:13:26 +00:00
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Branch]), ShOpts),
|
2013-10-16 10:54:06 +00:00
|
|
|
rebar_utils:sh(
|
|
|
|
?FMT("git pull --ff-only --no-rebase -q origin ~s", [Branch]),ShOpts);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {git, _Url, {tag, Tag}}) ->
|
2011-01-08 18:09:24 +00:00
|
|
|
ShOpts = [{cd, AppDir}],
|
2013-10-15 21:37:40 +00:00
|
|
|
rebar_utils:sh("git fetch origin", ShOpts),
|
2011-01-08 18:09:24 +00:00
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {git, _Url, Refspec}) ->
|
2011-08-13 00:14:17 +00:00
|
|
|
ShOpts = [{cd, AppDir}],
|
|
|
|
rebar_utils:sh("git fetch origin", ShOpts),
|
|
|
|
rebar_utils:sh(?FMT("git checkout -q ~s", [Refspec]), ShOpts);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {svn, _Url, Rev}) ->
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("svn up -r ~s", [Rev]), [{cd, AppDir}]);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {hg, _Url, Rev}) ->
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("hg pull -u -r ~s", [Rev]), [{cd, AppDir}]);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {bzr, _Url, Rev}) ->
|
2012-04-25 15:08:18 +00:00
|
|
|
rebar_utils:sh(?FMT("bzr update -r ~s", [Rev]), [{cd, AppDir}]);
|
2012-07-14 21:44:47 +00:00
|
|
|
update_source1(AppDir, {rsync, Url}) ->
|
2012-09-19 19:24:51 +00:00
|
|
|
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s",[Url,AppDir]),[]);
|
|
|
|
update_source1(AppDir, {fossil, Url}) ->
|
|
|
|
update_source1(AppDir, {fossil, Url, ""});
|
|
|
|
update_source1(AppDir, {fossil, _Url, Version}) ->
|
|
|
|
ok = file:set_cwd(AppDir),
|
|
|
|
rebar_utils:sh("fossil pull", [{cd, AppDir}]),
|
|
|
|
rebar_utils:sh(?FMT("fossil update ~s", [Version]), []).
|
|
|
|
|
2013-09-19 21:36:02 +00:00
|
|
|
%% Recursively update deps, this is not done via rebar's usual dep traversal as
|
|
|
|
%% that is the wrong order (tips are updated before branches). Instead we do a
|
|
|
|
%% traverse the deps at each level completely before traversing *their* deps.
|
|
|
|
%% This allows updates to actually propogate down the tree, rather than fail to
|
|
|
|
%% flow up the tree, which was the previous behaviour.
|
|
|
|
update_deps_int(Config0, UDD) ->
|
|
|
|
%% Determine what deps are required
|
|
|
|
ConfDir = filename:basename(rebar_utils:get_cwd()),
|
|
|
|
RawDeps = rebar_config:get_local(Config0, deps, []),
|
|
|
|
{Config1, Deps} = find_deps(Config0, read, RawDeps),
|
|
|
|
|
|
|
|
%% Update each dep
|
|
|
|
UpdatedDeps = [update_source(Config1, D)
|
2013-09-23 19:19:51 +00:00
|
|
|
|| D <- Deps, D#dep.source =/= undefined,
|
|
|
|
not lists:member(D, UDD),
|
|
|
|
not should_skip_update_dep(Config1, D)
|
|
|
|
],
|
2013-09-19 21:36:02 +00:00
|
|
|
|
|
|
|
lists:foldl(fun(Dep, {Config, Updated}) ->
|
|
|
|
{true, AppDir} = get_deps_dir(Config, Dep#dep.app),
|
2013-10-16 10:54:06 +00:00
|
|
|
Config2 = case has_vcs_dir(element(1, Dep#dep.source),
|
|
|
|
AppDir) of
|
|
|
|
false ->
|
|
|
|
%% If the dep did not exist (maybe it
|
|
|
|
%% was added), clone it.
|
|
|
|
%% We'll traverse ITS deps below and
|
|
|
|
%% clone them if needed.
|
|
|
|
{C1, _D1} = use_source(Config, Dep),
|
|
|
|
C1;
|
|
|
|
true ->
|
|
|
|
Config
|
|
|
|
end,
|
2013-09-19 21:36:02 +00:00
|
|
|
ok = file:set_cwd(AppDir),
|
|
|
|
Config3 = rebar_config:new(Config2),
|
|
|
|
%% track where a dep comes from...
|
2013-10-16 10:49:06 +00:00
|
|
|
DepOwner = dict:append(
|
|
|
|
Dep, ConfDir,
|
|
|
|
rebar_config:get_xconf(Config3, depowner,
|
|
|
|
dict:new())),
|
|
|
|
Config4 = rebar_config:set_xconf(Config3, depowner,
|
|
|
|
DepOwner),
|
2013-09-19 21:36:02 +00:00
|
|
|
|
|
|
|
{Config5, Res} = update_deps_int(Config4, Updated),
|
|
|
|
{Config5, lists:umerge(lists:sort(Res),
|
|
|
|
lists:sort(Updated))}
|
|
|
|
end, {Config1, lists:umerge(lists:sort(UpdatedDeps),
|
|
|
|
lists:sort(UDD))}, UpdatedDeps).
|
|
|
|
|
2013-09-23 19:19:51 +00:00
|
|
|
should_skip_update_dep(Config, Dep) ->
|
|
|
|
{true, AppDir} = get_deps_dir(Config, Dep#dep.app),
|
2013-09-24 16:07:41 +00:00
|
|
|
case rebar_app_utils:is_app_dir(AppDir) of
|
|
|
|
false ->
|
|
|
|
false;
|
|
|
|
{true, AppFile} ->
|
|
|
|
case rebar_app_utils:is_skipped_app(Config, AppFile) of
|
|
|
|
{_Config, {true, _SkippedApp}} ->
|
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
2013-09-23 19:19:51 +00:00
|
|
|
end.
|
|
|
|
|
2013-09-19 21:36:02 +00:00
|
|
|
%% Recursively walk the deps and build a list of them.
|
|
|
|
collect_deps(Dir, C) ->
|
|
|
|
case file:set_cwd(Dir) of
|
|
|
|
ok ->
|
|
|
|
Config = rebar_config:new(C),
|
|
|
|
RawDeps = rebar_config:get_local(Config, deps, []),
|
|
|
|
{Config1, Deps} = find_deps(Config, read, RawDeps),
|
|
|
|
|
|
|
|
lists:flatten(Deps ++ [begin
|
2013-10-16 10:54:06 +00:00
|
|
|
{true, AppDir} = get_deps_dir(
|
|
|
|
Config1, Dep#dep.app),
|
2013-09-19 21:36:02 +00:00
|
|
|
collect_deps(AppDir, C)
|
|
|
|
end || Dep <- Deps]);
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end.
|
|
|
|
|
2012-04-25 15:08:18 +00:00
|
|
|
|
2009-12-31 03:03:27 +00:00
|
|
|
%% ===================================================================
|
|
|
|
%% Source helper functions
|
|
|
|
%% ===================================================================
|
2009-12-30 05:05:32 +00:00
|
|
|
|
2011-07-08 11:58:01 +00:00
|
|
|
source_engine_avail(Source) ->
|
|
|
|
Name = element(1, Source),
|
|
|
|
source_engine_avail(Name, Source).
|
|
|
|
|
|
|
|
source_engine_avail(Name, Source)
|
2012-09-28 21:37:18 +00:00
|
|
|
when Name == hg; Name == git; Name == svn; Name == bzr; Name == rsync;
|
2013-09-17 15:22:05 +00:00
|
|
|
Name == fossil; Name == p4 ->
|
2011-09-02 12:54:08 +00:00
|
|
|
case vcs_client_vsn(Name) >= required_vcs_client_vsn(Name) of
|
2010-01-07 14:46:06 +00:00
|
|
|
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",
|
2011-09-02 12:54:08 +00:00
|
|
|
[required_vcs_client_vsn(Name), Name, Source])
|
2010-01-07 14:46:06 +00:00
|
|
|
end.
|
|
|
|
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(false, _VsnArg, _VsnRegex) ->
|
2010-01-07 14:46:06 +00:00
|
|
|
false;
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(Path, VsnArg, VsnRegex) ->
|
2010-12-05 00:07:12 +00:00
|
|
|
{ok, Info} = rebar_utils:sh(Path ++ VsnArg, [{env, [{"LANG", "C"}]},
|
|
|
|
{use_stdout, false}]),
|
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
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
required_vcs_client_vsn(p4) -> {2013, 1};
|
2012-09-19 19:24:51 +00:00
|
|
|
required_vcs_client_vsn(hg) -> {1, 1};
|
|
|
|
required_vcs_client_vsn(git) -> {1, 5};
|
|
|
|
required_vcs_client_vsn(bzr) -> {2, 0};
|
|
|
|
required_vcs_client_vsn(svn) -> {1, 6};
|
|
|
|
required_vcs_client_vsn(rsync) -> {2, 0};
|
|
|
|
required_vcs_client_vsn(fossil) -> {1, 0}.
|
2010-01-07 14:46:06 +00:00
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
vcs_client_vsn(p4) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("p4"), " -V",
|
|
|
|
"Rev\\. .*/(\\d+)\\.(\\d)/");
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(hg) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("hg"), " --version",
|
2011-01-28 15:08:27 +00:00
|
|
|
"version (\\d+).(\\d+)");
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(git) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("git"), " --version",
|
2011-01-28 15:08:27 +00:00
|
|
|
"git version (\\d+).(\\d+)");
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(bzr) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("bzr"), " --version",
|
2011-01-28 15:08:27 +00:00
|
|
|
"Bazaar \\(bzr\\) (\\d+).(\\d+)");
|
2011-09-02 12:54:08 +00:00
|
|
|
vcs_client_vsn(svn) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("svn"), " --version",
|
2012-04-25 15:08:18 +00:00
|
|
|
"svn, version (\\d+).(\\d+)");
|
|
|
|
vcs_client_vsn(rsync) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("rsync"), " --version",
|
2012-09-19 19:24:51 +00:00
|
|
|
"rsync version (\\d+).(\\d+)");
|
|
|
|
vcs_client_vsn(fossil) ->
|
|
|
|
vcs_client_vsn(rebar_utils:find_executable("fossil"), " version",
|
|
|
|
"version (\\d+).(\\d+)").
|
2010-12-07 17:37:29 +00:00
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
has_vcs_dir(p4, _) ->
|
|
|
|
true;
|
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"));
|
2012-04-25 15:08:18 +00:00
|
|
|
has_vcs_dir(rsync, _) ->
|
|
|
|
true;
|
2010-12-07 17:37:29 +00:00
|
|
|
has_vcs_dir(_, _) ->
|
|
|
|
true.
|
2011-04-21 12:08:40 +00:00
|
|
|
|
2011-09-02 12:54:08 +00:00
|
|
|
print_source(#dep{app=App, source=Source}) ->
|
|
|
|
?CONSOLE("~s~n", [format_source(App, Source)]).
|
|
|
|
|
2013-09-17 15:22:05 +00:00
|
|
|
format_source(App, {p4, Url}) ->
|
|
|
|
format_source(App, {p4, Url, "#head"});
|
2011-09-02 12:54:08 +00:00
|
|
|
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]).
|