Skip to content

Commit 04378bd

Browse files
jonatankloskojosevalim
authored andcommitted
Add build lock to deps.loadpaths (#14108)
1 parent fae36c5 commit 04378bd

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ defmodule Mix.Tasks.Deps.Loadpaths do
4848
Mix.Task.run("archive.check", args)
4949
end
5050

51+
config = Mix.Project.config()
52+
53+
if "--no-elixir-version-check" not in args do
54+
check_elixir_version(config)
55+
end
56+
5157
all = Mix.Dep.load_and_cache()
5258

5359
all =
@@ -57,14 +63,8 @@ defmodule Mix.Tasks.Deps.Loadpaths do
5763
all
5864
end
5965

60-
config = Mix.Project.config()
61-
62-
if "--no-elixir-version-check" not in args do
63-
check_elixir_version(config)
64-
end
65-
6666
if "--no-deps-check" not in args do
67-
deps_check(all, "--no-compile" in args)
67+
deps_check(config, all, "--no-compile" in args)
6868
end
6969

7070
Code.prepend_paths(Enum.flat_map(all, &Mix.Dep.load_paths/1), cache: true)
@@ -93,25 +93,38 @@ defmodule Mix.Tasks.Deps.Loadpaths do
9393
end
9494
end
9595

96+
defp deps_check(config, all, no_compile?) do
97+
with {:compile, _to_compile} <- deps_check(all, no_compile?) do
98+
# We need to compile, we first grab the lock, then, we check
99+
# again and compile if still applicable
100+
Mix.Project.with_build_lock(config, fn ->
101+
all = reload_deps(all)
102+
103+
with {:compile, to_compile} <- deps_check(all, no_compile?) do
104+
Mix.Tasks.Deps.Compile.compile(to_compile)
105+
106+
to_compile
107+
|> reload_deps()
108+
|> Enum.filter(&(not Mix.Dep.ok?(&1)))
109+
|> show_not_ok!()
110+
end
111+
end)
112+
end
113+
end
114+
96115
defp deps_check(all, no_compile?) do
97116
all = Enum.map(all, &check_lock/1)
98-
{not_ok, compile} = partition(all, [], [])
117+
{not_ok, to_compile} = partition(all, [], [])
99118

100119
cond do
101120
not_ok != [] ->
102121
show_not_ok!(not_ok)
103122

104-
compile == [] or no_compile? ->
123+
to_compile == [] or no_compile? ->
105124
:ok
106125

107126
true ->
108-
Mix.Tasks.Deps.Compile.compile(compile)
109-
110-
compile
111-
|> Enum.map(& &1.app)
112-
|> Mix.Dep.filter_by_name(Mix.Dep.load_and_cache())
113-
|> Enum.filter(&(not Mix.Dep.ok?(&1)))
114-
|> show_not_ok!()
127+
{:compile, to_compile}
115128
end
116129
end
117130

@@ -136,6 +149,12 @@ defmodule Mix.Tasks.Deps.Loadpaths do
136149
{Enum.reverse(not_ok), Enum.reverse(compile)}
137150
end
138151

152+
defp reload_deps(deps) do
153+
deps
154+
|> Enum.map(& &1.app)
155+
|> Mix.Dep.filter_by_name(Mix.Dep.load_and_cache())
156+
end
157+
139158
# Those are compiled by umbrella.
140159
defp from_umbrella?(dep) do
141160
dep.opts[:from_umbrella]

0 commit comments

Comments
 (0)