Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mix.Tasks.Compile.reenable #13771

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/mix/lib/mix/tasks/compile.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,27 @@ defmodule Mix.Tasks.Compile do
|> maybe_prepend(:yecc)
end

@doc """
Reenables given compilers so they can be executed again down the stack.

If an umbrella project reenables compilers, they are re-enabled for all
child projects.

Default is `[]`, for none compilers to be reenabled.
This task always re-enables `"compiler.all"`.
josevalim marked this conversation as resolved.
Show resolved Hide resolved
"""
@spec reenable([{:compilers, compilers}]) :: :ok when compilers: :all | [Mix.Task.task_name()]
josevalim marked this conversation as resolved.
Show resolved Hide resolved
def reenable(opts \\ []) do
compilers =
case Keyword.get(opts, :compilers, :all) do
:all -> compilers()
list when is_list(list) -> list
end

Enum.each(["compile", "compile.all"], &Mix.Task.reenable(&1))
Enum.each(compilers, &Mix.Task.reenable("compile.#{&1}"))
end

defp maybe_prepend(compilers, compiler) do
if compiler in compilers do
compilers
Expand Down
27 changes: 27 additions & 0 deletions lib/mix/test/mix/tasks/compile.elixir_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,33 @@ defmodule Mix.Tasks.Compile.ElixirTest do
end)
end

test "recompiles newly created files" do
in_fixture("no_mixfile", fn ->
Mix.Project.push(MixTest.Case.Sample)

assert Mix.Tasks.Compile.Elixir.run(["--verbose"]) == {:ok, []}
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
assert_received {:mix_shell, :info, ["Compiled lib/b.ex"]}

Mix.shell().flush()

File.write!("lib/z.ex", """
defmodule Z do
def ok, do: :ok
end
""")

Mix.Task.reenable("compile.elixir")
assert {:ok, []} = Mix.Tasks.Compile.Elixir.run(["--verbose"])

assert_received {:mix_shell, :info, ["Compiled lib/z.ex"]}
refute_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
refute_received {:mix_shell, :info, ["Compiled lib/b.ex"]}

assert File.regular?("_build/dev/lib/sample/ebin/Elixir.Z.beam")
end)
end

josevalim marked this conversation as resolved.
Show resolved Hide resolved
test "recompiles dependent changed modules" do
in_fixture("no_mixfile", fn ->
Mix.Project.push(MixTest.Case.Sample)
Expand Down
31 changes: 31 additions & 0 deletions lib/mix/test/mix/tasks/compile_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ defmodule Mix.Tasks.CompileTest do
end)
end

test "recompiles newly created files" do
in_fixture("no_mixfile", fn ->
assert Mix.Tasks.Compile.run(["--verbose"]) == {:ok, []}
Mix.shell().flush()

File.mkdir_p!("lib/foo")

File.write!("lib/foo/z.ex", """
defmodule Z do
def ok, do: :ok
end
""")

assert :ok = Mix.Task.reenable("compile")
assert {:noop, []} = Mix.Task.run("compile")
refute File.regular?("_build/dev/lib/sample/ebin/Elixir.Z.beam")

assert :ok = Mix.Tasks.Compile.reenable(compilers: [])
assert {:noop, []} = Mix.Task.run("compile")
refute File.regular?("_build/dev/lib/sample/ebin/Elixir.Z.beam")

assert :ok = Mix.Tasks.Compile.reenable(compilers: ["erlang"])
assert {:noop, []} = Mix.Task.run("compile")
refute File.regular?("_build/dev/lib/sample/ebin/Elixir.Z.beam")

assert :ok = Mix.Tasks.Compile.reenable()
assert {:ok, []} = Mix.Task.run("compile")
assert File.regular?("_build/dev/lib/sample/ebin/Elixir.Z.beam")
end)
end

test "recompiles app cache if manifest changes" do
in_fixture("no_mixfile", fn ->
Mix.Tasks.Compile.run(["--force"])
Expand Down