Skip to content

Commit dc8cfcd

Browse files
committed
Load and compile plugins from cache, closes #12880
1 parent 84c8d23 commit dc8cfcd

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

lib/mix/lib/mix/tasks/format.ex

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,7 @@ defmodule Mix.Tasks.Format do
303303
Mix.raise("Expected :plugins to return a list of modules, got: #{inspect(plugins)}")
304304
end
305305

306-
if plugins != [] do
307-
Mix.Task.run("loadpaths", [])
308-
end
309-
310-
if not Enum.all?(plugins, &Code.ensure_loaded?/1) do
311-
Mix.Task.run("compile", [])
312-
end
306+
maybe_load_and_compile_plugins(plugins)
313307

314308
for plugin <- plugins do
315309
cond do
@@ -351,12 +345,19 @@ defmodule Mix.Tasks.Format do
351345
else
352346
manifest = Path.join(Mix.Project.manifest_path(), @manifest)
353347

354-
{{locals_without_parens, subdirectories}, sources} =
348+
{cached?, {{locals_without_parens, subdirectories}, sources}} =
355349
maybe_cache_in_manifest(dot_formatter, manifest, fn ->
356350
{subdirectories, sources} = eval_subs_opts(subs, cwd, sources)
357351
{{eval_deps_opts(deps), subdirectories}, sources}
358352
end)
359353

354+
# If we read from cache, we may still need to load and compile plugins.
355+
if cached? do
356+
Enum.each(subdirectories, fn {_path, {opts, _deps}} ->
357+
maybe_load_and_compile_plugins(Keyword.get(opts, :plugins, []))
358+
end)
359+
end
360+
360361
formatter_opts =
361362
Keyword.update(
362363
formatter_opts,
@@ -369,11 +370,21 @@ defmodule Mix.Tasks.Format do
369370
end
370371
end
371372

373+
defp maybe_load_and_compile_plugins(plugins) do
374+
if plugins != [] do
375+
Mix.Task.run("loadpaths", [])
376+
end
377+
378+
if not Enum.all?(plugins, &Code.ensure_loaded?/1) do
379+
Mix.Task.run("compile", [])
380+
end
381+
end
382+
372383
defp maybe_cache_in_manifest(dot_formatter, manifest, fun) do
373384
cond do
374-
is_nil(Mix.Project.get()) or dot_formatter != ".formatter.exs" -> fun.()
375-
entry = read_manifest(manifest) -> entry
376-
true -> write_manifest!(manifest, fun.())
385+
is_nil(Mix.Project.get()) or dot_formatter != ".formatter.exs" -> {false, fun.()}
386+
entry = read_manifest(manifest) -> {true, entry}
387+
true -> {false, write_manifest!(manifest, fun.())}
377388
end
378389
end
379390

0 commit comments

Comments
 (0)