Skip to content

Commit ac629c8

Browse files
author
José Valim
committed
Move children decision down the tree so we don't ignore umbrella children
1 parent ab8ba93 commit ac629c8

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

lib/mix/lib/mix/dep/converger.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ defmodule Mix.Dep.Converger do
156156
# After we invoke the callback (which may actually check out the
157157
# dependency), we load the dependency including its latest info
158158
# and children information.
159-
dep = Mix.Dep.Loader.load(dep)
160-
%{dep | deps: Enum.filter(dep.deps, &(!children || &1.app in children))}
159+
Mix.Dep.Loader.load(dep, children)
161160
end
162161

163162
dep = %{dep | deps: reject_non_fullfilled_optional(dep.deps, current_breadths)}

lib/mix/lib/mix/dep/loader.ex

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,14 @@ defmodule Mix.Dep.Loader do
1717
* `:env` - filter dependencies on given environments
1818
"""
1919
def children(opts) do
20-
from = Path.absname("mix.exs")
21-
deps = Enum.map(Mix.Project.config[:deps] || [], &to_dep(&1, from))
22-
23-
# Filter deps not matching mix environment
24-
if env = opts[:env] do
25-
deps =
26-
Enum.filter(deps, fn %Mix.Dep{opts: opts} ->
27-
only = opts[:only]
28-
if only, do: env in List.wrap(only), else: true
29-
end)
30-
end
31-
32-
deps ++ Mix.Dep.Umbrella.unloaded
20+
mix_children(opts) ++ Mix.Dep.Umbrella.unloaded
3321
end
3422

3523
@doc """
3624
Loads the given dependency information, including its
3725
latest status and children.
3826
"""
39-
def load(dep) do
27+
def load(dep, children) do
4028
%Mix.Dep{manager: manager, scm: scm, opts: opts} = dep
4129
dep = %{dep | status: scm_status(scm, opts)}
4230
dest = opts[:dest]
@@ -47,16 +35,16 @@ defmodule Mix.Dep.Loader do
4735
{dep, []}
4836

4937
manager == :rebar ->
50-
rebar_dep(dep)
38+
rebar_dep(dep, children)
5139

5240
mix?(dest) ->
53-
mix_dep(%{dep | manager: :mix})
41+
mix_dep(dep, children)
5442

5543
rebar?(dest) ->
56-
rebar_dep(%{dep | manager: :rebar})
44+
rebar_dep(dep, children)
5745

5846
make?(dest) ->
59-
{%{dep | manager: :make}, []}
47+
make_dep(dep)
6048

6149
true ->
6250
{dep, []}
@@ -200,35 +188,60 @@ defmodule Mix.Dep.Loader do
200188

201189
## Fetching
202190

203-
defp mix_dep(%Mix.Dep{opts: opts} = dep) do
191+
defp mix_dep(%Mix.Dep{opts: opts} = dep, children) do
204192
Mix.Dep.in_dependency(dep, fn _ ->
205193
umbrella? = Mix.Project.umbrella?
206194

207195
if umbrella? do
208196
opts = Keyword.put_new(opts, :app, false)
209197
end
210198

199+
children = (mix_children(env: opts[:env] || :prod) |> filter_children(children))
200+
++ Mix.Dep.Umbrella.unloaded
201+
211202
dep = %{dep | manager: :mix, opts: opts, extra: [umbrella: umbrella?]}
212-
{dep, children(env: opts[:env] || :prod)}
203+
{dep, children}
213204
end)
214205
end
215206

216-
defp rebar_dep(%Mix.Dep{} = dep) do
207+
defp rebar_dep(%Mix.Dep{} = dep, children) do
217208
Mix.Dep.in_dependency(dep, fn _ ->
218209
rebar = Mix.Rebar.load_config(".")
219210
extra = Dict.take(rebar, [:sub_dirs])
220211
dep = %{dep | manager: :rebar, extra: extra}
221-
{dep, rebar_children(rebar)}
212+
{dep, rebar |> rebar_children |> filter_children(children)}
222213
end)
223214
end
224215

216+
defp make_dep(dep) do
217+
{%{dep | manager: :make}, []}
218+
end
219+
220+
defp mix_children(opts) do
221+
from = Path.absname("mix.exs")
222+
deps = Enum.map(Mix.Project.config[:deps] || [], &to_dep(&1, from))
223+
224+
# Filter deps not matching mix environment
225+
if env = opts[:env] do
226+
Enum.filter(deps, fn %Mix.Dep{opts: opts} ->
227+
only = opts[:only]
228+
if only, do: env in List.wrap(only), else: true
229+
end)
230+
else
231+
deps
232+
end
233+
end
234+
225235
defp rebar_children(root_config) do
226236
from = Path.absname("rebar.config")
227237
Mix.Rebar.recur(root_config, fn config ->
228238
Mix.Rebar.deps(config) |> Enum.map(&to_dep(&1, from, :rebar))
229239
end) |> Enum.concat
230240
end
231241

242+
defp filter_children(deps, nil), do: deps
243+
defp filter_children(deps, children), do: Enum.filter(deps, &(&1.app in children))
244+
232245
defp validate_path(%Mix.Dep{scm: scm, manager: manager} = dep) do
233246
if scm == Mix.SCM.Path and not manager in [:mix, nil] do
234247
Mix.raise ":path option can only be used with mix projects, " <>

lib/mix/lib/mix/dep/umbrella.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Mix.Dep.Umbrella do
2929
apps = Enum.map(deps, &(&1.app))
3030

3131
Enum.map(deps, fn umbrella_dep ->
32-
umbrella_dep = Mix.Dep.Loader.load(umbrella_dep)
32+
umbrella_dep = Mix.Dep.Loader.load(umbrella_dep, nil)
3333
deps = Enum.filter(umbrella_dep.deps, fn dep ->
3434
Mix.Dep.available?(dep) and dep.app in apps
3535
end)

0 commit comments

Comments
 (0)