diff options
author | Eric Meadows-Jönsson <eric.meadows.jonsson@gmail.com> | 2019-06-28 16:10:23 +0200 |
---|---|---|
committer | Eric Meadows-Jönsson <eric.meadows.jonsson@gmail.com> | 2019-06-28 16:10:23 +0200 |
commit | 72cdd07b6502feb3d218f2d4fb6abbab0f5c3362 (patch) | |
tree | 8502239128afe93ed61261b652e2656211c1fc3c | |
parent | a1a8b095e6701d600476102f7f9e7f79665ffbb4 (diff) | |
download | elixir-72cdd07b6502feb3d218f2d4fb6abbab0f5c3362.tar.gz |
Remove xref compiler task
-rw-r--r-- | lib/mix/lib/mix/tasks/compile.xref.ex | 106 | ||||
-rw-r--r-- | lib/mix/test/mix/tasks/compile.xref_test.exs | 116 |
2 files changed, 4 insertions, 218 deletions
diff --git a/lib/mix/lib/mix/tasks/compile.xref.ex b/lib/mix/lib/mix/tasks/compile.xref.ex index 4509e6c72..57d311036 100644 --- a/lib/mix/lib/mix/tasks/compile.xref.ex +++ b/lib/mix/lib/mix/tasks/compile.xref.ex @@ -1,110 +1,12 @@ defmodule Mix.Tasks.Compile.Xref do use Mix.Task.Compiler - alias Mix.Tasks.Compile.Elixir, as: E - @recursive true - @manifest "compile.xref" - @manifest_vsn 1 - - @moduledoc """ - Performs remote dispatch checking. - - It uses `mix xref` to check if any remote call does not exist or is - deprecated, and emits warnings in such cases. This task does not show - deprecated local calls (a call to a deprecated function or macro in the - same module) nor calls to deprecated functionality in Elixir itself. - - When this task runs, it will check if the source code has been modified. - If it has changed, `mix xref` will be run to check remote dispatches. You - can force checking regardless of modification time by passing the `--force` - option. - - ## Command line options - - * `--force` - forces checking regardless of modification time - * `--warnings-as-errors` - treats warnings as errors and returns a non-zero exit code - * `--all-warnings` - prints warnings even from files that do not need to be recompiled - - """ - - @switches [all_warnings: :boolean, force: :boolean, warnings_as_errors: :boolean] + @moduledoc false + # TODO: Deprecate in v1.11 @impl true - def run(args) do - {opts, _, _} = OptionParser.parse(args, switches: @switches) - - Mix.Task.run("compile") - - warnings = - if needs_xref?(opts) do - run_xref() - else - read_manifest() - end - - if warnings != [] and warnings_as_errors(opts) do - {:error, to_diagnostics(warnings, :error)} - else - {:noop, to_diagnostics(warnings, :warning)} - end - end - - defp needs_xref?(opts) do - # If all warnings is given, it is easier to check everything. - !!opts[:force] or !!opts[:all_warnings] or Mix.Utils.stale?(E.manifests(), manifests()) - end - - defp run_xref do - timestamp = System.os_time(:second) - warnings = Mix.Tasks.Xref.warnings([]) - write_manifest(warnings, timestamp) - warnings - end - - defp warnings_as_errors(opts) do - Keyword.get_lazy(opts, :warnings_as_errors, fn -> - Mix.Project.config()[:elixirc_options][:warnings_as_errors] - end) - end + def run(_args), do: {:noop, []} @impl true - def manifests, do: [manifest()] - - defp manifest, do: Path.join(Mix.Project.manifest_path(), @manifest) - - defp write_manifest(warnings, timestamp) do - manifest = manifest() - File.mkdir_p!(Path.dirname(manifest)) - File.write!(manifest, :erlang.term_to_binary({@manifest_vsn, warnings})) - File.touch(manifest, timestamp) - end - - defp read_manifest() do - try do - manifest() |> File.read!() |> :erlang.binary_to_term() - rescue - _ -> [] - else - {@manifest_vsn, data} when is_list(data) -> data - _ -> [] - end - end - - @impl true - def clean do - File.rm(manifest()) - end - - defp to_diagnostics(warnings, severity) do - for {message, locations} <- warnings, - {file, line} <- locations do - %Mix.Task.Compiler.Diagnostic{ - compiler_name: "Xref", - file: Path.absname(file), - message: to_string(message), - position: line, - severity: severity - } - end - end + def manifests, do: [] end diff --git a/lib/mix/test/mix/tasks/compile.xref_test.exs b/lib/mix/test/mix/tasks/compile.xref_test.exs deleted file mode 100644 index 5394fcfba..000000000 --- a/lib/mix/test/mix/tasks/compile.xref_test.exs +++ /dev/null @@ -1,116 +0,0 @@ -Code.require_file("../../test_helper.exs", __DIR__) - -defmodule Mix.Tasks.Compile.XrefTest do - use MixTest.Case - - import ExUnit.CaptureIO - - setup do - Mix.Project.push(MixTest.Case.Sample) - :ok - end - - test "doesn't xref if not stale, unless forced" do - in_fixture("no_mixfile", fn -> - write_deprecated_func() - - assert_warn(fn -> - assert Mix.Tasks.Compile.Elixir.run([]) == {:ok, []} - assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run([]) - end) - - assert_no_warn(fn -> assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run([]) end) - assert_warn(fn -> assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run(["--force"]) end) - end) - end - - test "doesn't xref if not stale, unless all warnings" do - in_fixture("no_mixfile", fn -> - write_deprecated_func() - - assert_warn(fn -> - assert Mix.Tasks.Compile.Elixir.run([]) == {:ok, []} - assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run([]) - end) - - assert_no_warn(fn -> assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run([]) end) - - assert_warn(fn -> - assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run(["--all-warnings"]) - end) - end) - end - - test "xrefs if stale" do - in_fixture("no_mixfile", fn -> - write_deprecated_func() - - assert_warn(fn -> - assert Mix.Tasks.Compile.Elixir.run([]) == {:ok, []} - file = Path.absname("lib/a.ex") - - assert {:noop, [diagnostic]} = Mix.Tasks.Compile.Xref.run([]) - - assert %Mix.Task.Compiler.Diagnostic{ - compiler_name: "Xref", - file: ^file, - message: "B.deprecated_func/0 is deprecated. message", - position: 2, - severity: :warning - } = diagnostic - end) - - [manifest] = Mix.Tasks.Compile.Elixir.manifests() - future = {{2038, 1, 1}, {0, 0, 0}} - File.touch!(manifest, future) - - Mix.Task.reenable("xref") - - assert_warn(fn -> assert {:noop, [_]} = Mix.Tasks.Compile.Xref.run([]) end) - end) - end - - test "exits if --warnings-as-errors" do - in_fixture("no_mixfile", fn -> - write_deprecated_func() - - assert_warn(fn -> - assert Mix.Tasks.Compile.Elixir.run([]) == {:ok, []} - assert {:error, [diagnostic]} = Mix.Tasks.Compile.Xref.run(["--warnings-as-errors"]) - assert %Mix.Task.Compiler.Diagnostic{severity: :error} = diagnostic - end) - end) - end - - test "does not exit if --warnings-as-errors and no warnings" do - in_fixture("no_mixfile", fn -> - assert_no_warn(fn -> - assert Mix.Tasks.Compile.Elixir.run([]) == {:ok, []} - assert Mix.Tasks.Compile.Xref.run(["--warnings-as-errors"]) == {:noop, []} - end) - end) - end - - defp write_deprecated_func do - File.write!("lib/a.ex", """ - defmodule A do - def a, do: B.deprecated_func - end - """) - - File.write!("lib/b.ex", """ - defmodule B do - @deprecated "message" - def deprecated_func, do: :ok - end - """) - end - - defp assert_warn(fun) do - assert capture_io(:stderr, fun) =~ "deprecated_func" - end - - defp assert_no_warn(fun) do - assert capture_io(:stderr, fun) == "" - end -end |