Skip to content

Commit

Permalink
Write consolidated files to _build
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed May 26, 2014
1 parent 6aada7f commit 23f0ff8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/mix/lib/mix/tasks/compile.protocols.ex
Expand Up @@ -14,12 +14,12 @@ defmodule Mix.Tasks.Compile.Protocols do
protocol versions. Simply add it to your codepath to
make use of it:
mix run -pa consolidated
mix run -pa _build/dev/consolidated
You can verify a protocol is consolidated by checking
its attributes:
elixir -pa consolidated -S \
elixir -pa _build/dev/consolidated -S \
mix run -e "IO.puts Protocol.consolidated?(Enumerable)"
"""
Expand All @@ -31,7 +31,7 @@ defmodule Mix.Tasks.Compile.Protocols do
paths = filter_otp(:code.get_path, :code.lib_dir)
paths
|> Protocol.extract_protocols
|> consolidate(paths, opts[:output] || "consolidated")
|> consolidate(paths, opts[:output] || Path.join(Mix.Project.build_path, "consolidated"))

:ok
end
Expand All @@ -50,6 +50,9 @@ defmodule Mix.Tasks.Compile.Protocols do
File.write!(Path.join(output, "#{protocol}.beam"), binary)
Mix.shell.info "Consolidated #{inspect protocol}"
end

relative = Path.relative_to_cwd(output)
Mix.shell.info "Consolidated protocols written to #{relative}"
end

defp maybe_reload(module) do
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/test/mix/tasks/compile.protocols_test.exs
Expand Up @@ -10,10 +10,10 @@ defmodule Mix.Tasks.Compile.ProtocolsTest do
assert Mix.Tasks.Compile.Protocols.run([]) == :ok
assert_received {:mix_shell, :info, ["Consolidated Enumerable"]}

assert File.regular? "consolidated/Elixir.Enumerable.beam"
assert File.regular? "_build/dev/consolidated/Elixir.Enumerable.beam"
purge [Enumerable]

Code.prepend_path("consolidated")
Code.prepend_path("_build/dev/consolidated")
assert Protocol.consolidated?(Enumerable)
end
after
Expand Down

0 comments on commit 23f0ff8

Please sign in to comment.