Skip to content

Commit d1b8657

Browse files
author
José Valim
committed
Do not load mix.exs for mix deps coming from hex
This is an optimization that allows us to shave off some seconds from booting applications.
1 parent 89d9cc8 commit d1b8657

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,40 @@ defmodule Mix.Dep.Loader do
188188

189189
## Fetching
190190

191-
defp mix_dep(%Mix.Dep{opts: opts} = dep, children) do
191+
defp mix_dep(%Mix.Dep{opts: opts} = dep, nil) do
192192
Mix.Dep.in_dependency(dep, fn _ ->
193193
umbrella? = Mix.Project.umbrella?
194194

195195
if umbrella? do
196196
opts = Keyword.put_new(opts, :app, false)
197197
end
198198

199-
children = (mix_children(env: opts[:env] || :prod) |> filter_children(children))
200-
++ Mix.Dep.Umbrella.unloaded
201-
202-
dep = %{dep | manager: :mix, opts: opts, extra: [umbrella: umbrella?]}
203-
{dep, children}
199+
deps = mix_children(env: opts[:env] || :prod) ++ Mix.Dep.Umbrella.unloaded
200+
{%{dep | manager: :mix, opts: opts, extra: [umbrella: umbrella?]}, deps}
204201
end)
205202
end
206203

204+
# If we have a Mix dependency that came from a remote converger,
205+
# we just use the dependencies given by the remote converger, we
206+
# don't need to load the mixfile at all. We can only do this for
207+
# now because umbrella projects are not supported.
208+
defp mix_dep(%Mix.Dep{opts: opts} = dep, children) do
209+
from = Path.join(opts[:dest], "mix.exs")
210+
deps = Enum.map(children, &to_dep({&1, []}, from))
211+
{%{dep | manager: :mix, extra: [umbrella: false]}, deps}
212+
end
213+
207214
defp rebar_dep(%Mix.Dep{} = dep, children) do
208215
Mix.Dep.in_dependency(dep, fn _ ->
209216
rebar = Mix.Rebar.load_config(".")
210217
extra = Dict.take(rebar, [:sub_dirs])
211-
dep = %{dep | manager: :rebar, extra: extra}
212-
{dep, rebar |> rebar_children |> filter_children(children)}
218+
deps = if children do
219+
from = Path.absname("rebar.config")
220+
Enum.map(children, &to_dep({&1, []}, from, :rebar))
221+
else
222+
rebar_children(rebar)
223+
end
224+
{%{dep | manager: :rebar, extra: extra}, deps}
213225
end)
214226
end
215227

@@ -239,9 +251,6 @@ defmodule Mix.Dep.Loader do
239251
end) |> Enum.concat
240252
end
241253

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

0 commit comments

Comments
 (0)