Skip to content

Commit 85ca87f

Browse files
author
José Valim
committed
Ensure changes in deps propagate to all umbrella children
This fix a long standing issue where users would have to delete _build after updating a dependency to recompile. This is done by a currently private and recursive task called will_recompile.
1 parent f244ee3 commit 85ca87f

File tree

5 files changed

+54
-25
lines changed

5 files changed

+54
-25
lines changed

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,6 @@
55
defmodule Mix.Dep.Lock do
66
@moduledoc false
77

8-
@manifest "compile.lock"
9-
10-
@doc """
11-
Returns the manifest file for dependencies.
12-
13-
The manifest is used to check if the lockfile
14-
itself is up to date.
15-
"""
16-
def manifest(path \\ Mix.Project.manifest_path()) do
17-
Path.join(path, @manifest)
18-
end
19-
20-
@doc """
21-
Touches the manifest file to force recompilation.
22-
"""
23-
def touch_manifest do
24-
path = Mix.Project.manifest_path()
25-
File.mkdir_p!(path)
26-
File.touch!(manifest(path))
27-
end
28-
298
@doc """
309
Reads the lockfile, returns a map containing
3110
each app name and its current lock information.
@@ -57,7 +36,7 @@ defmodule Mix.Dep.Lock do
5736
end
5837

5938
File.write!(lockfile(), ["%{\n", lines, "}\n"])
60-
touch_manifest()
39+
Mix.Task.run("will_recompile")
6140
end
6241

6342
:ok

lib/mix/lib/mix/project.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ defmodule Mix.Project do
207207
"""
208208
@spec config_files() :: [Path.t()]
209209
def config_files do
210-
[Mix.Dep.Lock.manifest() | Mix.ProjectStack.config_files()]
210+
[Mix.Tasks.WillRecompile.manifest() | Mix.ProjectStack.config_files()]
211211
end
212212

213213
@doc """
@@ -220,7 +220,7 @@ defmodule Mix.Project do
220220
@doc since: "1.7.0"
221221
@spec config_mtime() :: posix_mtime when posix_mtime: integer()
222222
def config_mtime do
223-
Mix.Dep.Lock.manifest()
223+
Mix.Tasks.WillRecompile.manifest()
224224
|> Mix.Utils.last_modified()
225225
|> max(Mix.ProjectStack.config_mtime())
226226
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defmodule Mix.Tasks.Deps.Compile do
101101
compiled? and fetchable?
102102
end)
103103

104-
if true in compiled, do: Mix.Dep.Lock.touch_manifest(), else: :ok
104+
if true in compiled, do: Mix.Task.run("will_recompile"), else: :ok
105105
end
106106

107107
defp maybe_clean(dep, opts) do
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defmodule Mix.Tasks.WillRecompile do
2+
use Mix.Task
3+
4+
@moduledoc false
5+
@recursive true
6+
@manifest "compile.lock"
7+
8+
@doc """
9+
Returns the will_recompile manifest for the project.
10+
"""
11+
def manifest(path \\ Mix.Project.manifest_path()) do
12+
Path.join(path, @manifest)
13+
end
14+
15+
@doc """
16+
Annotates the current project will recompile.
17+
"""
18+
def run(_) do
19+
path = Mix.Project.manifest_path()
20+
File.mkdir_p!(path)
21+
File.touch!(manifest(path))
22+
end
23+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Code.require_file("../../test_helper.exs", __DIR__)
2+
3+
defmodule Mix.Tasks.WillRecompileTest do
4+
use MixTest.Case
5+
6+
test "marks current project to recompile" do
7+
in_fixture("deps_status/deps/ok", fn ->
8+
Mix.Project.in_project(:ok, ".", fn _ ->
9+
refute File.exists?("_build/dev/lib/ok/.mix/compile.lock")
10+
Mix.Task.run("will_recompile")
11+
assert File.exists?("_build/dev/lib/ok/.mix/compile.lock")
12+
end)
13+
end)
14+
end
15+
16+
test "marks all projects in umbrella to recompile" do
17+
in_fixture("umbrella_dep/deps/umbrella", fn ->
18+
Mix.Project.in_project(:umbrella, ".", fn _ ->
19+
refute File.exists?("_build/dev/lib/foo/.mix/compile.lock")
20+
refute File.exists?("_build/dev/lib/bar/.mix/compile.lock")
21+
Mix.Task.run("will_recompile")
22+
assert File.exists?("_build/dev/lib/foo/.mix/compile.lock")
23+
assert File.exists?("_build/dev/lib/bar/.mix/compile.lock")
24+
end)
25+
end)
26+
end
27+
end

0 commit comments

Comments
 (0)