basho / rebar
Erlang Build Tools -- Please file bug and feature requests at http://issues.basho.com.
| commit 194: | 1715ab560db3 |
| parent 193: | 75b089ece24e |
| branch: | default |
Revamp deps system to NOT pull down deps automatically. You must now use pull-deps explicitly
dizzyd
5 months ago
5 months ago
Changed (Δ1.7 KB):
raw changeset »
src/rebar_core.erl (39 lines added, 32 lines removed)
src/rebar_deps.erl (68 lines added, 35 lines removed)
Up to file-list src/rebar_core.erl:
| … | … | @@ -176,45 +176,52 @@ filter_flags([Item | Rest], Commands) -> |
176 |
176 |
|
177 |
177 |
|
178 |
178 |
process_dir(Dir, ParentConfig, Commands) -> |
179 |
ok = file:set_cwd(Dir), |
|
180 |
Config = rebar_config:new(ParentConfig), |
|
179 |
case filelib:is_dir(Dir) of |
|
180 |
false -> |
|
181 |
?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]), |
|
182 |
ok; |
|
181 |
183 |
|
182 |
%% Save the current code path and then update it with |
|
183 |
%% lib_dirs. Children inherit parents code path, but we |
|
184 |
%% also want to ensure that we restore everything to pristine |
|
185 |
%% condition after processing this child |
|
186 |
|
|
184 |
true -> |
|
185 |
ok = file:set_cwd(Dir), |
|
186 |
Config = rebar_config:new(ParentConfig), |
|
187 |
187 |
|
188 |
%% Get the list of processing modules and check each one against |
|
189 |
%% CWD to see if it's a fit -- if it is, use that set of modules |
|
190 |
%% to process this dir. |
|
191 |
{ok, AvailModuleSets} = application:get_env(rebar, modules), |
|
192 |
|
|
188 |
%% Save the current code path and then update it with |
|
189 |
%% lib_dirs. Children inherit parents code path, but we |
|
190 |
%% also want to ensure that we restore everything to pristine |
|
191 |
%% condition after processing this child |
|
192 |
CurrentCodePath = update_code_path(Config), |
|
193 |
193 |
|
194 |
%% Get the list of modules for "any dir". This is a catch-all list of modules |
|
195 |
%% that are processed in addion to modules associated with this directory |
|
196 |
%% type. These any_dir modules are processed FIRST. |
|
197 |
{ok, AnyDirModules} = application:get_env(rebar, any_dir_modules), |
|
198 |
|
|
194 |
%% Get the list of processing modules and check each one against |
|
195 |
%% CWD to see if it's a fit -- if it is, use that set of modules |
|
196 |
%% to process this dir. |
|
197 |
{ok, AvailModuleSets} = application:get_env(rebar, modules), |
|
198 |
{DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir), |
|
199 |
199 |
|
200 |
%% Give the modules a chance to tweak config and indicate if there |
|
201 |
%% are any other dirs that might need processing first. |
|
202 |
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []), |
|
203 |
preprocess, Config, ModuleSetFile, []), |
|
204 |
?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]), |
|
205 |
[process_dir(D, UpdatedConfig, Commands) || D <- Dirs], |
|
200 |
%% Get the list of modules for "any dir". This is a catch-all list of modules |
|
201 |
%% that are processed in addion to modules associated with this directory |
|
202 |
%% type. These any_dir modules are processed FIRST. |
|
203 |
{ok, AnyDirModules} = application:get_env(rebar, any_dir_modules), |
|
204 |
Modules = AnyDirModules ++ DirModules, |
|
206 |
205 |
|
207 |
%% Make sure the CWD is reset properly; processing subdirs may have caused it |
|
208 |
%% to change |
|
209 |
|
|
206 |
%% Give the modules a chance to tweak config and indicate if there |
|
207 |
%% are any other dirs that might need processing first. |
|
208 |
{UpdatedConfig, Dirs} = acc_modules(select_modules(Modules, preprocess, []), |
|
209 |
preprocess, Config, ModuleSetFile, []), |
|
210 |
?DEBUG("~s subdirs: ~p\n", [Dir, Dirs]), |
|
211 |
[process_dir(D, UpdatedConfig, Commands) || D <- Dirs], |
|
210 |
212 |
|
211 |
%% Finally, process the current working directory |
|
212 |
apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile), |
|
213 |
%% Make sure the CWD is reset properly; processing subdirs may have caused it |
|
214 |
%% to change |
|
215 |
ok = file:set_cwd(Dir), |
|
213 |
216 |
|
214 |
%% Once we're all done processing, reset the code path to whatever |
|
215 |
%% the parent initialized it to |
|
216 |
restore_code_path(CurrentCodePath), |
|
217 |
ok. |
|
217 |
%% Finally, process the current working directory |
|
218 |
apply_commands(Commands, Modules, UpdatedConfig, ModuleSetFile), |
|
219 |
||
220 |
%% Once we're all done processing, reset the code path to whatever |
|
221 |
%% the parent initialized it to |
|
222 |
restore_code_path(CurrentCodePath), |
|
223 |
ok |
|
224 |
end. |
|
218 |
225 |
|
219 |
226 |
%% |
220 |
227 |
%% Given a list of module sets from rebar.app and a directory, find |
Up to file-list src/rebar_deps.erl:
29 |
29 |
-include("rebar.hrl"). |
30 |
30 |
|
31 |
31 |
-export([preprocess/2, |
32 |
|
|
32 |
'get-deps'/2, |
|
33 |
'delete-deps'/2]). |
|
33 |
34 |
|
34 |
35 |
%% =================================================================== |
35 |
36 |
%% Public API |
36 |
37 |
%% =================================================================== |
37 |
38 |
|
38 |
39 |
preprocess(Config, _) -> |
40 |
DepsDir = get_deps_dir(Config), |
|
41 |
Config2 = rebar_config:set(Config, deps_dir, DepsDir), |
|
42 |
||
43 |
%% Check for available deps, using the list of deps specified in our config. |
|
44 |
%% We use the directory from the list of tuples for deps with source information to |
|
45 |
%% update our list of directories to process. |
|
46 |
case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of |
|
47 |
Deps when is_list(Deps) -> |
|
48 |
%% Walk all the deps and make sure they are available on the code path, |
|
49 |
%% if the application we're interested in actually exists there. |
|
50 |
ok = update_deps_code_path(Deps), |
|
51 |
{ok, Config2, [Dir || {Dir, _, _, _} <- Deps]}; |
|
52 |
{'EXIT', Reason} -> |
|
53 |
?ABORT("Error while processing dependencies: ~p\n", [Reason]) |
|
54 |
end. |
|
55 |
||
56 |
'get-deps'(Config, _) -> |
|
57 |
DepsDir = get_deps_dir(Config), |
|
58 |
||
59 |
%% Get a list of deps that need to be downloaded |
|
60 |
case catch(check_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of |
|
61 |
Deps when is_list(Deps) -> |
|
62 |
%% Now for each dependency tuple, pull it |
|
63 |
[use_source(Dir, App, VsnRegex, Source) || {Dir, App, VsnRegex, Source} <- Deps], |
|
64 |
ok; |
|
65 |
{'EXIT', Reason} -> |
|
66 |
?ABORT("Error while processing dependencies: ~p\n", [Reason]) |
|
67 |
end. |
|
68 |
||
69 |
'delete-deps'(Config, _) -> |
|
70 |
%% Delete all the deps which we downloaded (or would have caused to be |
|
71 |
%% downloaded). |
|
72 |
DepsDir = rebar_config:get(Config, deps_dir, rebar_utils:get_cwd()), |
|
73 |
?DEBUG("Delete deps: ~p\n", [rebar_config:get(Config, deps, [])]), |
|
74 |
delete_deps(rebar_config:get_local(Config, deps, []), DepsDir). |
|
75 |
||
76 |
%% =================================================================== |
|
77 |
%% Internal functions |
|
78 |
%% =================================================================== |
|
79 |
||
80 |
get_deps_dir(Config) -> |
|
39 |
81 |
%% Get the directory where we will place downloaded deps. Take steps |
40 |
82 |
%% to ensure that if we're doing a multi-level build, all the deps will |
41 |
83 |
%% wind up in a single directory; avoiding potential pain from having |
| … | … | @@ -49,50 +91,40 @@ preprocess(Config, _) -> |
49 |
91 |
AllDirs -> |
50 |
92 |
DepsDir = filename:absname(hd(lists:reverse(AllDirs))) |
51 |
93 |
end, |
94 |
?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]), |
|
95 |
DepsDir. |
|
52 |
96 |
|
53 |
?DEBUG("~s: Using deps dir: ~s\n", [rebar_utils:get_cwd(), DepsDir]), |
|
54 |
Config2 = rebar_config:set(Config, deps_dir, DepsDir), |
|
97 |
update_deps_code_path([]) -> |
|
98 |
ok; |
|
99 |
update_deps_code_path([{AppDir, App, VsnRegex, _Source} | Rest]) -> |
|
100 |
case is_app_available(App, VsnRegex, AppDir) of |
|
101 |
true -> |
|
102 |
code:add_patha(filename:join(AppDir, ebin)); |
|
103 |
false -> |
|
104 |
ok |
|
105 |
end, |
|
106 |
update_deps_code_path(Rest). |
|
55 |
107 |
|
56 |
%% Process the list of local deps from the configuration |
|
57 |
case catch(process_deps(rebar_config:get_local(Config, deps, []), [], DepsDir)) of |
|
58 |
Dirs when is_list(Dirs) -> |
|
59 |
{ok, Config2, Dirs}; |
|
60 |
{'EXIT', Reason} -> |
|
61 |
?ABORT("Error while processing dependencies: ~p\n", [Reason]) |
|
62 |
end. |
|
63 |
||
64 |
distclean(Config, _) -> |
|
65 |
%% Delete all the deps which we downloaded (or would have caused to be |
|
66 |
%% downloaded). |
|
67 |
DepsDir = rebar_config:get(Config, deps_dir, rebar_utils:get_cwd()), |
|
68 |
?DEBUG("Delete deps: ~p\n", [rebar_config:get(Config, deps, [])]), |
|
69 |
delete_deps(rebar_config:get_local(Config, deps, []), DepsDir). |
|
70 |
||
71 |
%% =================================================================== |
|
72 |
%% Internal functions |
|
73 |
%% =================================================================== |
|
74 |
||
75 |
process_deps([], Acc, _Dir) -> |
|
108 |
check_deps([], Acc, _Dir) -> |
|
76 |
109 |
Acc; |
77 |
|
|
110 |
check_deps([App | Rest], Acc, Dir) when is_atom(App) -> |
|
78 |
111 |
require_app(App, ".*"), |
79 |
process_deps(Rest, Acc, Dir); |
|
80 |
process_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) -> |
|
112 |
check_deps(Rest, Acc, Dir); |
|
113 |
check_deps([{App, VsnRegex} | Rest], Acc, Dir) when is_atom(App) -> |
|
81 |
114 |
require_app(App, VsnRegex), |
82 |
process_deps(Rest, Acc, Dir); |
|
83 |
process_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) -> |
|
115 |
check_deps(Rest, Acc, Dir); |
|
116 |
check_deps([{App, VsnRegex, Source} | Rest], Acc, Dir) -> |
|
84 |
117 |
case is_app_available(App, VsnRegex) of |
85 |
118 |
true -> |
86 |
|
|
119 |
check_deps(Rest, Acc, Dir); |
|
87 |
120 |
false -> |
88 |
%% App may not be on the code path, or the version that is doesn't |
|
89 |
%% match our regex. Either way, we want to pull our revision into |
|
90 |
%% |
|
121 |
%% App is not on our code path OR the version that is available |
|
122 |
%% doesn't match our regex. Return a tuple containing the target dir |
|
123 |
%% and source information. |
|
91 |
124 |
AppDir = filename:join(Dir, App), |
92 |
use_source(AppDir, App, VsnRegex, Source), |
|
93 |
process_deps(Rest, [AppDir | Acc], Dir) |
|
125 |
check_deps(Rest, [{AppDir, App, VsnRegex, Source} | Acc], Dir) |
|
94 |
126 |
end; |
95 |
|
|
127 |
check_deps([Other | _Rest], _Acc, _Dir) -> |
|
96 |
128 |
?ABORT("Invalid dependency specification ~p in ~s\n", |
97 |
129 |
[Other, rebar_utils:get_cwd()]). |
98 |
130 |
|
| … | … | @@ -170,6 +202,7 @@ is_app_available(App, VsnRegex, Path) -> |
170 |
202 |
end. |
171 |
203 |
|
172 |
204 |
use_source(AppDir, App, VsnRegex, Source) -> |
205 |
?CONSOLE("Pulling ~p from ~p\n", [App, Source]), |
|
173 |
206 |
use_source(AppDir, App, VsnRegex, Source, 3). |
174 |
207 |
|
175 |
208 |
use_source(_AppDir, _App, _VsnRegex, Source, 0) -> |
