Skip to content

Commit c0a6dc4

Browse files
author
José Valim
committed
Simplify manifest API and put tests back on green
1 parent 99da29b commit c0a6dc4

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,17 @@ defmodule Mix.Tasks.Compile.Elixir do
7878
to_compile = Mix.Utils.extract_files(elixirc_paths, compile_exts)
7979
to_watch = Mix.Utils.extract_files(elixirc_paths, watch_exts)
8080

81-
force = opts[:force]
8281
stale = if Mix.Utils.stale?(Mix.Project.config_files, [manifest]) do
8382
force = true
8483
to_watch
8584
else
85+
force = opts[:force]
8686
Mix.Utils.extract_stale(to_watch, [manifest])
8787
end
8888

8989
if force or stale != [] do
9090
File.mkdir_p! compile_path
91+
Code.prepend_path compile_path
9192
compile_files opts[:quick], project, compile_path, to_compile, stale, opts
9293
:ok
9394
else
@@ -103,19 +104,17 @@ defmodule Mix.Tasks.Compile.Elixir do
103104
end
104105

105106
defp compile_files(false, project, compile_path, to_compile, _stale, opts) do
106-
Mix.Utils.read_manifest Path.join(compile_path, @manifest), fn file ->
107-
Path.join(compile_path, file) <> ".beam" |> File.rm
107+
previous = Mix.Utils.read_manifest(Path.join(compile_path, @manifest))
108+
109+
Enum.each previous, fn entry ->
110+
Path.join(compile_path, entry <> ".beam") |> File.rm
108111
end
109112

110113
set_compiler_opts(project, opts, [])
114+
compiled = compile_files to_compile, compile_path
115+
compiled = lc { mod, _ } inlist compiled, do: atom_to_binary(mod)
111116

112-
{ _current, to_remove } =
113-
Mix.Utils.update_manifest Path.join(compile_path, @manifest), fn ->
114-
compiled = compile_files to_compile, compile_path
115-
lc { mod, _ } inlist compiled, do: atom_to_binary(mod)
116-
end
117-
118-
lc f inlist to_remove, do: File.rm(Path.join(compile_path, f) <> ".beam")
117+
Mix.Utils.update_manifest(Path.join(compile_path, @manifest), compiled)
119118
end
120119

121120
defp set_compiler_opts(project, opts, extra) do

lib/mix/lib/mix/utils.ex

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ defmodule Mix.Utils do
106106
end
107107

108108
@doc """
109-
Read the manifest.
109+
Reads the manifest and return each entry.
110110
"""
111-
def read_manifest(file, fun) do
112-
if File.exists?(file) do
113-
Enum.each File.stream!(file), fn file ->
114-
fun.(String.rstrip(file, ?\n))
115-
end
111+
def read_manifest(file) do
112+
case File.read(file) do
113+
{ :ok, contents } -> String.split(contents, "\n")
114+
{ :error, _ } -> []
116115
end
117116
end
118117

@@ -123,15 +122,8 @@ defmodule Mix.Utils do
123122
function is compared to the manifest in order do detect
124123
the files removed from the manifest file.
125124
"""
126-
def update_manifest(file, fun) do
127-
old =
128-
case File.read(file) do
129-
{ :ok, contents } -> String.split(contents, "\n")
130-
{ :error, _ } -> []
131-
end
132-
current = fun.()
133-
File.write!(file, Enum.join(current, "\n"))
134-
{ current, old -- current }
125+
def update_manifest(file, new) do
126+
File.write!(file, Enum.join(new, "\n"))
135127
end
136128

137129
@doc """

0 commit comments

Comments
 (0)