Skip to content

Commit 0e804a2

Browse files
committed
Merge pull request #2513 from ericmj/mix-mtimes
Warn and reset mime on future files
2 parents 5a4b276 + 33ab167 commit 0e804a2

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ defmodule Mix.Compilers.Elixir do
2626
# changed, let's just compile everything
2727
all
2828
else
29-
modified = Mix.Utils.last_modified(manifest)
29+
modified = Mix.Utils.last_modified(manifest)
30+
all_mtimes = mtimes(all_entries)
3031

3132
# Otherwise let's start with the new ones
3233
# plus the ones that have changed
@@ -35,7 +36,8 @@ defmodule Mix.Compilers.Elixir do
3536
do: source)
3637
++
3738
for({_b, _m, source, _d, files} <- all_entries,
38-
Mix.Utils.stale?([source|files], [modified]),
39+
times = Enum.map([source|files], &HashDict.fetch!(all_mtimes, &1)),
40+
Mix.Utils.stale?(times, [modified]),
3941
do: source)
4042
end
4143

@@ -53,6 +55,18 @@ defmodule Mix.Compilers.Elixir do
5355
end
5456
end
5557

58+
defp mtimes(entries) do
59+
Enum.reduce(entries, HashDict.new, fn {_b, _m, source, _d, files}, dict ->
60+
Enum.reduce([source|files], dict, fn file, dict ->
61+
if HashDict.has_key?(dict, file) do
62+
dict
63+
else
64+
HashDict.put(dict, file, Mix.Utils.last_modified(file))
65+
end
66+
end)
67+
end)
68+
end
69+
5670
@doc """
5771
Removes compiled files.
5872
"""

lib/mix/lib/mix/utils.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ defmodule Mix.Utils do
9999
end
100100

101101
def last_modified(path) do
102+
now = :calendar.local_time
103+
102104
case File.stat(path) do
103-
{:ok, %File.Stat{mtime: mtime}} -> mtime
104-
{:error, _} -> {{1970, 1, 1}, {0, 0, 0}}
105+
{:ok, %File.Stat{mtime: mtime}} when mtime > now ->
106+
Mix.shell.error("warning: mtime (modified time) for \"#{path}\" was set to the future, resetting to now")
107+
File.touch!(path, now)
108+
mtime
109+
{:ok, %File.Stat{mtime: mtime}} ->
110+
mtime
111+
{:error, _} ->
112+
{{1970, 1, 1}, {0, 0, 0}}
105113
end
106114
end
107115

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ defmodule Mix.Tasks.Compile.ElixirTest do
7979
File.touch!("lib/a.ex", future)
8080
Mix.Tasks.Compile.Elixir.run []
8181

82+
assert_received {:mix_shell, :error, ["warning: mtime (modified time) for \"lib/a.ex\" was set to the future, resetting to now"]}
83+
refute_received {:mix_shell, :error, ["warning: mtime (modified time) for \"lib/b.ex\" was set to the future, resetting to now"]}
84+
8285
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
8386
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}
8487

0 commit comments

Comments
 (0)