Skip to content

Commit fadf5c6

Browse files
committed
Do not always load applications during convergence, closes #12682
1 parent e975613 commit fadf5c6

File tree

10 files changed

+108
-117
lines changed

10 files changed

+108
-117
lines changed

lib/mix/lib/mix/dep.ex

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ defmodule Mix.Dep do
114114
write_cached_deps(top, {env, target}, load_and_cache(config, top, bottom, env, target))
115115

116116
_ ->
117-
converge(env: env, target: target)
117+
converge_and_load(env: env, target: target)
118118
end
119119
end
120120

121121
defp load_and_cache(_config, top, top, env, target) do
122-
converge(env: env, target: target)
122+
converge_and_load(env: env, target: target)
123123
end
124124

125125
defp load_and_cache(config, _top, bottom, _env, _target) do
@@ -152,6 +152,20 @@ defmodule Mix.Dep do
152152
end)
153153
end
154154

155+
defp converge_and_load(opts) do
156+
for %{app: app, opts: opts} = dep <- Mix.Dep.Converger.converge(opts) do
157+
case Keyword.pop(opts, :app_properties) do
158+
{nil, _opts} ->
159+
dep
160+
161+
{app_properties, opts} ->
162+
# We don't raise because child dependencies may be missing if manually cleaned
163+
:application.load({:application, app, app_properties})
164+
%{dep | opts: opts}
165+
end
166+
end
167+
end
168+
155169
defp read_cached_deps(project, env_target) do
156170
case Mix.State.read_cache({:cached_deps, project}) do
157171
{^env_target, deps} -> deps
@@ -164,6 +178,13 @@ defmodule Mix.Dep do
164178
deps
165179
end
166180

181+
@doc """
182+
Although private API, this is kept to avoid breaking code on patch releases.
183+
"""
184+
def load_on_environment(opts) do
185+
Mix.Dep.Converger.converge(opts)
186+
end
187+
167188
@doc """
168189
Clears loaded dependencies from the cache for the current environment.
169190
"""
@@ -174,25 +195,6 @@ defmodule Mix.Dep do
174195
end
175196
end
176197

177-
@doc """
178-
Returns loaded dependencies recursively on the given environment.
179-
180-
If no environment is passed, dependencies are loaded across all
181-
environments. The result is not cached.
182-
183-
## Exceptions
184-
185-
This function raises an exception if any of the dependencies
186-
provided in the project are in the wrong format.
187-
"""
188-
def load_on_environment(opts) do
189-
converge(opts)
190-
end
191-
192-
defp converge(opts) do
193-
Mix.Dep.Converger.converge(nil, nil, opts, &{&1, &2, &3}) |> elem(0)
194-
end
195-
196198
@doc """
197199
Filters the given dependencies by name.
198200

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ defmodule Mix.Dep.Converger do
6060
)
6161
end
6262

63+
@doc """
64+
Converge without lock and accumulator updates.
65+
66+
Note the dependencies returned from converge are not yet loaded.
67+
The relevant app keys are found under `dep.opts[:app_properties]`.
68+
69+
See `Mix.Dep.Loader.children/1` for options.
70+
"""
71+
def converge(opts \\ []) do
72+
converge(nil, nil, opts, &{&1, &2, &3}) |> elem(0)
73+
end
74+
6375
@doc """
6476
Converges all dependencies from the current project,
6577
including nested dependencies.
@@ -68,35 +80,15 @@ defmodule Mix.Dep.Converger do
6880
must return an updated dependency in case some processing
6981
is done.
7082
83+
Note the dependencies returned from converge are not yet loaded.
84+
The relevant app keys are found under `dep.opts[:app_properties]`.
85+
7186
See `Mix.Dep.Loader.children/1` for options.
7287
"""
7388
def converge(acc, lock, opts, callback) do
7489
{deps, acc, lock} = all(acc, lock, opts, callback)
7590
if remote = Mix.RemoteConverger.get(), do: remote.post_converge()
76-
77-
deps =
78-
for %{app: app, opts: opts} = dep <- topological_sort(deps) do
79-
case Keyword.pop(opts, :app_properties) do
80-
{nil, _opts} ->
81-
dep
82-
83-
{app_properties, opts} ->
84-
case :application.load({:application, app, app_properties}) do
85-
:ok ->
86-
:ok
87-
88-
{:error, {:already_loaded, _}} ->
89-
:ok
90-
91-
{:error, error} ->
92-
Mix.raise("Could not load application #{inspect(app)}: #{inspect(error)}")
93-
end
94-
95-
%{dep | opts: opts}
96-
end
97-
end
98-
99-
{deps, acc, lock}
91+
{topological_sort(deps), acc, lock}
10092
end
10193

10294
defp all(acc, lock, opts, callback) do

lib/mix/lib/mix/tasks/deps.clean.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule Mix.Tasks.Deps.Clean do
4141
value = opts[switch],
4242
do: {key, :"#{value}"}
4343

44-
loaded_deps = Mix.Dep.load_on_environment(loaded_opts)
44+
loaded_deps = Mix.Dep.Converger.converge(loaded_opts)
4545

4646
apps_to_clean =
4747
cond do

lib/mix/lib/mix/tasks/deps.compile.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ defmodule Mix.Tasks.Deps.Compile do
5757

5858
case OptionParser.parse(args, switches: @switches) do
5959
{opts, [], _} ->
60-
# Because this command may be invoked explicitly with
61-
# deps.compile, we simply try to compile any available
62-
# or local dependency.
6360
compile(filter_available_and_local_deps(deps), opts)
6461

6562
{opts, tail, _} ->

lib/mix/lib/mix/tasks/deps.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Mix.Tasks.Deps do
22
use Mix.Task
33

4-
import Mix.Dep, only: [load_on_environment: 1, format_dep: 1, format_status: 1, check_lock: 1]
4+
import Mix.Dep, only: [format_dep: 1, format_status: 1, check_lock: 1]
55

66
@shortdoc "Lists dependencies and their status"
77

@@ -167,7 +167,7 @@ defmodule Mix.Tasks.Deps do
167167

168168
shell = Mix.shell()
169169

170-
load_on_environment(loaded_opts)
170+
Mix.Dep.Converger.converge(loaded_opts)
171171
|> Enum.sort_by(& &1.app)
172172
|> Enum.each(fn dep ->
173173
%Mix.Dep{scm: scm, manager: manager} = dep

lib/mix/lib/mix/tasks/deps.tree.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule Mix.Tasks.Deps.Tree do
4444
value = opts[switch],
4545
do: {key, :"#{value}"}
4646

47-
deps = Mix.Dep.load_on_environment(deps_opts)
47+
deps = Mix.Dep.Converger.converge(deps_opts)
4848

4949
root =
5050
case args do

lib/mix/lib/mix/tasks/deps.unlock.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ defmodule Mix.Tasks.Deps.Unlock do
8383
end
8484

8585
defp unused_apps(lock) do
86-
apps = Mix.Dep.load_on_environment([]) |> Enum.map(& &1.app)
86+
apps = Mix.Dep.Converger.converge([]) |> Enum.map(& &1.app)
8787

8888
lock
8989
|> Map.drop(apps)

0 commit comments

Comments
 (0)