@@ -11,7 +11,7 @@ defmodule Mix.Deps.Retriever do
1111 """
1212 def children do
1313 scms = Mix.SCM . available
14- from = current_source ( : mix)
14+ from = Path . absname ( " mix.exs" )
1515 Enum . map ( Mix . project [ :deps ] || [ ] , & to_dep ( & 1 , scms , from ) ) ++
1616 Mix.Deps.Umbrella . unfetched
1717 end
@@ -31,69 +31,25 @@ defmodule Mix.Deps.Retriever do
3131 manager == :rebar ->
3232 rebar_dep ( dep , config )
3333
34- mixfile? ( dep ) ->
35- mix_dep ( dep . manager ( :mix ) , config )
34+ manager == :mix ->
35+ mix_dep ( dep , config )
3636
37- rebarconfig? ( dep ) or rebarexec? ( dep ) ->
38- rebar_dep ( dep . manager ( :rebar ) , config )
39-
40- makefile? ( dep ) ->
41- dep . manager ( :make )
42-
43- true ->
44- mix_dep ( dep . manager ( :mix ) , config )
37+ manager == :make ->
38+ dep
4539 end )
4640 end
4741
4842 ## Helpers
4943
50- defp current_source ( manager ) do
51- case manager do
52- :mix -> "mix.exs"
53- :rebar -> "rebar.config"
54- end |> Path . absname
55- end
56-
5744 defp to_dep ( tuple , scms , from , manager // nil ) do
58- dep = with_scm_and_app ( tuple , scms ) . from ( from ) . manager ( manager )
45+ dep = with_scm_and_app ( tuple , scms ) . from ( from )
5946
6047 if match? ( { _ , req , _ } when is_regex ( req ) , tuple ) and
6148 not String . ends_with? ( from , "rebar.config" ) do
6249 invalid_dep_format ( tuple )
6350 end
6451
65- dep
66- end
67-
68- defp mix_dep ( Mix.Dep [ opts : opts , app: app , status: status ] = dep , config ) do
69- Mix.Deps . in_dependency ( dep , config , fn _ ->
70- default =
71- if Mix.Project . umbrella? do
72- false
73- else
74- Path . join ( Mix . project [ :compile_path ] , "#{ app } .app" )
75- end
76-
77- opts = Keyword . put_new ( opts , :app , default )
78- stat = if vsn = old_elixir_lock ( ) , do: { :elixirlock , vsn } , else: status
79- dep . manager ( :mix ) . opts ( opts ) . deps ( children ) . status ( stat )
80- end )
81- end
82-
83- defp rebar_dep ( Mix.Dep [ ] = dep , config ) do
84- Mix.Deps . in_dependency ( dep , config , fn _ ->
85- config = Mix.Rebar . load_config ( "." )
86- extra = Dict . take ( config , [ :sub_dirs ] )
87- dep . manager ( :rebar ) . extra ( extra ) . deps ( rebar_children ( config ) )
88- end )
89- end
90-
91- defp rebar_children ( root_config ) do
92- scms = Mix.SCM . available
93- from = current_source ( :rebar )
94- Mix.Rebar . recur ( root_config , fn config ->
95- Mix.Rebar . deps ( config ) |> Enum . map ( & to_dep ( & 1 , scms , from , :rebar ) )
96- end ) |> Enum . concat
52+ dep . manager ( manager || detect_manager ( dep ) )
9753 end
9854
9955 defp with_scm_and_app ( { app , opts } , scms ) when is_atom ( app ) and is_list ( opts ) do
@@ -136,6 +92,71 @@ defmodule Mix.Deps.Retriever do
13692 end
13793 end
13894
95+ defp ok? ( { :ok , _ } ) , do: true
96+ defp ok? ( _ ) , do: false
97+
98+ defp detect_manager ( dep ) do
99+ dest = dep . opts [ :dest ]
100+ cond do
101+ mix? ( dest ) -> :mix
102+ rebar? ( dest ) -> :rebar
103+ make? ( dest ) -> :make
104+ true -> :mix
105+ end
106+ end
107+
108+ defp mix? ( dest ) do
109+ File . regular? ( Path . join ( dest , "mix.exs" ) )
110+ end
111+
112+ defp rebar? ( dest ) do
113+ Enum . any? ( [ "rebar.config" , "rebar.config.script" ] , fn file ->
114+ File . regular? ( Path . join ( dest , file ) )
115+ end ) or File . regular? ( Path . join ( dest , "rebar" ) )
116+ end
117+
118+ defp make? ( dest ) do
119+ File . regular? Path . join ( dest , "Makefile" )
120+ end
121+
122+ defp invalid_dep_format ( dep ) do
123+ raise Mix.Error , message: % s ( Dependency specified in the wrong format: #{inspect dep}, ) <>
124+ % s ( expected { app :: atom , opts :: Keyword . t } | { app :: atom , requirement :: String . t , opts :: Keyword . t } )
125+ end
126+
127+ ## Fetching
128+
129+ defp mix_dep ( Mix.Dep [ opts : opts , app: app , status: status ] = dep , config ) do
130+ Mix.Deps . in_dependency ( dep , config , fn _ ->
131+ default =
132+ if Mix.Project . umbrella? do
133+ false
134+ else
135+ Path . join ( Mix . project [ :compile_path ] , "#{ app } .app" )
136+ end
137+
138+ opts = Keyword . put_new ( opts , :app , default )
139+ stat = if vsn = old_elixir_lock ( ) , do: { :elixirlock , vsn } , else: status
140+ dep . manager ( :mix ) . opts ( opts ) . deps ( children ) . status ( stat )
141+ end )
142+ end
143+
144+ defp rebar_dep( Mix. Dep [ ] = dep , config) do
145+ Mix. Deps . in_dependency ( dep , config , fn _ ->
146+ config = Mix.Rebar . load_config ( "." )
147+ extra = Dict . take ( config , [ :sub_dirs ] )
148+ dep . manager ( :rebar ) . extra ( extra ) . deps ( rebar_children ( config ) )
149+ end )
150+ end
151+
152+ defp rebar_children( root_config) do
153+ scms = Mix.SCM . available
154+ from = Path . absname ( "rebar.config" )
155+ Mix.Rebar . recur ( root_config , fn config ->
156+ Mix.Rebar . deps ( config ) |> Enum . map ( & to_dep ( & 1 , scms , from , :rebar ) )
157+ end ) |> Enum . concat
158+ end
159+
139160 defp validate_app( Mix. Dep [ opts : opts , requirement: req , app: app , status: status ] = dep ) do
140161 opts_app = opts [ :app ]
141162
@@ -175,32 +196,6 @@ defmodule Mix.Deps.Retriever do
175196 Version . match? ( actual , req )
176197 end
177198
178- defp mixfile? ( dep ) do
179- File . regular? ( Path . join ( dep . opts [ :dest ] , "mix.exs" ) )
180- end
181-
182- defp rebarexec? ( dep ) do
183- File . regular? ( Path . join ( dep . opts [ :dest ] , "rebar" ) )
184- end
185-
186- defp rebarconfig? ( dep ) do
187- Enum . any? ( [ "rebar.config" , "rebar.config.script" ] , fn file ->
188- File . regular? ( Path . join ( dep . opts [ :dest ] , file ) )
189- end )
190- end
191-
192- defp makefile? ( dep ) do
193- File . regular? Path . join ( dep . opts [ :dest ] , "Makefile" )
194- end
195-
196- defp ok? ( { :ok , _ } ) , do: true
197- defp ok? ( _ ) , do: false
198-
199- defp invalid_dep_format ( dep ) do
200- raise Mix.Error , message: % s ( Dependency specified in the wrong format: #{inspect dep}, ) <>
201- % s ( expected { app :: atom , opts :: Keyword . t } | { app :: atom , requirement :: String . t , opts :: Keyword . t } )
202- end
203-
204199 defp old_elixir_lock do
205200 old_vsn = Mix.Deps.Lock . elixir_vsn
206201 if old_vsn && old_vsn != System . version do
0 commit comments