logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/
commit: 5addbf39fbdc67d93f6b8605ce02157e14c3edb1
parent 63cbc1208d2654ed174f7d319334aca3e08f69d7
Author: Phantasm <phantasm@centrum.cz>
Date:   Tue, 13 May 2025 00:01:34 +0200

Elixir 1.18 Deal with :warnings_as_errors deprecation in compiler_options/1

warning: :warnings_as_errors is deprecated as part of Code.get_compiler_option/1
  (elixir 1.18.3) lib/code.ex:1597: Code.get_compiler_option/1
  (elixir 1.18.3) lib/code.ex:1572: anonymous fn/2 in Code.compiler_options/1
  (elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
  (elixir 1.18.3) lib/code.ex:1571: Code.compiler_options/1
  (pleroma 2.9.1-77-g8ec49c59-elixir-1-18+test) lib/pleroma/application.ex:104: Pleroma.Application.start/2
  (kernel 10.2.6) application_master.erl:295: :application_master.start_it_old/4

warning: :warnings_as_errors is deprecated as part of Code.put_compiler_option/2, instead you must pass it as a --warnings-as-errors flag. If you need to set it as a default in a mix task, you can also set it under aliases: [compile: "compile --warnings-as-errors"]
  (elixir 1.18.3) lib/code.ex:1710: Code.put_compiler_option/2
  (elixir 1.18.3) lib/code.ex:1573: anonymous fn/2 in Code.compiler_options/1
  (elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
  (elixir 1.18.3) lib/code.ex:1571: Code.compiler_options/1
  (pleroma 2.9.1-77-g8ec49c59-elixir-1-18+test) lib/pleroma/application.ex:104: Pleroma.Application.start/2
  (kernel 10.2.6) application_master.erl:295: :application_master.start_it_old/4

Diffstat:

Mlib/mix/tasks/pleroma/test_runner.ex2+-
Mlib/pleroma/application.ex18+++++++++++++++---
Mmix.exs2+-
Mtest/test_helper.exs2--
4 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/mix/tasks/pleroma/test_runner.ex b/lib/mix/tasks/pleroma/test_runner.ex @@ -4,7 +4,7 @@ defmodule Mix.Tasks.Pleroma.TestRunner do use Mix.Task def run(args \\ []) do - case System.cmd("mix", ["test"] ++ args, into: IO.stream(:stdio, :line)) do + case System.cmd("mix", ["test", "--warnings-as-errors"] ++ args, into: IO.stream(:stdio, :line)) do {_, 0} -> :ok diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex @@ -43,9 +43,6 @@ defmodule Pleroma.Application do # every time the application is restarted, so we disable module # conflicts at runtime Code.compiler_options(ignore_module_conflict: true) - # Disable warnings_as_errors at runtime, it breaks Phoenix live reload - # due to protocol consolidation warnings - Code.compiler_options(warnings_as_errors: false) Pleroma.Telemetry.Logger.attach() Config.Holder.save_default() Pleroma.HTML.compile_scrubbers() @@ -93,6 +90,21 @@ defmodule Pleroma.Application do end end + # Disable warnings_as_errors at runtime, it breaks Phoenix live reload + # due to protocol consolidation warnings + # :warnings_as_errors is deprecated via Code.compiler_options/2 since 1.18 + if elixir_version = System.version() do + [major, minor] = + elixir_version + |> String.split(".") + |> Enum.map(&String.to_integer/1) + |> Enum.take(2) + + if major == 1 and minor < 18 do + Code.compiler_options(warnings_as_errors: false) + end + end + # Define workers and child supervisors to be supervised children = [ diff --git a/mix.exs b/mix.exs @@ -236,7 +236,7 @@ defmodule Pleroma.Mixfile do "ecto.rollback": ["pleroma.ecto.rollback"], "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], "ecto.reset": ["ecto.drop", "ecto.setup"], - test: ["ecto.create --quiet", "ecto.migrate", "test"], + test: ["ecto.create --quiet", "ecto.migrate", "test --warnings-as-errors"], docs: ["pleroma.docs", "docs"], analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"], copyright: &add_copyright/1, diff --git a/test/test_helper.exs b/test/test_helper.exs @@ -2,8 +2,6 @@ # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> # SPDX-License-Identifier: AGPL-3.0-only -Code.put_compiler_option(:warnings_as_errors, true) - ExUnit.configure(capture_log: true, max_cases: System.schedulers_online()) ExUnit.start(exclude: [:federated])