4
4
defmodule Mix.Dep.Loader do
5
5
@ moduledoc false
6
6
7
+ import Mix.Dep , only: [ ok?: 1 , mix?: 1 , rebar?: 1 , make?: 1 ]
8
+
7
9
@ doc """
8
10
Gets all direct children of the current `Mix.Project`
9
11
as a `Mix.Dep` struct. Umbrella project dependencies
@@ -37,25 +39,27 @@ defmodule Mix.Dep.Loader do
37
39
Loads the given dependency information, including its
38
40
latest status and children.
39
41
"""
40
- def load ( dep , children ) do
41
- % Mix.Dep { manager: manager , scm: scm , opts: opts } = dep
42
- dep = % { dep | status: scm_status ( scm , opts ) }
43
- dest = opts [ :dest ]
42
+ def load ( % Mix.Dep { manager: manager , scm: scm , opts: opts } = dep , children ) do
43
+ manager = opts [ :manager ] ||
44
+ scm_manager ( scm , opts ) ||
45
+ select_manager ( manager , opts [ :dest ] )
46
+
47
+ dep = % { dep | manager: manager , status: scm_status ( scm , opts ) }
44
48
45
49
{ dep , children } =
46
50
cond do
47
- not ok? ( dep . status ) ->
51
+ not ok? ( dep ) ->
48
52
{ dep , [ ] }
49
53
50
- mix? ( dest ) ->
54
+ mix? ( dep ) ->
51
55
mix_dep ( dep , children )
52
56
53
57
# If not an explicit rebar or Mix dependency
54
58
# but came from rebar, assume to be a rebar dep.
55
- rebar? ( dest ) or manager == :rebar ->
56
- rebar_dep ( dep , children )
59
+ rebar? ( dep ) ->
60
+ rebar_dep ( dep , children , manager )
57
61
58
- make? ( dest ) ->
62
+ make? ( dep ) ->
59
63
make_dep ( dep )
60
64
61
65
true ->
@@ -155,11 +159,18 @@ defmodule Mix.Dep.Loader do
155
159
end
156
160
157
161
defp get_scm ( app , opts ) do
158
- Enum . find_value Mix.SCM . available , { nil , opts } , fn ( scm ) ->
162
+ Enum . find_value Mix.SCM . available , { nil , opts } , fn scm ->
159
163
( new = scm . accepts_options ( app , opts ) ) && { scm , new }
160
164
end
161
165
end
162
166
167
+ @ managers ~w( mix rebar rebar3 make) a
168
+
169
+ defp scm_manager ( scm , opts ) do
170
+ managers = scm . managers ( opts )
171
+ Enum . find ( @ managers , & ( & 1 in managers ) )
172
+ end
173
+
163
174
defp scm_status ( scm , opts ) do
164
175
if scm . checked_out? ( opts ) do
165
176
{ :ok , nil }
@@ -168,19 +179,21 @@ defmodule Mix.Dep.Loader do
168
179
end
169
180
end
170
181
171
- defp ok? ( { :ok , _ } ) , do: true
172
- defp ok? ( _ ) , do: false
173
-
174
- defp mix? ( dest ) do
175
- any_of? ( dest , [ "mix.exs" ] )
176
- end
177
-
178
- defp rebar? ( dest ) do
179
- any_of? ( dest , [ "rebar" , "rebar.config" , "rebar.config.script" ] )
182
+ defp select_manager ( nil , dest ) do
183
+ cond do
184
+ any_of? ( dest , [ "mix.exs" ] ) ->
185
+ :mix
186
+ any_of? ( dest , [ "rebar" , "rebar.config" , "rebar.config.script" ] ) ->
187
+ :rebar
188
+ any_of? ( dest , [ "Makefile" , "Makefile.win" ] ) ->
189
+ :make
190
+ true ->
191
+ nil
192
+ end
180
193
end
181
194
182
- defp make? ( dest ) do
183
- any_of? ( dest , [ "Makefile" , "Makefile.win" ] )
195
+ defp select_manager ( manager , _dest ) do
196
+ manager
184
197
end
185
198
186
199
defp any_of? ( dest , files ) do
@@ -227,7 +240,7 @@ defmodule Mix.Dep.Loader do
227
240
end
228
241
229
242
deps = mix_children ( env: opts [ :env ] || :prod ) ++ Mix.Dep.Umbrella . unloaded
230
- { % { dep | manager: :mix , opts: opts } , deps }
243
+ { % { dep | opts: opts } , deps }
231
244
end )
232
245
end
233
246
@@ -238,25 +251,28 @@ defmodule Mix.Dep.Loader do
238
251
defp mix_dep ( % Mix.Dep { opts: opts } = dep , children ) do
239
252
from = Path . join ( opts [ :dest ] , "mix.exs" )
240
253
deps = Enum . map ( children , & to_dep ( & 1 , from ) )
241
- { % { dep | manager: :mix } , deps }
254
+ { dep , deps }
242
255
end
243
256
244
- defp rebar_dep ( % Mix.Dep { } = dep , children ) do
257
+ defp rebar_dep ( % Mix.Dep { app: app } = dep , children , manager ) do
245
258
Mix.Dep . in_dependency ( dep , fn _ ->
246
- rebar = Mix.Rebar . load_config ( "." )
247
- extra = Keyword . take ( rebar , [ :sub_dirs ] )
248
- deps = if children do
259
+ config = Mix.Rebar . load_config ( "." )
260
+ extra = Mix.Rebar . merge_config ( dep . extra , config )
261
+ deps = if children do
249
262
from = Path . absname ( "rebar.config" )
250
- Enum . map ( children , & to_dep ( & 1 , from , :rebar ) )
263
+ # Pass the manager because deps of a rebar project need
264
+ # to default to rebar if we cannot chose a manager from
265
+ # files in the dependency
266
+ Enum . map ( children , & to_dep ( & 1 , from , manager ) )
251
267
else
252
- rebar_children ( rebar )
268
+ rebar_children ( app , config , extra , manager )
253
269
end
254
- { % { dep | manager: :rebar , extra: extra } , deps }
270
+ { % { dep | extra: extra } , deps }
255
271
end )
256
272
end
257
273
258
274
defp make_dep ( dep ) do
259
- { % { dep | manager: :make } , [ ] }
275
+ { dep , [ ] }
260
276
end
261
277
262
278
defp validate_only! ( only ) do
@@ -274,18 +290,21 @@ defmodule Mix.Dep.Loader do
274
290
|> elem ( 0 )
275
291
end
276
292
277
- defp rebar_children ( root_config ) do
293
+ defp rebar_children ( app , root_config , extra , manager ) do
278
294
from = Path . absname ( "rebar.config" )
279
295
Mix.Rebar . recur ( root_config , fn config ->
280
- Mix.Rebar . deps ( config ) |> Enum . map ( & to_dep ( & 1 , from , :rebar ) )
296
+ deps = Mix.Rebar . deps ( app , config , extra [ :overrides ] || [ ] )
297
+ Enum . map ( deps , fn dep ->
298
+ % { to_dep ( dep , from , manager ) | extra: extra }
299
+ end )
281
300
end ) |> Enum . concat
282
301
end
283
302
284
- defp validate_app ( % Mix.Dep { opts: opts , requirement: req , app: app , status: status } = dep ) do
303
+ defp validate_app ( % Mix.Dep { opts: opts , requirement: req , app: app } = dep ) do
285
304
opts_app = opts [ :app ]
286
305
287
306
cond do
288
- not ok? ( status ) ->
307
+ not ok? ( dep ) ->
289
308
dep
290
309
recently_fetched? ( dep ) ->
291
310
% { dep | status: :compile }
0 commit comments