mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Revamp deps system to NOT pull down deps automatically. You must now use pull-deps explicitly
This commit is contained in:
parent
a12778ba65
commit
be6bb20c59
2 changed files with 106 additions and 66 deletions
|
@ -176,45 +176,52 @@ filter_flags([Item | Rest], Commands) ->
|
||||||
|
|
||||||
|
|
||||||
process_dir(Dir, ParentConfig, Commands) ->
|
process_dir(Dir, ParentConfig, Commands) ->
|
||||||
ok = file:set_cwd(Dir),
|
case filelib:is_dir(Dir) of
|
||||||
Config = rebar_config:new(ParentConfig),
|
false ->
|
||||||
|
?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]),
|
||||||
|
ok;
|
||||||
|
|
||||||
%% Save the current code path and then update it with
|
true ->
|
||||||
%% lib_dirs. Children inherit parents code path, but we
|
ok = file:set_cwd(Dir),
|
||||||
%% also want to ensure that we restore everything to pristine
|
Config = rebar_config:new(ParentConfig),
|
||||||
%% condition after processing this child
|
|
||||||
CurrentCodePath = update_code_path(Config),
|
|
||||||
|
|
||||||
%% Get the list of processing modules and check each one against
|
%% Save the current code path and then update it with
|
||||||
%% CWD to see if it's a fit -- if it is, use that set of modules
|
%% lib_dirs. Children inherit parents code path, but we
|
||||||
%% to process this dir.
|
%% also want to ensure that we restore everything to pristine
|
||||||
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
%% condition after processing this child
|
||||||
{DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir),
|
CurrentCodePath = update_code_path(Config),
|
||||||
|
|
||||||
%% Get the list of modules for "any dir". This is a catch-all list of modules
|
%% Get the list of processing modules and check each one against
|
||||||
%% that are processed in addion to modules associated with this directory
|
%% CWD to see if it's a fit -- if it is, use that set of modules
|
||||||
%% type. These any_dir modules are processed FIRST.
|
%% to process this dir.
|
||||||
{ok, AnyDirModules} = application:get_env(rebar, any_dir_modules),
|
{ok, AvailModuleSets} = application:get_env(rebar, modules),
|
||||||
Modules = AnyDirModules ++ DirModules,
|
{DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir),
|
||||||
|
|
||||||
%% Give the modules a chance to tweak config and indicate if there
|
%% Get the list of modules for "any dir". This is a catch-all list of modules
|
||||||
%% are any other dirs that might need processing first.
|
%% that are processed in addion to modules associated with this directory
|
||||||
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []),
|
%% type. These any_dir modules are processed FIRST.
|
||||||
preprocess, Config, ModuleSetFile, []),
|
{ok, AnyDirModules} = application:get_env(rebar, any_dir_modules),
|
||||||
?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]),
|
Modules = AnyDirModules ++ DirModules,
|
||||||
[process_dir(D, UpdatedConfig, Commands) || D <- Dirs],
|
|
||||||
|
|
||||||
%% Make sure the CWD is reset properly; processing subdirs may have caused it
|
%% Give the modules a chance to tweak config and indicate if there
|
||||||
%% to change
|
%% are any other dirs that might need processing first.
|
||||||
ok = file:set_cwd(Dir),
|
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []),
|
||||||
|
preprocess, Config, ModuleSetFile, []),
|
||||||
|
?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]),
|
||||||
|
[process_dir(D, UpdatedConfig, Commands) || D <- Dirs],
|
||||||
|
|
||||||
%% Finally, process the current working directory
|
%% Make sure the CWD is reset properly; processing subdirs may have caused it
|
||||||
apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile),
|
%% to change
|
||||||
|
ok = file:set_cwd(Dir),
|
||||||
|
|
||||||
%% Once we're all done processing, reset the code path to whatever
|
%% Finally, process the current working directory
|
||||||
%% the parent initialized it to
|
apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile),
|
||||||
restore_code_path(CurrentCodePath),
|
|
||||||
ok.
|
%% Once we're all done processing, reset the code path to whatever
|
||||||
|
%% the parent initialized it to
|
||||||
|
restore_code_path(CurrentCodePath),
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Given a list of module sets from rebar.app and a directory, find
|
%% Given a list of module sets from rebar.app and a directory, find
|
||||||
|
|
|
@ -29,13 +29,55 @@
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
-export([preprocess/2,
|
-export([preprocess/2,
|
||||||
distclean/2]).
|
'get-deps'/2,
|
||||||
|
'delete-deps'/2]).
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Public API
|
%% Public API
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
preprocess(Config, _) ->
|
preprocess(Config, _) ->
|
||||||
|
DepsDir = get_deps_dir(Config),
|
||||||
|
Config2 = rebar_config:set(Config, deps_dir, DepsDir),
|
||||||
|
|
||||||
|
%% Check for available deps, using the list of deps specified in our config.
|
||||||
|
%% We use the directory from the list of tuples for deps with source information to
|
||||||
|
%% update our list of directories to process.
|
||||||
|
case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of
|
||||||
|
Deps when is_list(Deps) ->
|
||||||
|
%% Walk all the deps and make sure they are available on the code path,
|
||||||
|
%% if the application we're interested in actually exists there.
|
||||||
|
ok = update_deps_code_path(Deps),
|
||||||
|
{ok, Config2, [Dir || {Dir, _, _, _} <- Deps]};
|
||||||
|
{'EXIT', Reason} ->
|
||||||
|
?ABORT("Error while processing dependencies: ~p\n", [Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
|
'get-deps'(Config, _) ->
|
||||||
|
DepsDir = get_deps_dir(Config),
|
||||||
|
|
||||||
|
%% Get a list of deps that need to be downloaded
|
||||||
|
case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of
|
||||||
|
Deps when is_list(Deps) ->
|
||||||
|
%% Now for each dependency tuple, pull it
|
||||||
|
[use_source(Dir, App, VsnRegex, Source) || {Dir, App, VsnRegex, Source} <- Deps],
|
||||||
|
ok;
|
||||||
|
{'EXIT', Reason} ->
|
||||||
|
?ABORT("Error while processing dependencies: ~p\n", [Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
|
'delete-deps'(Config, _) ->
|
||||||
|
%% Delete all the deps which we downloaded (or would have caused to be
|
||||||
|
%% downloaded).
|
||||||
|
DepsDir = rebar_config:get(Config, deps_dir, rebar_utils:get_cwd()),
|
||||||
|
?DEBUG("Delete deps: ~p\n", [rebar_config:get(Config, deps, [])]),
|
||||||
|
delete_deps(rebar_config:get_local(Config, deps, []), DepsDir).
|
||||||
|
|
||||||
|
%% ===================================================================
|
||||||
|
%% Internal functions
|
||||||
|
%% ===================================================================
|
||||||
|
|
||||||
|
get_deps_dir(Config) ->
|
||||||
%% Get the directory where we will place downloaded deps. Take steps
|
%% Get the directory where we will place downloaded deps. Take steps
|
||||||
%% to ensure that if we're doing a multi-level build, all the deps will
|
%% to ensure that if we're doing a multi-level build, all the deps will
|
||||||
%% wind up in a single directory; avoiding potential pain from having
|
%% wind up in a single directory; avoiding potential pain from having
|
||||||
|
@ -49,50 +91,40 @@ preprocess(Config, _) ->
|
||||||
AllDirs ->
|
AllDirs ->
|
||||||
DepsDir = filename:absname(hd(lists:reverse(AllDirs)))
|
DepsDir = filename:absname(hd(lists:reverse(AllDirs)))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]),
|
?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]),
|
||||||
Config2 = rebar_config:set(Config, deps_dir, DepsDir),
|
DepsDir.
|
||||||
|
|
||||||
%% Process the list of local deps from the configuration
|
update_deps_code_path([]) ->
|
||||||
case catch(process_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of
|
ok;
|
||||||
Dirs when is_list(Dirs) ->
|
update_deps_code_path([{AppDir, App, VsnRegex, _Source} | Rest]) ->
|
||||||
{ok, Config2, Dirs};
|
case is_app_available(App, VsnRegex, AppDir) of
|
||||||
{'EXIT', Reason} ->
|
true ->
|
||||||
?ABORT("Error while processing dependencies: ~p\n", [Reason])
|
code:add_patha(filename:join(AppDir, ebin));
|
||||||
end.
|
false ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
update_deps_code_path(Rest).
|
||||||
|
|
||||||
distclean(Config, _) ->
|
check_deps([], Acc, _Dir) ->
|
||||||
%% Delete all the deps which we downloaded (or would have caused to be
|
|
||||||
%% downloaded).
|
|
||||||
DepsDir = rebar_config:get(Config, deps_dir, rebar_utils:get_cwd()),
|
|
||||||
?DEBUG("Delete deps: ~p\n", [rebar_config:get(Config, deps, [])]),
|
|
||||||
delete_deps(rebar_config:get_local(Config, deps, []), DepsDir).
|
|
||||||
|
|
||||||
%% ===================================================================
|
|
||||||
%% Internal functions
|
|
||||||
%% ===================================================================
|
|
||||||
|
|
||||||
process_deps([], Acc, _Dir) ->
|
|
||||||
Acc;
|
Acc;
|
||||||
process_deps([App | Rest], Acc, Dir) when is_atom(App) ->
|
check_deps([App | Rest], Acc, Dir) when is_atom(App) ->
|
||||||
require_app(App, ".*"),
|
require_app(App, ".*"),
|
||||||
process_deps(Rest, Acc, Dir);
|
check_deps(Rest, Acc, Dir);
|
||||||
process_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) ->
|
check_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) ->
|
||||||
require_app(App, VsnRegex),
|
require_app(App, VsnRegex),
|
||||||
process_deps(Rest, Acc, Dir);
|
check_deps(Rest, Acc, Dir);
|
||||||
process_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) ->
|
check_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) ->
|
||||||
case is_app_available(App, VsnRegex) of
|
case is_app_available(App, VsnRegex) of
|
||||||
true ->
|
true ->
|
||||||
process_deps(Rest, Acc, Dir);
|
check_deps(Rest, Acc, Dir);
|
||||||
false ->
|
false ->
|
||||||
%% App may not be on the code path, or the version that is doesn't
|
%% App is not on our code path OR the version that is available
|
||||||
%% match our regex. Either way, we want to pull our revision into
|
%% doesn't match our regex. Return a tuple containing the target dir
|
||||||
%% the deps dir and try to use that
|
%% and source information.
|
||||||
AppDir = filename:join(Dir, App),
|
AppDir = filename:join(Dir, App),
|
||||||
use_source(AppDir, App, VsnRegex, Source),
|
check_deps(Rest, [{AppDir, App, VsnRegex, Source} | Acc], Dir)
|
||||||
process_deps(Rest, [AppDir | Acc], Dir)
|
|
||||||
end;
|
end;
|
||||||
process_deps([Other | _Rest], _Acc, _Dir) ->
|
check_deps([Other | _Rest], _Acc, _Dir) ->
|
||||||
?ABORT("Invalid dependency specification ~p in ~s\n",
|
?ABORT("Invalid dependency specification ~p in ~s\n",
|
||||||
[Other, rebar_utils:get_cwd()]).
|
[Other, rebar_utils:get_cwd()]).
|
||||||
|
|
||||||
|
@ -170,6 +202,7 @@ is_app_available(App, VsnRegex, Path) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
use_source(AppDir, App, VsnRegex, Source) ->
|
use_source(AppDir, App, VsnRegex, Source) ->
|
||||||
|
?CONSOLE("Pulling ~p from ~p\n", [App, Source]),
|
||||||
use_source(AppDir, App, VsnRegex, Source, 3).
|
use_source(AppDir, App, VsnRegex, Source, 3).
|
||||||
|
|
||||||
use_source(_AppDir, _App, _VsnRegex, Source, 0) ->
|
use_source(_AppDir, _App, _VsnRegex, Source, 0) ->
|
||||||
|
|
Loading…
Reference in a new issue