Skip to content

Commit 463f1aa

Browse files
committed
Do not recompile if compilation fails due to --warnings-as-errors
1 parent a3a632e commit 463f1aa

File tree

4 files changed

+15
-91
lines changed

4 files changed

+15
-91
lines changed

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ defmodule Code do
17091709
def put_compiler_option(:warnings_as_errors, _value) do
17101710
IO.warn(
17111711
":warnings_as_errors is deprecated as part of Code.put_compiler_option/2, " <>
1712-
"pass it as option to Kernel.ParallelCompiler instead or as a --warnings-as-errors flag. " <>
1712+
"instead you must pass it as a --warnings-as-errors flag. " <>
17131713
"If you need to set it as a default in a mix task, you can also set it under aliases: " <>
17141714
"[compile: \"compile --warnings-as-errors\"]"
17151715
)

lib/elixir/lib/kernel/parallel_compiler.ex

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,28 +257,13 @@ defmodule Kernel.ParallelCompiler do
257257

258258
{status, modules_or_errors, info} =
259259
try do
260-
outcome = spawn_workers(schedulers, cache, files, output, options)
261-
{outcome, Keyword.get(options, :warnings_as_errors, false)}
260+
spawn_workers(schedulers, cache, files, output, options)
262261
else
263-
{{:ok, _, %{runtime_warnings: r_warnings, compile_warnings: c_warnings} = info}, true}
264-
when r_warnings != [] or c_warnings != [] ->
265-
message =
266-
"Compilation failed due to warnings while using the --warnings-as-errors option"
267-
268-
IO.puts(:stderr, message)
269-
errors = Enum.map(r_warnings ++ c_warnings, &Map.replace!(&1, :severity, :error))
270-
{:error, errors, %{info | runtime_warnings: [], compile_warnings: []}}
271-
272-
{{:ok, outcome, info}, _} ->
262+
{:ok, outcome, info} ->
273263
beam_timestamp = Keyword.get(options, :beam_timestamp)
274264
{:ok, write_module_binaries(outcome, output, beam_timestamp), info}
275265

276-
{{:error, errors, info}, true} ->
277-
%{runtime_warnings: r_warnings, compile_warnings: c_warnings} = info
278-
info = %{info | runtime_warnings: [], compile_warnings: []}
279-
{:error, c_warnings ++ r_warnings ++ errors, info}
280-
281-
{{:error, errors, info}, _} ->
266+
{:error, errors, info} ->
282267
{:error, errors, info}
283268
after
284269
Module.ParallelChecker.stop(cache)

lib/elixir/test/elixir/kernel/parallel_compiler_test.exs

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -421,40 +421,6 @@ defmodule Kernel.ParallelCompilerTest do
421421
end)
422422
end
423423

424-
test "supports warnings as errors" do
425-
[fixture] =
426-
write_tmp(
427-
"warnings_as_errors",
428-
warnings_as_errors: """
429-
defmodule WarningsSample do
430-
def hello(a), do: a
431-
def hello(b), do: b
432-
end
433-
"""
434-
)
435-
436-
output = tmp_path("not_to_be_used")
437-
438-
try do
439-
msg =
440-
capture_io(:stderr, fn ->
441-
assert {:error, [error], []} =
442-
Kernel.ParallelCompiler.compile_to_path([fixture], output,
443-
warnings_as_errors: true
444-
)
445-
446-
assert {^fixture, {3, 7}, "this clause " <> _} = error
447-
end)
448-
449-
assert msg =~
450-
"Compilation failed due to warnings while using the --warnings-as-errors option\n"
451-
after
452-
purge([WarningsSample])
453-
end
454-
455-
refute File.exists?(output)
456-
end
457-
458424
test "does not use incorrect line number when error originates in another file" do
459425
File.mkdir_p!(tmp_path())
460426

@@ -587,33 +553,5 @@ defmodule Kernel.ParallelCompilerTest do
587553
"cannot compile module WithBehaviourAndStruct (errors have been logged)"
588554
end) =~ expected_msg
589555
end
590-
591-
test "supports warnings as errors" do
592-
[fixture] =
593-
write_tmp(
594-
"warnings_as_errors",
595-
warnings_as_errors: """
596-
defmodule WarningsSample do
597-
def hello(a), do: a
598-
def hello(b), do: b
599-
end
600-
"""
601-
)
602-
603-
try do
604-
msg =
605-
capture_io(:stderr, fn ->
606-
assert {:error, [error], []} =
607-
Kernel.ParallelCompiler.require([fixture], warnings_as_errors: true)
608-
609-
assert {^fixture, {3, 7}, "this clause " <> _} = error
610-
end)
611-
612-
assert msg =~
613-
"Compilation failed due to warnings while using the --warnings-as-errors option\n"
614-
after
615-
purge([WarningsSample])
616-
end
617-
end
618556
end
619557
end

lib/mix/lib/mix/compilers/elixir.ex

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,18 @@ defmodule Mix.Compilers.Elixir do
208208
end
209209

210210
Mix.Task.Compiler.notify_modules_compiled(lazy_modules_diff)
211-
212-
unless_previous_warnings_as_errors(previous_warnings, opts, {:ok, all_warnings})
211+
unless_warnings_as_errors(opts, {:ok, all_warnings})
213212

214213
{:error, errors, %{runtime_warnings: r_warnings, compile_warnings: c_warnings}, state} ->
214+
{errors, warnings} =
215+
if opts[:warnings_as_errors],
216+
do: {errors ++ r_warnings ++ c_warnings, []},
217+
else: {errors, r_warnings ++ c_warnings}
218+
215219
# In case of errors, we show all previous warnings and all new ones.
216220
{_, _, sources, _, _, _} = state
217221
errors = Enum.map(errors, &diagnostic/1)
218-
warnings = Enum.map(r_warnings ++ c_warnings, &diagnostic/1)
222+
warnings = Enum.map(warnings, &diagnostic/1)
219223
all_warnings = Keyword.get(opts, :all_warnings, errors == [])
220224
{:error, previous_warnings(sources, all_warnings) ++ warnings ++ errors}
221225
after
@@ -254,8 +258,7 @@ defmodule Mix.Compilers.Elixir do
254258

255259
all_warnings = Keyword.get(opts, :all_warnings, true)
256260
previous_warnings = previous_warnings(sources, all_warnings)
257-
258-
unless_previous_warnings_as_errors(previous_warnings, opts, {status, previous_warnings})
261+
unless_warnings_as_errors(opts, {status, previous_warnings})
259262
end
260263
end
261264

@@ -1012,8 +1015,8 @@ defmodule Mix.Compilers.Elixir do
10121015
File.rm(manifest <> ".checkpoint")
10131016
end
10141017

1015-
defp unless_previous_warnings_as_errors(previous_warnings, opts, {status, all_warnings}) do
1016-
if previous_warnings != [] and opts[:warnings_as_errors] do
1018+
defp unless_warnings_as_errors(opts, {status, all_warnings}) do
1019+
if all_warnings != [] and opts[:warnings_as_errors] do
10171020
message = "Compilation failed due to warnings while using the --warnings-as-errors option"
10181021
IO.puts(:stderr, message)
10191022
{:error, all_warnings}
@@ -1049,7 +1052,6 @@ defmodule Mix.Compilers.Elixir do
10491052
threshold = opts[:long_compilation_threshold] || 10
10501053
profile = opts[:profile]
10511054
verbose = opts[:verbose] || false
1052-
warnings_as_errors = opts[:warnings_as_errors] || false
10531055

10541056
pid =
10551057
spawn_link(fn ->
@@ -1071,8 +1073,7 @@ defmodule Mix.Compilers.Elixir do
10711073
long_compilation_threshold: threshold,
10721074
profile: profile,
10731075
beam_timestamp: timestamp,
1074-
return_diagnostics: true,
1075-
warnings_as_errors: warnings_as_errors
1076+
return_diagnostics: true
10761077
]
10771078

10781079
response = Kernel.ParallelCompiler.compile_to_path(stale, dest, compile_opts)

0 commit comments

Comments
 (0)