Skip to content

Commit 25b813c

Browse files
author
José Valim
committed
Make a distinction between touching and updating the lock manifest
Previously, deps.compile would update the parent project lock manifest, which updated its Elixir version and made it impossible to detect later on that we were upgrading from a previous Elixir version. This commit adds the ability to both touch and update the manifest file and change deps.compile to only touch it.
1 parent c7aec3a commit 25b813c

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

lib/mix/lib/mix/compilers/elixir.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Mix.Compilers.Elixir do
22
@moduledoc false
33

4-
@manifest_vsn 1
4+
@manifest_vsn :v1
55

66
@doc """
77
Compiles stale Elixir files.
@@ -199,7 +199,7 @@ defmodule Mix.Compilers.Elixir do
199199

200200
defp read_manifest(manifest) do
201201
case :file.consult(manifest) do
202-
{:ok, [{:version, @manifest_vsn}|t]} -> t
202+
{:ok, [@manifest_vsn|t]} -> t
203203
_ -> []
204204
end
205205
end
@@ -223,7 +223,7 @@ defmodule Mix.Compilers.Elixir do
223223
File.mkdir_p!(Path.dirname(manifest))
224224

225225
File.open!(manifest, [:write], fn device ->
226-
:io.format(device, '~p.~n', [{:version, @manifest_vsn}])
226+
:io.format(device, '~p.~n', [@manifest_vsn])
227227

228228
Enum.map entries, fn {beam, _, _, _, _, _, binary} = entry ->
229229
if binary, do: File.write!(beam, binary)
@@ -236,6 +236,6 @@ defmodule Mix.Compilers.Elixir do
236236
# The Mix.Dep.Lock keeps all the project dependencies. Since Elixir
237237
# is a dependency itself, we need to touch the lock so the current
238238
# Elixir version, used to compile the files above, is properly stored.
239-
Mix.Dep.Lock.touch
239+
Mix.Dep.Lock.update_manifest
240240
end
241241
end

lib/mix/lib/mix/dep/lock.ex

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ defmodule Mix.Dep.Lock do
88

99
@doc """
1010
Returns the manifest file for dependencies.
11+
12+
The manifest is used to check if the lockfile
13+
itself is up to date.
1114
"""
1215
@spec manifest(Path.t) :: Path.t
1316
def manifest(manifest_path \\ Mix.Project.manifest_path) do
1417
Path.join(manifest_path, @manifest)
1518
end
1619

1720
@doc """
18-
Touches the manifest storing the current project info unless it is an umbrella application.
21+
Updates the lock manifest with the latest metadata.
1922
"""
20-
@spec touch :: :ok
21-
def touch do
23+
@spec update_manifest :: :ok
24+
def update_manifest do
2225
config = Mix.Project.config
2326
unless Mix.Project.umbrella?(config) do
2427
manifest_path = Mix.Project.manifest_path(config)
@@ -29,6 +32,19 @@ defmodule Mix.Dep.Lock do
2932
:ok
3033
end
3134

35+
@doc """
36+
Touches the manifest file to force recompilation.
37+
"""
38+
@spec touch_manifest :: :ok
39+
def touch_manifest do
40+
config = Mix.Project.config
41+
unless Mix.Project.umbrella?(config) do
42+
manifest = manifest()
43+
File.exists?(manifest) && File.touch(manifest)
44+
end
45+
:ok
46+
end
47+
3248
@doc """
3349
Returns the manifest status with Elixir version and scm.
3450
"""
@@ -71,7 +87,7 @@ defmodule Mix.Dep.Lock do
7187
~s("#{app}": #{inspect rev, limit: :infinity})
7288
end
7389
File.write! lockfile, "%{" <> Enum.join(lines, ",\n ") <> "}\n"
74-
touch
90+
update_manifest()
7591
end
7692
:ok
7793
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule Mix.Tasks.Deps.Compile do
7272
compiled
7373
end)
7474

75-
if Enum.any?(compiled), do: Mix.Dep.Lock.touch, else: :ok
75+
if Enum.any?(compiled), do: Mix.Dep.Lock.touch_manifest, else: :ok
7676
end
7777

7878
defp touch_fetchable(scm, path) do

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ defmodule Mix.Tasks.Loadpaths do
5959
vsn = System.version
6060
scm = config[:build_scm]
6161

62-
# Force recompile if we have lock mismatch
62+
# Erase the app build if we have lock mismatch.
63+
# We do this to force full recompilation when
64+
# any of SCM or Elixir version changes. Applies
65+
# to dependencies and the main project alike.
6366
case Mix.Dep.Lock.status() do
6467
{:ok, old_vsn, _} when old_vsn != vsn -> rm_rf_app(config)
6568
{:ok, _, old_scm} when old_scm != scm -> rm_rf_app(config)

lib/mix/test/mix/dep/lock_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ defmodule Mix.Dep.LockTest do
2929
test "stores status in manifest" do
3030
in_fixture "no_mixfile", fn ->
3131
assert Mix.Dep.Lock.status == :error
32-
Mix.Dep.Lock.touch
32+
Mix.Dep.Lock.touch_manifest
33+
assert Mix.Dep.Lock.status == :error
34+
Mix.Dep.Lock.update_manifest
3335
assert Mix.Dep.Lock.status == {:ok, System.version, nil}
3436
end
3537
end

0 commit comments

Comments
 (0)