Skip to content

Commit 6f5d4d0

Browse files
author
José Valim
committed
Sinplify mechanism for checking and handling locks
In particular, there is no need to pass :lockfile around deps. We also remove the umbrella handling from the lock.
1 parent 13eab25 commit 6f5d4d0

File tree

5 files changed

+32
-38
lines changed

5 files changed

+32
-38
lines changed

lib/mix/lib/mix/deps.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ defmodule Mix.Deps do
270270
:outdated ->
271271
dep.status :lockoutdated
272272
:ok ->
273-
dep
273+
if vsn = old_elixir_lock(dep) do
274+
dep.status({ :elixirlock, vsn })
275+
else
276+
dep
277+
end
274278
end
275279
else
276280
dep
@@ -451,4 +455,11 @@ defmodule Mix.Deps do
451455
if is_binary(app), do: binary_to_atom(app), else: app
452456
end
453457
end
458+
459+
defp old_elixir_lock(Mix.Dep[opts: opts]) do
460+
old_vsn = Mix.Deps.Lock.elixir_vsn(opts[:build])
461+
if old_vsn && old_vsn != System.version do
462+
old_vsn
463+
end
464+
end
454465
end

lib/mix/lib/mix/deps/lock.ex

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,28 @@ defmodule Mix.Deps.Lock do
99
@doc """
1010
Returns the manifest file for dependencies.
1111
"""
12-
def manifest do
13-
Path.join(Mix.Project.manifest_path, @manifest)
12+
def manifest(manifest_path // Mix.Project.manifest_path) do
13+
Path.join(manifest_path, @manifest)
1414
end
1515

1616
@doc """
1717
Touches the manifest timestamp and updates the elixir version.
1818
"""
19-
def touch do
20-
manifest_path = Mix.Project.manifest_path
19+
def touch(manifest_path // Mix.Project.manifest_path) do
2120
File.mkdir_p!(manifest_path)
2221
File.write!(Path.join(manifest_path, @manifest), System.version)
2322
end
2423

2524
@doc """
2625
Returns the elixir lock version.
2726
"""
28-
def elixir_vsn do
29-
unless Mix.Project.umbrella? do
30-
case File.read(manifest) do
31-
{ :ok, contents } -> contents
32-
{ :error, _ } -> nil
33-
end
27+
def elixir_vsn(manifest_path // Mix.Project.manifest_path) do
28+
case File.read(manifest(manifest_path)) do
29+
{ :ok, contents } -> contents
30+
{ :error, _ } -> nil
3431
end
3532
end
3633

37-
@doc """
38-
Returns the lockfile path. In case this is a nested
39-
dependencies, the lockfile will always point to the
40-
parent project lockfile.
41-
"""
42-
def lockfile do
43-
Mix.project[:lockfile]
44-
end
45-
4634
@doc """
4735
Read the lockfile, returns a keyword list containing
4836
each app name and its current lock information.
@@ -72,4 +60,8 @@ defmodule Mix.Deps.Lock do
7260
touch
7361
end
7462
end
75-
end
63+
64+
defp lockfile do
65+
Mix.project[:lockfile]
66+
end
67+
end

lib/mix/lib/mix/deps/retriever.ex

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ defmodule Mix.Deps.Retriever do
139139

140140
## Fetching
141141

142-
defp mix_dep(Mix.Dep[opts: opts, app: app, status: status] = dep, config) do
142+
defp mix_dep(Mix.Dep[opts: opts, app: app] = dep, config) do
143143
Mix.Deps.in_dependency(dep, config, fn _ ->
144144
config = Mix.project
145145
umbrella? = Mix.Project.umbrella?
@@ -150,14 +150,12 @@ defmodule Mix.Deps.Retriever do
150150
Path.join(Mix.Project.compile_path(config), "#{app}.app")
151151
end
152152

153-
stat = cond do
154-
vsn = old_elixir_lock() -> { :elixirlock, vsn }
155-
req = old_elixir_req(config) -> { :elixirreq, req }
156-
true -> status
153+
if req = old_elixir_req(config) do
154+
dep = dep.status({ :elixirreq, req })
157155
end
158156

159157
opts = Keyword.put_new(opts, :app, app_path)
160-
{ dep.manager(:mix).opts(opts).status(stat).extra(umbrella: umbrella?), children }
158+
{ dep.manager(:mix).opts(opts).extra(umbrella: umbrella?), children }
161159
end)
162160
end
163161

@@ -210,13 +208,6 @@ defmodule Mix.Deps.Retriever do
210208
end
211209
end
212210

213-
defp old_elixir_lock do
214-
old_vsn = Mix.Deps.Lock.elixir_vsn
215-
if old_vsn && old_vsn != System.version do
216-
old_vsn
217-
end
218-
end
219-
220211
defp old_elixir_req(config) do
221212
req = config[:elixir]
222213
if req && not Version.match?(System.version, req) do

lib/mix/lib/mix/project.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ defmodule Mix.Project do
7171
@doc false
7272
def deps_config(config // config()) do
7373
[ build_path: build_path(config),
74-
deps_path: deps_path(config),
75-
lockfile: Path.expand(config[:lockfile]) ]
74+
deps_path: deps_path(config) ]
7675
end
7776

7877
@doc """

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ defmodule Mix.Tasks.Loadpaths do
3838
end
3939
end
4040

41-
# Force recompile if we have a version mismatch
42-
old_vsn = Mix.Deps.Lock.elixir_vsn
41+
# Force recompile if we have a version mismatch.
42+
# Skip it for umbrella apps since they have no build.
43+
old_vsn = not Mix.Project.umbrella? && Mix.Deps.Lock.elixir_vsn
4344
if old_vsn && old_vsn != System.version, do: Mix.Deps.Lock.touch
4445

4546
Enum.each Mix.Project.load_paths, &Code.prepend_path(&1)

0 commit comments

Comments
 (0)