Skip to content

Commit 597381b

Browse files
author
José Valim
committed
Write to manifest when file is removed
Signed-off-by: José Valim <[email protected]>
1 parent df70729 commit 597381b

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule Mix.Compilers.Elixir do
1818
all_entries = read_manifest(manifest)
1919

2020
removed =
21-
for {_b, _m, source, _d, _f} <- all_entries, not(source in all), do: source
21+
for {_b, _m, source, _d, _f, _bin} <- all_entries, not(source in all), do: source
2222

2323
changed =
2424
if force do
@@ -32,10 +32,10 @@ defmodule Mix.Compilers.Elixir do
3232
# Otherwise let's start with the new ones
3333
# plus the ones that have changed
3434
for(source <- all,
35-
not Enum.any?(all_entries, fn {_b, _m, s, _d, _f} -> s == source end),
35+
not Enum.any?(all_entries, fn {_b, _m, s, _d, _f, _bin} -> s == source end),
3636
do: source)
3737
++
38-
for({_b, _m, source, _d, files} <- all_entries,
38+
for({_b, _m, source, _d, files, _bin} <- all_entries,
3939
times = Enum.map([source|files], &HashDict.fetch!(all_mtimes, &1)),
4040
Mix.Utils.stale?(times, [modified]),
4141
do: source)
@@ -46,17 +46,18 @@ defmodule Mix.Compilers.Elixir do
4646

4747
cond do
4848
stale != [] ->
49-
do_compile(manifest, entries, stale, dest, on_start)
49+
compile_manifest(manifest, entries, stale, dest, on_start)
5050
:ok
5151
removed != [] ->
52+
write_manifest(manifest, entries)
5253
:ok
5354
true ->
5455
:noop
5556
end
5657
end
5758

5859
defp mtimes(entries) do
59-
Enum.reduce(entries, HashDict.new, fn {_b, _m, source, _d, files}, dict ->
60+
Enum.reduce(entries, HashDict.new, fn {_b, _m, source, _d, files, _bin}, dict ->
6061
Enum.reduce([source|files], dict, fn file, dict ->
6162
if HashDict.has_key?(dict, file) do
6263
dict
@@ -82,16 +83,14 @@ defmodule Mix.Compilers.Elixir do
8283
end
8384
end
8485

85-
defp do_compile(manifest, entries, stale, dest, on_start) do
86+
defp compile_manifest(manifest, entries, stale, dest, on_start) do
8687
Mix.Project.build_structure
8788
on_start.()
8889
cwd = File.cwd!
8990

9091
# Starts a server responsible for keeping track which files
9192
# were compiled and the dependencies in between them.
92-
{:ok, pid} = Agent.start_link(fn ->
93-
Enum.map(entries, &Tuple.insert_at(&1, 5, nil))
94-
end)
93+
{:ok, pid} = Agent.start_link(fn -> entries end)
9594

9695
try do
9796
_ = Kernel.ParallelCompiler.files :lists.usort(stale),
@@ -155,7 +154,7 @@ defmodule Mix.Compilers.Elixir do
155154
remove_stale_entries(all, :lists.usort(changed), [], [])
156155
end
157156

158-
defp remove_stale_entries([{beam, module, source, _d, _f} = entry|t], changed, removed, acc) do
157+
defp remove_stale_entries([{beam, module, source, _d, _f, _bin} = entry|t], changed, removed, acc) do
159158
if source in changed do
160159
atom = String.to_atom(module)
161160
_ = File.rm(beam)
@@ -170,7 +169,7 @@ defmodule Mix.Compilers.Elixir do
170169
defp remove_stale_entries([], changed, removed, acc) do
171170
# If any of the dependencies for the remaining entries
172171
# were removed, get its source so we can remove them.
173-
next_changed = for {_b, _m, source, deps, _f} <- acc,
172+
next_changed = for {_b, _m, source, deps, _f, _bin} <- acc,
174173
Enum.any?(deps, &(&1 in removed)),
175174
do: source
176175

@@ -193,7 +192,7 @@ defmodule Mix.Compilers.Elixir do
193192
{deps, ["Elixir"|files]} -> {deps, files}
194193
{deps, _} -> {deps, []}
195194
end
196-
[{beam, module, source, deps, files}|acc]
195+
[{beam, module, source, deps, files, nil}|acc]
197196
_ ->
198197
acc
199198
end
@@ -216,6 +215,11 @@ defmodule Mix.Compilers.Elixir do
216215
[beam, module, source | tail] |> Enum.join("\t")
217216
end)
218217

218+
# The Mix.Dep.Lock keeps all the project dependencies. Since Elixir
219+
# is a dependency itself, we need to touch the lock so the current
220+
# Elixir version, used to compile the files above, is properly stored.
221+
Mix.Dep.Lock.touch
222+
219223
File.mkdir_p!(Path.dirname(manifest))
220224
File.write!(manifest, Enum.join(lines, "\n"))
221225
end

lib/mix/lib/mix/tasks/compile.elixir.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,10 @@ defmodule Mix.Tasks.Compile.Elixir do
6262
force = opts[:force] || local_deps_changed?(manifest)
6363
|| Mix.Utils.stale?(configs, [manifest])
6464

65-
result = Mix.Compilers.Elixir.compile(manifest, srcs, [:ex], dest, force, fn ->
65+
Mix.Compilers.Elixir.compile(manifest, srcs, [:ex], dest, force, fn ->
6666
true = Code.prepend_path(dest)
6767
set_compiler_opts(project, opts, [])
6868
end)
69-
70-
# The Mix.Dep.Lock keeps all the project dependencies. Since Elixir
71-
# is a dependency itself, we need to touch the lock so the current
72-
# Elixir version, used to compile the files above, is properly stored.
73-
unless result == :noop, do: Mix.Dep.Lock.touch
74-
result
7569
end
7670

7771
@doc """

lib/mix/test/mix/tasks/compile.elixir_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ defmodule Mix.Tasks.Compile.ElixirTest do
6565
assert Mix.Tasks.Compile.Elixir.run([]) == :ok
6666
refute File.regular?("_build/dev/lib/sample/ebin/Elixir.A.beam")
6767
refute Code.ensure_loaded?(A)
68+
refute String.contains?(File.read!("_build/dev/lib/sample/.compile.elixir"),
69+
"Elixir.A.beam")
6870
end
6971
end
7072

0 commit comments

Comments
 (0)