Fix protocols diff calculation between compilations (#6339)
This commit is contained in:
@@ -193,14 +193,20 @@ defmodule Mix.Tasks.Compile.Protocols do
|
||||
Map.put(protocols, protocol, true)
|
||||
end)
|
||||
|
||||
removed_metadata =
|
||||
old_metadata -- new_metadata
|
||||
|
||||
removed_protocols =
|
||||
for {protocol, :protocol, _beam} <- removed_metadata,
|
||||
remove_consolidated(protocol, output),
|
||||
do: {protocol, true},
|
||||
into: %{}
|
||||
|
||||
protocols =
|
||||
Enum.reduce(old_metadata -- new_metadata, protocols, fn
|
||||
{_, {:impl, protocol}, _beam}, protocols ->
|
||||
Map.put(protocols, protocol, true)
|
||||
{protocol, :protocol, _beam}, protocols ->
|
||||
remove_consolidated(protocol, output)
|
||||
protocols
|
||||
end)
|
||||
for {_, {:impl, protocol}, _beam} <- removed_metadata,
|
||||
not Map.has_key?(removed_protocols, protocol),
|
||||
do: {protocol, true},
|
||||
into: protocols
|
||||
|
||||
Map.keys(protocols)
|
||||
end
|
||||
|
||||
@@ -42,6 +42,41 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do
|
||||
end
|
||||
end
|
||||
|
||||
test "compiles after converting a protocol into a standard module", context do
|
||||
Mix.Project.push MixTest.Case.Sample
|
||||
|
||||
in_tmp context.test, fn ->
|
||||
File.mkdir_p!("lib")
|
||||
assert Mix.Task.run("compile")
|
||||
|
||||
# Define a local protocol
|
||||
File.write!("lib/protocol.ex", """
|
||||
defprotocol Compile.Protocol do
|
||||
def foo(a)
|
||||
end
|
||||
|
||||
defimpl Compile.Protocol, for: Integer do
|
||||
def foo(a), do: a
|
||||
end
|
||||
""")
|
||||
assert compile_elixir_and_protocols() == :ok
|
||||
mark_as_old!("_build/dev/lib/sample/consolidated/Elixir.Compile.Protocol.beam")
|
||||
File.rm!("lib/protocol.ex")
|
||||
|
||||
# Define a standard module
|
||||
File.write!("lib/protocol.ex", """
|
||||
defmodule Compile.Protocol do
|
||||
end
|
||||
""")
|
||||
assert compile_elixir_and_protocols() == :noop
|
||||
|
||||
# Delete a local protocol
|
||||
File.rm!("lib/protocol.ex")
|
||||
assert compile_elixir_and_protocols() == :noop
|
||||
refute File.regular?("_build/dev/lib/sample/consolidated/Elixir.Compile.Protocol.beam")
|
||||
end
|
||||
end
|
||||
|
||||
test "compiles and consolidates deps protocols", context do
|
||||
Mix.Project.push MixTest.Case.Sample
|
||||
|
||||
|
||||
Reference in New Issue
Block a user