Skip to content

Commit ba6c6da

Browse files
ericentinjosevalim
authored andcommitted
use ETF for elixir_scm and protocols manifests (#4779)
1 parent d4cc6ff commit ba6c6da

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

lib/mix/lib/mix/dep/elixir_scm.ex

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ defmodule Mix.Dep.ElixirSCM do
1010

1111
def update(manifest_path \\ Mix.Project.manifest_path) do
1212
config = Mix.Project.config
13-
data = {@manifest_vsn, System.version, config[:build_scm]}
1413
File.mkdir_p!(manifest_path)
15-
File.write!(manifest(manifest_path), :io_lib.format('~p.~n', [data]))
16-
:ok
14+
15+
manifest_data =
16+
{@manifest_vsn, System.version, config[:build_scm]}
17+
|> :erlang.term_to_binary(compressed: 9)
18+
19+
File.write!(manifest(manifest_path), manifest_data)
1720
end
1821

1922
def read(manifest_path \\ Mix.Project.manifest_path) do
20-
case :file.consult(manifest(manifest_path)) do
21-
{:ok, [{@manifest_vsn, vsn, scm}]} ->
22-
{:ok, vsn, scm}
23-
{:error, {_, :erl_parse, _}} ->
24-
{:ok, "1.0.0", nil} # Force old version if file exists but old format
23+
case manifest(manifest_path) |> File.read() do
24+
{:ok, contents} ->
25+
try do
26+
:erlang.binary_to_term(contents)
27+
else
28+
{@manifest_vsn, vsn, scm} ->
29+
{:ok, vsn, scm}
30+
31+
_ ->
32+
{:ok, "1.0.0", nil} # Force old version if file exists but old format
33+
rescue
34+
_ ->
35+
{:ok, "1.0.0", nil} # Force old version if file exists but old format
36+
end
37+
2538
_ ->
2639
:error
2740
end

lib/mix/lib/mix/tasks/compile.protocols.ex

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,28 @@ defmodule Mix.Tasks.Compile.Protocols do
132132
end
133133

134134
defp read_manifest(manifest, output) do
135-
case :file.consult(manifest) do
136-
{:ok, [@manifest_vsn | t]} ->
135+
try do
136+
manifest |> File.read!() |> :erlang.binary_to_term()
137+
else
138+
[@manifest_vsn | t] ->
137139
t
138-
{:ok, _} ->
140+
141+
_ ->
139142
# If manifest is out of date, remove old files
140-
_ = File.rm_rf(output)
141-
[]
142-
{:error, _} ->
143+
File.rm_rf(output)
143144
[]
145+
rescue
146+
_ -> []
144147
end
145148
end
146149

147150
defp write_manifest(_manifest, nil), do: :om
148151
defp write_manifest(manifest, metadata) do
149-
File.open!(manifest, [:write], fn device ->
150-
:io.format(device, '~p.~n', [@manifest_vsn])
151-
Enum.map metadata, fn entry ->
152-
:io.format(device, '~p.~n', [entry])
153-
end
154-
:ok
155-
end)
152+
manifest_data =
153+
[@manifest_vsn | metadata]
154+
|> :erlang.term_to_binary(compressed: 9)
155+
156+
File.write!(manifest, manifest_data)
156157
end
157158

158159
defp diff_manifest(manifest, new_metadata, output) do

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ defmodule Mix.Tasks.Compile.ElixirTest do
4747

4848
Mix.Task.clear
4949
File.write!("_build/dev/consolidated/.to_be_removed", "")
50-
File.write!("_build/dev/lib/sample/.compile.elixir_scm", ~s({v1, <<"0.0.0">>, nil}.))
50+
manifest_data = :erlang.term_to_binary({:v1, "0.0.0", nil})
51+
File.write!("_build/dev/lib/sample/.compile.elixir_scm", manifest_data)
5152
File.touch!("_build/dev/lib/sample/.compile.elixir_scm", {{2010, 1, 1}, {0, 0, 0}})
5253

5354
Mix.Tasks.Compile.run []
@@ -66,7 +67,8 @@ defmodule Mix.Tasks.Compile.ElixirTest do
6667
assert Mix.Dep.ElixirSCM.read == {:ok, System.version, Mix.SCM.Path}
6768

6869
Mix.Task.clear
69-
File.write!("_build/dev/lib/sample/.compile.elixir_scm", ~s({v1, <<"#{System.version}">>, another}.))
70+
manifest_data = :erlang.term_to_binary({:v1, "#{System.version}", :another})
71+
File.write!("_build/dev/lib/sample/.compile.elixir_scm", manifest_data)
7072
File.touch!("_build/dev/lib/sample/.compile.elixir_scm", {{2010, 1, 1}, {0, 0, 0}})
7173

7274
Mix.Tasks.Compile.run []

lib/mix/test/mix/tasks/deps_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ defmodule Mix.Tasks.DepsTest do
512512
Mix.Tasks.Deps.Check.run []
513513

514514
File.mkdir_p!("_build/dev/lib/ok/ebin")
515-
File.write!("_build/dev/lib/ok/.compile.elixir_scm", ~s({v1, <<\"the_future\">>, scm}.))
515+
manifest_data = :erlang.term_to_binary({:v1, "the_future", :scm})
516+
File.write!("_build/dev/lib/ok/.compile.elixir_scm", manifest_data)
516517
Mix.Task.clear
517518

518519
msg = " the dependency was built with an out-of-date Elixir version, run \"mix deps.compile\""
@@ -536,7 +537,8 @@ defmodule Mix.Tasks.DepsTest do
536537
Mix.Tasks.Deps.Check.run []
537538

538539
File.mkdir_p!("_build/dev/lib/ok/ebin")
539-
File.write!("_build/dev/lib/ok/.compile.elixir_scm", ~s({v1, <<"#{System.version}">>, scm}.))
540+
manifest_data = :erlang.term_to_binary({:v1, "#{System.version}", :scm})
541+
File.write!("_build/dev/lib/ok/.compile.elixir_scm", manifest_data)
540542
Mix.Task.clear
541543

542544
msg = " the dependency was built with another SCM, run \"mix deps.compile\""

0 commit comments

Comments
 (0)