Skip to content

Commit 22635e6

Browse files
committed
Allow forcing specific compilers
1 parent 4a8d4f2 commit 22635e6

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

lib/mix/lib/mix/task.compiler.ex

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,24 @@ defmodule Mix.Task.Compiler do
295295
end
296296

297297
defp run_compiler(compiler, args) do
298-
result = normalize(Mix.Task.run("compile.#{compiler}", args), compiler)
298+
args_maybe_force = maybe_prepend_force(args, compiler)
299+
result = normalize(Mix.Task.run("compile.#{compiler}", args_maybe_force), compiler)
299300
Enum.reduce(Mix.ProjectStack.pop_after_compiler(compiler), result, & &1.(&2))
300301
end
301302

303+
defp maybe_prepend_force(args, compiler) do
304+
args
305+
|> Enum.any?(fn
306+
"--force-" <> rest -> rest == compiler |> to_string() |> String.replace("_", "-")
307+
_ -> false
308+
end)
309+
|> if do
310+
["--force" | args]
311+
else
312+
args
313+
end
314+
end
315+
302316
# Normalize the compiler result to a diagnostic tuple
303317
defp normalize(result, name) do
304318
case result do

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

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

88
@shortdoc "Compiles source files"
99

10-
@moduledoc """
10+
@moduledoc ~S"""
1111
The main entry point to compile source files.
1212
1313
It simply runs the compilers registered in your project and returns
@@ -59,7 +59,9 @@ defmodule Mix.Tasks.Compile do
5959
* `--all-warnings` (`--no-all-warnings`) - prints all warnings, including previous compilations
6060
(default is true except on errors)
6161
* `--erl-config` - path to an Erlang term file that will be loaded as Mix config
62-
* `--force` - forces compilation
62+
* `--force` - forces compilation. You can also specify `--force-#{compiler}` for each compiler
63+
invoked to force specifically that compiler to run (it requires the compiler to respect the
64+
`--force` option, which is advised)
6365
* `--list` - lists all enabled compilers
6466
* `--listeners` - starts Mix listeners (they are started by default,
6567
unless `--no-listeners` or `--no-deps-check` are given)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,23 @@ defmodule Mix.Tasks.Compile.ElixirTest do
12531253
end)
12541254
end
12551255

1256+
test "recompiles with --force-elixir" do
1257+
in_fixture("no_mixfile", fn ->
1258+
Mix.Project.push(MixTest.Case.Sample)
1259+
assert Mix.Task.run("compile") == {:ok, []}
1260+
purge([A, B])
1261+
1262+
# Now we have a noop
1263+
Mix.Task.clear()
1264+
assert Mix.Task.run("compile") == {:noop, []}
1265+
1266+
# --force-elixir
1267+
Mix.Task.clear()
1268+
assert Mix.Task.run("compile", ["--verbose", "--force-elixir"]) == {:ok, []}
1269+
assert_received {:mix_shell, :info, ["Compiled lib/a.ex"]}
1270+
end)
1271+
end
1272+
12561273
test "compiles files with autoload disabled" do
12571274
in_fixture("no_mixfile", fn ->
12581275
Mix.Project.push(MixTest.Case.Sample)

0 commit comments

Comments
 (0)